Tuesday, March 17, 2009

AS3 : accessing Document Class methods / function from a child class

okay this maybe a little old but i figured someone might find it useful.

actually this way of coding does not parallel with the true OOP ways of doing thing ,
because a CHILD should never ask a PARENT to do stuffs, it's always should be the other way round. the best workaround is to use event dispatching and listening between the child and parent to let the parent know what's happening inside the child.

but , if you were stuck or you don't want to lose more of your hair, you can do this to access the Document Class.

var _deeproot:MovieClip = stage.getChildAt(0) as MovieClip;
_deeproot.someMethod(); // access someMethod method
_deeproot.myVar = "foo"; // access and set
public var myVar to "foo"