Groups | Blog | Home
all groups > flash actionscript > october 2007 >

flash actionscript : How do I add something to the display list from a non-main class?


lumpthing
10/14/2007 3:00:15 PM
I know how to use addChild() within the main class to add something to the
stage display list and have it appear on the screen, but how do I add something
to the stage display list from code within another class? :confused;

So for example say I want to add some text (myTextField) to the stage's
display list from within NotTheMainClass' code, could you give an example of
the necessary code?
kglad
10/14/2007 3:05:55 PM
lumpthing
10/14/2007 6:19:24 PM
kglad
10/14/2007 6:25:39 PM
you must pass a reference to a display list object or create one that's
available to your class.

there are so many ways to do this i'm not sure how you want to proceed. but
you can create a globally available reference to the stage and root timeline:



package {
// usage, on main timelne: var mtl:mainTL=new mainTL(this);
// usage, from any class needing access to the root timeline: mainTL.root
// usage, from any class needing access to the stage timeline:
mainTL.root.stage
import flash.display.MovieClip;
import flash.display.DisplayObjectContainer;

public class mainTL extends MovieClip {

public static var root:DisplayObjectContainer;

public function mainTL(rt:DisplayObjectContainer) {
mainTL.root = rt;
}
}
}
AddThis Social Bookmark Button