Why compiling in Flash IDE I cannot access stage in a Sprite constructor before addChild while if I compile within Flex it works?
I've created this simpl开发者_如何学Pythone class (omissing package directive and imports)
public class Viewer extends Sprite {
public function Viewer():void {
trace(stage);
}
}
then in Flash IDE I import in first frame this AS:
import Viewer
var viewer = new Viewer();
stage.addChild(viewer);
trace(viewer.stage);
and this works as I expected: the first trace called in constructor say stage is "null" because I haven't yet add viewer to a DisplayObjectContainer. The second one output the stage object.
So I created a project using AXDT eclipse plugin, I've recreated and compiled only the first class (trashed the AS init script used in Flash IDE because is not needed) and on the first trace ... wow ... the stage is filled with the stage Object.
I seems to me that the compiler used by AXDT (Flex4 SDK open source) add the class... before construct it (!?).. to a DisplayObjectContainer already attached to a Stage.
I want to understand how can reproduce this behaviour using compiler in Flash IDE so I can directrly access Stage in construction.
stage
is defined in the Document Class before the constructor is invoked. Since you compile Viewer
as Document class this happens.
精彩评论