Hi everybody,
After years of as, i finally look at AS3…it’s a nightmare for me right now since a lot of things have changed.
So now my problem is with the stage. I just want to change the x and y of a simple movie clip. I have a resize handler that do that…no problem. But my clip at the beginning is not positionning where i want to.
a simple :
MovieClip(background).x=stage.stageWidth/2;
MovieClip(background).y=stage.stageHeight/2;
doesn’t work when it loads. On the resiezHandler yes but not at the beginning…even with an activateHandler function. Do i missed something ?? I’m pretty lost.
I even found that : http://tush.wordpress.com/2007/06/25/action-script-3-resize-swf-on-browser-resize/
But i can’t make it work. A basic example or just an explanation of what i do wrong would be appreciated.
Thank’s for your help
Here’s a basic AS3 liquid GUI script that might be helpful.
Includes a tiled background image, and a movieclip centered on the stage.
/*---------------------------------------------------------------------------------
Library: tilable bitmap, class name "Background"
on Stage: movieclip, instance name "centered_mc" with centered registration point.
---------------------------------------------------------------------------------*/
stop();
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.events.Event;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener(Event.RESIZE, resizeHandler);
function resizeHandler(event:Event=null):void {
var sw:Number = stage.stageWidth;
var sh:Number = stage.stageHeight;
var canvas:Sprite = new Sprite;
addChild(canvas);
canvas.graphics.beginBitmapFill(new Background(0, 0));
canvas.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
canvas.graphics.endFill();
addChild(centered_mc);//move to the top of the display list
centered_mc.x = sw/2;
centered_mc.y = sh/2;
}
resizeHandler(null);
Thank you. I had that kind of code but i just understood what i did wrong, it was stupid. I didn’t have my clip where i put the code. Thank’s anyway.