3 Replies Latest reply on Jan 26, 2017 6:35 AM by kglad

    refer to a MC inside a MC

    wfzen Level 1

      Sorry this may be too simple a question, but I can't figure out where the mistake is.

      function EnableButtonsQ4() {

        for (var i:Number = 1; i<=TotalChoices; i++) {

        var btn:MovieClip = _root["C1_4_"+i];// select + i = instance name

        _root["C1_4_"+i].Num = i;

        btn.onRollOver = function() {

        if (userAns == 0 || userAns<>this.Num) {

        _root["C1_4_"+this.Num].gotoAndStop(2);

        } else {

        _root["C1_4_"+this.Num].gotoAndStop(3);

        }

        };

        btn.onRollOut = function() {

        if (userAns == 0 || userAns<>this.Num) {

        _root["C1_4_"+this.Num].gotoAndStop(1);

        } else {

        _root["C1_4_"+this.Num].gotoAndStop(3);

        }

        };

        btn.onRelease = function() {

        if (totalAttempt<maxAttemptAllowed) {

        resetBtn();

        _root["C1_4_"+this.Num].gotoAndStop(3);

        userAns = this.Num;

        trace("user answer: "+userAns);

        }

        };

        }

      }

       

      Basically, it's buttons script to select answers. C1_4_1, C1_4_2, C1_4_3... are instance names for each choice. Rolling over shows rollover state, depending on the selection, it displays the selected state. The script works as it (copied from previous projects), but this case is a little bit different. different states (rollover, selected) in different frames are inside a Movie Clip inside C1_4_1 movie clip. So I added movie clip name (states in this case) to the string like below:  _root["C1_4_" + this.Num + ".states"].gotoAndStop(2);

       

      Then it does not do highlight or selected.  button is recognized but not working in changing state. I added traces and it seems it executed the block but never changed the state. If I put the button in a blank file and added a line: C1_4_1.states.gotoAndStop(2) and it shows the highlight state correctly.

       

      So how do I specify the gotoAndStop(x) in 2 levels of movie clip?

       

      Thanks for your help,

       

      BTW, what is the proper way to include script? I chose raw HTML and it only showed up in editing not the viewing mode.

       

      Message was edited by: Peter Liu

        • 1. Re: refer to a MC inside a MC
          kglad Adobe Community Professional & MVP

          there's no easy way to reference a child or a button, so don't use buttons, use movieclips.  and despite your poor choice of names, it looks like you are using movieclips.

           

          for example, if you want to control the child movieclip 'state' in one of your movieclip's btn use:

           

          btn.onRollOver=function(){

          this.stage.gotoAndStop(whatever);

          }

          • 2. Re: refer to a MC inside a MC
            wfzen Level 1

            Thanks for the quick response.

            I have to integrate it with a loop to cover all buttons like _root["C1_4_" + this.Num + ".states"].gotoAndStop(2);

            So button movie clips can be C1_4_1, C1_4_2, C1_4_3, ... this.Num will generate 1, 2, 3 in each loop.

            If I put C1_4_1.states.gotoAndStop(2) as a test, it shows up the highlights correctly but not in the loop.

             

            Thanks,

            • 3. Re: refer to a MC inside a MC
              kglad Adobe Community Professional & MVP

              put that code in your loop.

               

              if you're trying to control some other btn's child state, you would use something like:

               

              btn.onRollOver = function() {

                          // to reference this btn's state child

                          this.state.gotoAndStop(wherever);

                          // to reference the 'next' btn's child

                          _root["CL_4_"+(this.Num+1)%TotalChoices].state.gotoAndStop(wheverever else);

                      };