I’m starting to get into AS3 and I need a bit of help with understanding the stage property. I understand you can access it from the main class but what I’m not able to grasp is why I need to extend Sprite to get it working. Is this a proper way to do it?
package {
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.display.MovieClip;
import flash.display.StageDisplayState;
public class index extends Sprite {
private var centerStage:MovieClip = new MovieClip;
public function index():void
{
createCenterStage();
}
private function createCenterStage():void
{
addChild(centerStage);
stage.addEventListener(Event.RESIZE, centerContainer);
centerStage.addEventListener(Event.ADDED, centerContainer);
}
private function centerContainer(event:Event):void
{
centerStage.x = Math.round((stage.stageWidth/2)-(centerStage.width/2));
centerStage.y = Math.round((stage.stageHeight/2)-(centerStage.height/2));
}
}
}
Well I know my code works but I’d just like to know if there’s a better way to do this since I want to learn the proper way to do things. Thanks in advance!