PDA

View Full Version : stage size = window size ?


aneuryzma
06-28-2009, 07:02 PM
hi,

is possible to dynamically change the dimensions of my flash stage depending on the size of the browser window ?

Very important, I don't want to stretch any element. Just make the background bigger.

thanks

lordofduct
06-28-2009, 08:17 PM
You've got 4 state scale modes available to you, and you can set it and react accordingly.

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/StageScaleMode.html

first: EXACT_FIT - this will stretch the image to fit exactly in the dimensions of the flash container. THis means that if the container is half the width of the original then the horizontal will get squished... probably not what you want.

next: NO_BORDER - this forces the original to keep aspect ratio, but scale to fit into the new container. While conserving aspect ratio anything that can't fit into the new aspect ratio will be cropped off to conserve original aspect ratio.

next: NO_SCALE - when the container is changed size no scaling or anything occurs. If the container is larger then original then a bunch of white space appears. When the container becomes smaller, it gets cropped.

finally: SHOW_ALL - this is like NO_BORDER, but instead of cropping, it fits it into the container and shows white space where something couldn't get fit.


the stage object also fires a Event.RESIZE event when the container is changed dimensions. So you can do more things come time that it gets resized.

Keep in mind the align parameter also effects this stuff (especially NO_SCALE scale mode).

So pick you params, then in the RESIZE event resize your brackground accordingly.

lordofduct
06-28-2009, 08:19 PM
My best suggestion though. Because flash actually doesn't give you a lot of info about visible area at any given moment. I go with NO_SCALE mode with a TL align mode all the time. Then on resize I scale and move everything accordingly. This way you have your own record of what exactly occured and you can devise visible area easily and on your own to an exact amount of detail you require (for instance, useful if you really need to describe a Rectangle describing the visible area on screen).

aneuryzma
06-28-2009, 09:01 PM
hi!

this is what I get with NO_SCALE and 100% 100% width and height.

http://dl.getdropbox.com/u/72686/lancelmaat.html

The puppet moves until the edge of the movieclip so you roll over it to see how big the stage width.

As you can see, it doesn't fit all window.. I would like the puppet bouncing on the browser window and not before.

thanks

aneuryzma
06-28-2009, 09:16 PM
this is my code


package {

import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.StageScaleMode;

public class lancelmaat extends MovieClip{

public var herm;
public var karen;
public var toLeft;
public var toTop;

//velocity and acceleration
private var vx:Number=0;
private var vy:Number=0;
private var ax:Number=0;
private var ay:Number=0;

//boundaries
var left:Number = 0;
var right:Number = stage.stageWidth;
var top:Number = 0;
var bottom:Number = stage.stageHeight;





public function lancelmaat() {

stage.scaleMode = StageScaleMode.NO_SCALE;

herm = new Herm();
karen = new Karen();

herm.scaleY = herm.scaleX = 0.5;

addChild(herm);
//addChild(karen);

herm.x=stage.stageWidth/2;
herm.y=stage.stageHeight/2;

herm.addEventListener(MouseEvent.MOUSE_OVER,onMous eOver);
addEventListener(Event.ENTER_FRAME,onEnterFrame);



}




private function onMouseOver(event:MouseEvent):void {

var sign = 1;
//if (Math.random() > 0.5) sign = sign*-1;
ax = sign * (Math.random() / 2);
ay = sign * (Math.random() / 4);
vx = 0;
vy = 0;

herm.removeEventListener(MouseEvent.MOUSE_OVER,onM ouseOver);

}



private function onEnterFrame(event:Event):void {


vx += ax;
vy += ay;


herm.y += vy;
herm.x += vx;


if (herm.x + 70 > right) {

herm.x = right - 70;
vx *= -1
ax=0;
herm.getChildAt(0).scaleX=-1;


}



if (herm.x - 70 < left) {

herm.x = left + 70;
vx *= -1;
ax=0;
herm.getChildAt(0).scaleX=1;


}


if (herm.y + 5 < top) {

herm.y = top - 5;
vy *= -1;


}



if (herm.y + 80 > bottom) {

herm.y = bottom - 80;
vy *= -1;


}





}


}
}

lordofduct
06-28-2009, 09:40 PM
you need to update: left, right, top, and bottom on the Event.RESIZE event:


stage.addEventListener( Event.RESIZE, onResize, false, 0, true );

function onResize(e:Event):void
{
right = stage.stageWidth;
bottom = stage.stageHeight;
}

aneuryzma
06-28-2009, 09:53 PM
ok, I've added it and the puppets bounds before or later depending on the window width.

Still I don't get why it perfectly bounds on window border if the window is big and 100px before the end of the window if the window is little.

Shoudn't it bound always at the same distance from window border ?

http://dl.getdropbox.com/u/72686/lancelmaat.html

thanks