7 Replies Latest reply on Nov 29, 2017 3:18 PM by Marampazú

    Actions in a nested mc

    Marampazú Level 1

      Hello again.

      I'm trying to do actions with movieclips that are nested inside another.

      I'm calling them dynamically with a for, something like this:

       

      root = this;

       

      for (i = 1; i <= 12; i ++) {

      root ["mcP_" + i] .visible = false;

      };

       

       

      This code works, but when the movieclips are nested, it does not find them anymore.

       

       

      for (i = 1; i <= 12; i ++) {

      root.anotherMovieClip ["mcP_" + i] .visible = false;

      };

       

       

      Surely I am executing incorrectly the call to the objects, I wish they could tell me what is the correct way to execute this.

       

      Thanks for your support.

      Greetings.

        • 1. Re: Actions in a nested mc
          kglad Adobe Community Professional & MVP

          if your path/name were correct that would work.  ie, if this.anotherMovieClip.mcP_1 etc were correct, your code would work.

           

          use the trace function to see if any if the first references is incorrect or the failure occurs after mcP_1.

          1 person found this helpful
          • 2. Re: Actions in a nested mc
            Colin Holgate MVP & Adobe Community Professional

            I can't get it to fail. One thing to watch out for, assuming this is HTML5 Canvas, because you're not saying this.root = this; or var root = this;, 'root' is a window variable, and if anything else going on makes a change to the same variable name, it could mess things up.

             

            Same for 'I'. Now, it could be you're doing that already, and the code you showed was just an example written while you were posting. So, if it's not working I would check that the outer movieclip and the inner movieclips have the names you think they should have.

            1 person found this helpful
            • 3. Re: Actions in a nested mc
              ClayUUID Adobe Community Professional

              Make sure you're waiting a frame or two for all the nested movieclips to initialize.

              • 4. Re: Actions in a nested mc
                Marampazú Level 1

                Thanks for the answers. Really thank you very much. I commented:

                 

                The file is made for html. The code I'm picking up from a file I did before is this:

                 

                var root = this;

                 

                for (i = 1; i <= 12; i ++) {

                     root ["mcP_" + i] .visible = false;

                };

                 

                In this file the mcP_1, mcP_2 ... mcP_12 are at the same level as the action frame. This is your instace name.

                 

                In the file I am currently doing I am trying to reuse the code, only that in this case the mcP are nested movies inside another. We will call this movieclip map (instance name).

                 

                for (i = 1; i <= 12; i ++) {

                     root.mapa ["mcP_" + i] .visible = false;

                };

                 

                When I execute it, it does not work. The message in the console is: Can not set property 'visible' of undefined, so I think it is not enough to retrieve the instance name of the movieclip.

                 

                If I take it out of the for and I put it one by one, if it works.

                 

                root.mapa.mcP_1.visible = false;

                root.mapa.mcP_2.visible = false;

                root.mapa.mcP_3.visible = false;

                .

                .

                .

                root.mapa.mcP_12.visible = false;

                 

                I have already reviewed the instance names and they are correct.

                Probably with this information you can help me.

                 

                Thanks for the support.

                • 5. Re: Actions in a nested mc
                  kglad Adobe Community Professional & MVP

                  those movieclips don't exist when your code executes.  put that code in a function:

                   

                  var root=this;

                  function intiF(){

                  for (i = 1; i <= 12; i ++) {

                       root.mapa ["mcP_" + i] .visible = false;

                  };

                  }

                   

                   

                   

                  // and on a frame where the mcP exist, put

                   

                  this.parent.initF();

                   

                   

                  // if that fails, use a ticker to wait one tick before calling initF

                  1 person found this helpful
                  • 6. Re: Actions in a nested mc
                    Colin Holgate MVP & Adobe Community Professional

                    That could lead to a flash of the movieclips being visible for a moment. If you want those 12 movieclips to all be invisible when you get to their frame, you could put this into each one, in the first frame:

                     

                    this.visible = false;

                     

                    That would work no matter how nested they are.

                    1 person found this helpful
                    • 7. Re: Actions in a nested mc
                      Marampazú Level 1

                      It sounds logical, but still and what is missing is to give them a little more context about what I am doing.

                       

                      The development is a game type where the character moves from left to right and after speaking with some character has to start a search. This is why the buttons should initially be disabled / not visible. They are inside a movie clip because I am moving the stage and the elements that it has inside to simulate the advance, the character does not move, only his movement is animated.

                       

                      This scenario loads (and moves within) the areas (buttons) that the user has to click on. I could take them out of the movie but what I want to avoid is to make multiple lines of code like this:

                       

                      this.mcPlayer.play ();

                      this.mcFront.x + = velocityFront * directionScene;

                      this.mcMedium.x + = velocityFront * directionScene;

                      this.mcNPC01.x + = velocityFront * directionScene;

                      this.mcRightLimito.x + = velocityFront * directionScene;

                      this.mcLeftLimit.x + = velocityFront * directionScene;

                      ...

                       

                      And add line by line each of the buttons and elements with which the user will interact.

                       

                      Thanks again, I'm still on the lookout.

                       

                      By the way, I'm a graphic designer, I've had to implement code ... it's quite fun.