0
votes

I have some problems with AS3. I have a Movieclip and I have added it to the stage with addChild(gameLevelSelect);.

The thing is I also have other MovieClips inside it but not as addChild just in that addChild(gameLevelSelect); on the stage. I gave a symbol a instance name of stageThumb_01, but it does not work. How can I fix that?

This is the code:

gameLevelSelect.getChildByName("stageThumb_01").addEventListener(MouseEvent.CLICK, load_Level01);
function load_Level01(e:MouseEvent):void {
    trace("blam")
    gameLevelSelect.getChildByName("stageThumb_01").getChildByName("stars").gotoAndPlay(2);
}

.................................................

gameTitle.addEventListener(Event.ENTER_FRAME, load_LevelSelection);
function load_LevelSelection(event:Event):void {
    if(MovieClip(gameTitle).currentFrame == 22){
        removeChild(gameTitle);
        addChild(gameLevelSelect);

        addChild(thumbLevel01);

        thumbLevel01.getChildByName("stars").gotoAndPlay(1);

        gameLevelSelect.gotoAndPlay(1);

    }
}

var thumbLevel01 = new stageThumb01();
thumbLevel01.x = 83;
thumbLevel01.y = 161;

thumbLevel01.addEventListener(MouseEvent.CLICK, load_Level01);
function load_Level01(e:MouseEvent):void {
    trace("blam")
    //thumbLevel01.getChildByName("stars").gotoAndPlay(2);
}

this works and the reason is that i made thumbLevel01 a addChild. But this is not what i want. i have a movieclip added to the stage as a addChild(gameLevelSelect); and in that movieclip there are animations and buttons And instead of doing a linkage i want to keep it as a movieclip in addChild(gameLevelSelect);. What i want to know is how can i communicate with the movie clips with instance name in addChild(gameLevelSelect);. i have Tried

gameLevelSelect(theAddClass).getChildByName("thumbLevel01").getChildByName("stars").<..stars is a movieClip in thumbLevel01. then addEventListener(MouseEvent.CLICK, load_Level01);

[addChild - gameLevelSelect] . . . . . . . > movieClip with instance name - thumbLevel01 (not add child). . . . . . . . .> movieClip with instance name - starsMeter (for score).

1
What does not work? You event handler doesn't fire? There are runtime errors? See your gameLevelSelect variable with the addChild in your code sample might be helpful.Jason Sturges
i tried lots of things still no success.user1492440

1 Answers

0
votes

The way you've asked the question is pretty obtuse, so I can't get to the core of what you're really asking, but I suspect that what's going on is you're trying to access children before they're added to the stage of the instance you've added through code.

In general, you don't want to directly access children. Instead, the component you added should expose properties and methods that allow you to do what you need to do, that also take into account the specific details of how that MC is built. For example:

class ShowMessage extends MovieClip {
  public var tf:TextField;//this is public so the Flash player can fill it, not for external use
  private var _message:String;
  public function get message():String {
      return _message;
  }
  public function set message(value:String):void {
      _message = value;
      if (tf) {
        tf.text = value;
      } 
  }
}

For other ways to handle a mixture of timeline and AS, check out Combining the Timeline with OOP in Flash.