8 Replies Latest reply on Dec 14, 2009 10:31 AM by designingal

    Copying actions to a duplicated symbol

    designingal Level 1

      Hi

      I am an newbie trying to take an existing Flash game and modifying it for my own selfish goals.  I am duplicating symbols and trying to preserve all of their actions so that I can then swap them out for my own symbols.  When I swap, actions are preserved, but I have run out of symbols to swap, so now I am trying to duplicate the remaining symbol so I have more to swap with, but when I duplicate the actions are lost.  I have adjusted the actions code to accommodate more symbols ( or at least I think I have).  Any help would be appreciated.

        • 1. Re: Copying actions to a duplicated symbol
          robdillon Most Valuable Participant

          From your description it sounds like you have instances of objects, probably movieClips, on the stage that have been named. You also have some actionscript that is related to these objects through their instance names. And these seem to work as you want.

           

          If you duplicate an object on the stage that has an instance name, then you will also duplicate the instance name. This means that you will now have two objects with the same name. The actionscript will find the first one and use that one and ignore the second, or third.

           

          If you drag a new instance of an object from the Library to the stage, it will have no instance name.

           

          Does any of that sound like what may be going on for you?

          1 person found this helpful
          • 2. Re: Copying actions to a duplicated symbol
            designingal Level 1

            Yes, you are describing what I am doing. I lose the function I want when I copy the symbol.  How can I add more symbols and apply the actions of the existing ones to my new ones?

            • 3. Re: Copying actions to a duplicated symbol
              robdillon Most Valuable Participant

              That will depend on what your functions do and how you are linking them to the objects on the stage. And which version of actionscript you are using. In any case you will need to name each new object with a unique name. Then you can assign the function. In AS3 you can assign an event listener and point it to the same function that the other objects are using. In AS2 you might replicate one of the functions assigned to another object and use the new object's instance name in the event. Can you show the code that you are using now?

              • 4. Re: Copying actions to a duplicated symbol
                designingal Level 1

                Below is the action code controlling the symbols.  I am copying this model from a book I found. The actions sit outside of the stage in a word called "actions".   I will have 36 symbols, and I would like them to have the same characteristics as the 13 in the original program.  I actually would like the symbol to duplicate itself each time the user clicks and drags it, if that is possible.  The concept I am trying to create is as if you had a box of crayons and each time you clicked and dragged a color to the stage the original crayon wouldn't disappear from the box, it would just duplicate.  You have been very helpful, thank you.

                 

                 

                 

                // start with nothing dragging
                onClipEvent (load) {
                dragPart = 0;
                }

                // start drag
                onClipEvent (mouseDown) {
                // get current location
                x = _root._xmouse;
                y = _root._ymouse;

                // find which, if any, part the cursor is over
                for(i=1;i<=13;i++) {
                  if (_root["Part"+i].hitTest(x,y, true)) {
                   // set to drag this part, remember offset
                   dragPart = i;
                    offsetx = _root["Part"+i]._x - x;
                    offsety = _root["Part"+i]._y - y;
                   break;
                  }
                }

                }

                // end drag
                onClipEvent (mouseUp) {
                dragPart = 0;
                }

                // if dragging, set new position
                onClipEvent (enterFrame) {
                if (dragPart > 0) {
                  _root["Part"+dragPart]._x = _root._xmouse + offsetx;
                  _root["Part"+dragPart]._y = _root._ymouse + offsety;
                }
                }

                • 5. Re: Copying actions to a duplicated symbol
                  robdillon Most Valuable Participant

                  This code won't duplicate anything it will just drag around whatever you click on on the stage. The code is very old. What version of Flash are you using and what version of Actionscript do you want to use? Is there any other Actionscript in the movie?

                  • 6. Re: Copying actions to a duplicated symbol
                    designingal Level 1

                    Hi Rob,

                    I am back at work on this project and have overcome the naming problem, but now I have a new one.  I have since renamed my movie clips  part1. part2, etc.. and have added in all of the movie clips that I want and they move around just great.  Now I would like to duplicate each movie clip so that each time it is clicked on the original stays put and the new one can be moved around.  This needs to happen as many times as the user would like it to duplicate and be able to move each one independently.  I know the code is old, but so far it is working for me and I don't mess with what works!  I have found a new snippet of code that I think will make my MC's duplicate, but either my placement or syntax is wrong.

                     

                    Will this code duplicate my movie clip?

                     

                    on (press) {
                    // duplicate part
                    part.duplicateMovieClip("part"+level,level);
                    // set a random position
                    _root["part"+level]._x = int(Math.random()*550);
                    _root["part"+level]._y = int(Math.random()*400);
                    // increase level
                    level++;
                    }

                     

                    Where in below code should above snippet go?

                     


                    // start with nothing dragging
                    onClipEvent (load) {
                    dragPart = 0;
                    }

                    // start drag
                    onClipEvent (mouseDown) {
                    // get current location
                    x = _root._xmouse;
                    y = _root._ymouse;

                    // find which, if any, part the cursor is over
                    for(i=1;i<=36;i++) {
                      if (_root["Part"+i].hitTest(x,y, true)) {
                       // set to drag this part, remember offset
                       dragPart = i;
                        offsetx = _root["Part"+i]._x - x;
                        offsety = _root["Part"+i]._y - y;
                       break;
                      }
                    }

                    }


                    /*
                    pyrBtn1.onRollOver = function (){
                    gotoAndStop ("btn1Rollover");
                    };
                    */


                    // end drag
                    onClipEvent (mouseUp) {
                    dragPart = 0;
                    }

                    // if dragging, set new position
                    onClipEvent (enterFrame) {
                    if (dragPart > 0) {
                      _root["Part"+dragPart]._x = _root._xmouse + offsetx;
                      _root["Part"+dragPart]._y = _root._ymouse + offsety;
                    }
                    }

                     

                    Thanks for any help you can offer.

                    • 7. Re: Copying actions to a duplicated symbol
                      robdillon Most Valuable Participant

                      Yes, the on(press) function will duplicate a movieClip named "part". It also requires a variable named "level". In any case this code, placed in a frame action space will do the same job as all of that other code. Just add in the names of each of the clips to be used:

                      -------------------

                      var level:Number = 1;

                       

                      // an array of the original movieClips...
                      // add the instance names as needed
                      var clipArray:Array = new Array(part1, part2, part3, part4, part5);

                       

                      for (c in clipArray) {
                          clipArray[c].onPress = duplicateAndDrag;
                      }

                       

                      function duplicateAndDrag() {
                          // duplicate any given movieClip and drag the duplicate around...
                          var newClip = this.duplicateMovieClip("subPart"+level, getNextHighestDepth());
                          // position the new clip at the cursor...
                          newClip._x = _xmouse;
                          newClip._y = _ymouse;
                          newClip.startDrag();
                          // create a mouse listener to detect when the user lets go of the new clip...
                          var mouseListener:Object = new Object();
                          mouseListener.onMouseUp = function() {
                              stopDrag();
                          };
                          Mouse.addListener(mouseListener);
                          // increase level
                          level++;
                      }

                       

                      ------------------------

                      1 person found this helpful
                      • 8. Re: Copying actions to a duplicated symbol
                        designingal Level 1

                        Hi Rob,

                        That code worked perfectly.  All of my movie clips are duplicating and moving exactly as I want them too, thank you!  Is it possible to move around the copies once they are placed down?  Ultimately I would like to mimic some of Illustrator's functions with these movie clips and have the basic functions of pick up and re-place (moving), clicking and duplicating the instances that are on the stage, deleting instances, grouping instances ( and re- coloring the groups), copying and pasting them as a group, and saving and printing finished work.  If you want to see how I am applying this I have attached what I have done so far.  Thanks for all your help.

                         

                        https://www.woolybaabaa.com/index.php?_a=viewProd&productId=646

                         

                        Message was edited by: designingal