Why compiling in Flash IDE I cannot access stage in a Sprite constructor before addChild while if I

Posted by yuri on Stack Overflow See other posts from Stack Overflow or by yuri
Published on 2010-04-30T08:18:57Z Indexed on 2010/04/30 8:57 UTC
Read the original article Hit count: 295

Filed under:
|
|

I've created this simple 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.

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about stage