views:

36

answers:

1

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.

+2  A: 

stage is defined in the Document Class before the constructor is invoked. Since you compile Viewer as Document class this happens.

Theo.T
Thanks now I understand! I've Googled Document Class and I found a pretty simple and weel explained article:http://www.heaveninteractive.com/weblog/2008/03/04/introduction-to-the-document-class-in-actionscript-30-tutorial/
yuri