View Full Version : AS3 Stage Align
tha10co
June 20th, 2007, 05:16 AM
Hi I just make a Switch to Flash CS3 and AS3 and one of my favorite tricks in AS2 are Stage Align for swf at fullscreen... and align my elements in the place I like
I just write some AS3 for Stage Align but doesn´t work
looks like this...
package {
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
public class Test extends MovieClip {
public function Test() {
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
}
public function onResize(event:Event)
{
AppMain.x = stage.stageWidth / 2;
AppMain.y = stage.stageHeight / 2;
}
}
}
I see this thread (http://www.kirupa.com/forum/showthread.php?t=265189) and I want to do the same in AS3
Can anybody help me?
greggreg
June 20th, 2007, 05:10 PM
im pretty sure your just missing the event listener for the stage. you need something like:
stage.addEventListener(Event.RESIZE, onResize);
that should trigger the onResize() function every time the RESIZE event is fired from the stage.
Krilnon
June 20th, 2007, 05:11 PM
You need to add a listener so that the handler will be called:
stage.addEventListener(Event.RESIZE, onResize);
tha10co
June 20th, 2007, 06:54 PM
thanks a lot for your answears
Now I have this code...
package {
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
public class Test extends MovieClip {
public function Test() {
stage.align=StageAlign.TOP_LEFT;
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.addEventListener(Event.ACTIVATE, activateHandler);
stage.addEventListener(Event.RESIZE, resizeHandler);
}
public function onResize(event:Event){
AppMain.x = (stage.stageWidth-AppMain.width)/2
AppMain.y = (stage.stageHeight-AppMain.height)/2
}
}
}
But doesn't work yet... have any idea?
how I make a call of this code on my Flash file?
Derlei
June 20th, 2007, 07:25 PM
thanks a lot for your answears
Now I have this code...
package {
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
public class Test extends MovieClip {
public function Test() {
stage.align=StageAlign.TOP_LEFT;
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.addEventListener(Event.ACTIVATE, activateHandler);
stage.addEventListener(Event.RESIZE, resizeHandler);
}
public function onResize(event:Event){
AppMain.x = (stage.stageWidth-AppMain.width)/2
AppMain.y = (stage.stageHeight-AppMain.height)/2
}
}
}
But doesn't work yet... have any idea?
how I make a call of this code on my Flash file?
I think you are missing something
package {
import flash.display.MovieClip;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
public class Test extends MovieClip {
public function Test() {
initStage();
}
private function initStage():void {
stage.align=StageAlign.TOP_LEFT;
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, resizeHandler);
}
private function resizeHandler(event:Event):void{
AppMain.x = (stage.stageWidth-AppMain.width)/2
AppMain.y = (stage.stageHeight-AppMain.height)/2
}
}
}
tha10co
June 20th, 2007, 07:47 PM
One more question...
How can I add or import of this test.as on my test.fla?
My test.as is not working right now maybe my import is wrong can any body tell me how I can do imports...
I want to do a package with contain my test.as
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.