Search code examples
flashactionscript-3timeline

Flash/AS3: Accessing the instance of a DisplayObject on a mid-timeline frame


I have the Dynamic Text field that has an instance name on a mid-timeline frame in Flash CS4.

I have a class that inherits from Sprite, and which is always added to the stage on instantiation. How can I get a reference to my Dynamic Text instance from this class?

Thanks!

EDIT: example:

My Main class (linked in Flash's publish settings) goes like this:

protected function beginGame(e:MouseEvent){
    gotoAndStop(8);
    var game:GameContainer = new GameContainer(41,8);
    addChild(game);
    game.x=36;
    game.y=128;
}

Game Container extends MovieClip, and draws some pretty gfx.

On Frame 8, in the Flash IDE, there is a Dynamic Text element instance named "scoreText".

I want to access this from the GameContainer class.

Possible?


Solution

  • As long as GameContainer is on the stage you can do:

    if (MovieClip(root).scoreText) {
      MovieClip(root).scoreText.text = "hello";
    }
    

    If it's not on the stage it won't have a root property.