8 Replies Latest reply on Nov 12, 2010 7:57 AM by Ned Murphy

    Instance name when adding from library

    Johnnsen

      So this is a huge problem for me while probably the dumbest question in the world.

       

      When addressing nested movieclips like so: _root.movieclip.movieclip.variable


      they need to have an instance name set, otherwise they count as undefined. So I can set that in the properties no problem, but when deleting it from the stage and then readding (manually or by actionscript) the instance name is gone thus I can not address nested clips by action script.

       

      I don't understand how this will work then, since every time I add a clip by code it will have no instance name. The only alternative for me so far was keeping the clip on the stage the whole time, just out of bounds or invisible so I can still do stuff like _root.movieclip.movieclip.variable or _root.movieclip.movieclip.gotoAndStop(2).

       

      Someone please enlighten me for I can't figure it out.

        • 1. Re: Instance name when adding from library
          Ned Murphy Adobe Community Professional & MVP

          I don't understand your explanation/issue. If you could outline steps to describe how you arrive at what you are having a problem with, then it might be easier to see what the issue is.

          1 person found this helpful
          • 2. Re: Instance name when adding from library
            smilelilac

            HI  Johnnsen ,

             

            I too don't understand your qusetion please make it clear.

            • 3. Re: Instance name when adding from library
              Johnnsen Level 1

              Alright, I'm sorry, I will try to make it clearer. If you still don't understand, please tell me which part is unclear.

               

              So, if I want to do a "gotoAndStop" for a movieclip inside another movieclip, I'd have to do it like this: "_root.movieclip1.movieclip2.gotoAndStop(2)" Right? This however, only works if the first movieclip has its instance name set correctly, which you can set here (Picture): http://cubeupload.com/files/2b1243screenshot201011.png

              And this instance name stays set, as long as you keep it on the stage. Maybe try it. Pull something from the library on the stage, give it an instance name, and then delete it. When you get it from the library again, the instance name is gone. That means, whenever I attach a movieclip via actionscript, the instance name also seems to be gone, because any code that refers to nested movieclips doesn't get through, presumedly because the parents movieclip's instance name is empty again.

               

              Here in short form what the problem is:
              I want to attach a movieclip, and that movieclip's class should tell another movieclip nested in it to go to frame 2. That however only works if the movieclip1 containing movieclip2 gets added to the stage and gettings its instance name set manually. When attaching movieclip1 via code the "_root.movieclip1.movieclip2.gotoAndStop(2)" thing doesn't work, because apparently "movieclip1" (containing movieclip2) is "undefined".

               

               

              I hope this made it clearer, I'm sure there is a stupid mistake there somewhere, apparently I don't set the instance name right when attaching the movie with AS2,  I don't know. I can only use gotoAndStop on nested movieclips if the parent MC was added manually and having its instance name set.

              • 4. Re: Instance name when adding from library
                Ned Murphy Adobe Community Professional & MVP

                The purpose of instance names is to be able to use the same library object numerous times and target each one separately.... an instance of this object here, an instance of this object there, etc...  The instance name only applies to an object on the stage.  A library object has no instance name until you assign it one while it is participating in the movie.

                 

                When you attach a movieclip using code in AS2, you should be using the attachMovie() method.  Within that method's arguments is where you assign the instance name...

                 

                   this.attachMovie(id, name, depth)

                 

                The 'name' argument is the instance name you code will use to target that instance.  So inn your case you would use...

                 

                   this.attachMovie(id, "movieclip1", ....)

                 

                 

                I am intentionally only focusing on the instance name, the other arguments you hopefully know how to deal with

                • 5. Re: Instance name when adding from library
                  Johnnsen Level 1

                  Yes, I do a attachMovie("movieclip1", "movieclip1", _root.getNextHighestDepth());

                   

                  But then when I try to change the frame of a clip that is inside of movieclip1 with "_root.movieclip1.movieclip2.gotoAndStop(2)" nothing happens.

                   

                  Thanks for making it clearer though, I had a bit of a wrong understanding of it. I think I figured it out now.

                  What is the ID supposed to be, assuming you want a clear setup of your code? Should it be the same as the name?

                  • 6. Re: Instance name when adding from library
                    Ned Murphy Adobe Community Professional & MVP

                    The ID is the linkage ID you assign to the movieclip in the library -- it is the identifier you use to call that symbol onto the stage using code.  If you right click the symbol in the library and select the Linkage option, that should open the interface where you assign the ID.

                     

                    The ID has no relation to the name you assign.  In fact, if you plan to attach lots of the same symbols using attachMovie, you can hopefully see where you might not want to have the name be the same as the ID.  The ID is for the symbol, but the instance name is for a single unique instance of that symbol.

                    1 person found this helpful
                    • 7. Re: Instance name when adding from library
                      Johnnsen Level 1

                      Thanks, that made it a lot clearer!

                      • 8. Re: Instance name when adding from library
                        Ned Murphy Adobe Community Professional & MVP

                        You're welcome