10 Replies Latest reply on May 23, 2008 4:37 PM by MikeM2

    Duplicated MC's that are not in.

    MikeM2 Level 1
      I've set up:

      duplicateMovieClip (obj0, "obj" + zp, zp);

      which makes a duplicate of obj0, but I have to include the instance and name it obj0. I want to be able to make a duplicate of the original instance. I used the linker and exported it to first frame, but it still doesn't catch..
        • 1. Re: Duplicated MC's that are not in.
          clbeech Level 3
          is 'obj0' currently on the Stage? it does need to be in order to use the duplicateMovie method. if your trying to 'link' to an Library instance then you need to use attachMovie, as in:

          this.attachMovie('obj0', 'obj'+zp, zp);
          • 2. Re: Duplicated MC's that are not in.
            MikeM2 Level 1
            yes obj0 is on the stage, but I dont want it to be. So I will try the attachMovie method. Thanks.
            • 3. Re: Duplicated MC's that are not in.
              clbeech Level 3
              np, you're welcome - you can also pass an initObj reference in the method to assign properties on call - like positioning as in:

              this.attachMovie('obj0', 'obj'+zp, zp, {_x:100, _y:100});
              • 4. Re: Duplicated MC's that are not in.
                MikeM2 Level 1
                awesome.

                now what about the code that is set on the movie clip it self. not within but on it. I have this onClipEvent enterframe where i have lots of variables and what not.

                how could i set that ?
                • 5. Re: Duplicated MC's that are not in.
                  clbeech Level 3
                  bad juju man - it's recommended not to place code with object attachments - it can of course be done - but it's not a 'best practice' as you'll find as you do more and more scripting. it really is better to place your code on the timeline makes paths much more accessible.

                  however, depending on what you want to do with it, you can call to other timelines to achieve your goal - for instance: say in this MC you are using the above to attach clips to the main timeline - and this MC instance resides on the main - first you reference the main timeline using '_parent' then target an MC instance the resides on the main as in something like:

                  _parent.my_otherMC.attachMovie(blah blah blah);
                  • 6. Re: Duplicated MC's that are not in.
                    MikeM2 Level 1
                    So using onclipevent is not recommended?
                    • 7. Re: Duplicated MC's that are not in.
                      clbeech Level 3
                      not exactly - 'attaching code' to object instance is not, no. the timeline equivalent is: onEnterFrame (for that one in particular) the syntax on the timeline would be:

                      my_mc.onEnterFrame = function() {
                      //do stuff here
                      }

                      and don't forget to 'turn off' the loop when your events are complete with:

                      delete onEnterFrame;

                      or it'll just keep running (same is true with the attachment method)
                      I'm just saying this is a good habit - in fact object code attachment has been eliminated in AS3 for these reasons (and several others).
                      • 8. Re: Duplicated MC's that are not in.
                        MikeM2 Level 1
                        ahh so, eventually I shouldnt be attaching code to objects, only in the timeline.
                        • 9. Re: Duplicated MC's that are not in.
                          clbeech Level 3
                          yes - that really is best, for certain. when one does so (attachment) - it can make code very difficult to find and debug - not to mention the problems with paths and variables that are only accessible within the clip - it's often more useful to have access to all of your values. it does depend on what you're doing (sort of) but even in the simplest application it's just better to get use to not using them at all in that way. You'll find as your applications grow in size that it becomes quite difficult to keep track of codes strewn about through your document and instances, perhaps several children deep.
                          • 10. Re: Duplicated MC's that are not in.
                            MikeM2 Level 1
                            ahh makes sense.

                            appreciate it!