5 Replies Latest reply on Sep 4, 2006 9:39 PM by Craig Grummitt

    Problem moving objects with Actionscript

    yeddish
      I'm hoping someone can help me with this issue. It just doesn't make sense to me.

      I'm moving a movieClip on the Stage using an interval, so that the motion is apparent to the user. I have to do it dynamically, because the MovieClip could be in different places on the stage, but it needs to move to a specified point.

      All the movieClips move properly expect for one. It only happens when there are 2 of these movable clips and it only happens to the left one. The values are right going into the interval function (as seen by trace()), but mysteriously change somehow.

      I'll attach the code with some comments showing where the problems are. I can also link to the swf and post some trace output if it's needed.

      Thanks for the help.
      -yeddish
        • 1. Problem moving objects with Actionscript
          Craig Grummitt Level 3
          every time your attachMovie statement runs, it creates a movieclip called "box". so if the drawChildToCenterBox function is called twice, you'll have two movieclips on the stage both called "box", making it very difficult to reference one of them individually.

          you then put the reference to this movieclip into a variable called boxRef. if the drawChildToCenterBox function is called twice, the second call will replace the variable boxRef with the reference to the second movieclip, meaning all interval calls will only reference the second boxRef. You have a similar problem with intervalID, xPos, yPos and i.
          • 2. Re: Problem moving objects with Actionscript
            yeddish Level 1
            Thanks for the reply!

            There's only supposed to be one instance of this object "box". I do a removeClip() on it in another part of the code.
            I could post the rest of the code, if it would help. xPos, yPos, and pretty much everything in this function is meant to be disposable. I return the boxRef for later use and keep track of that in other parts of the code.

            -yeddish
            • 3. Re: Problem moving objects with Actionscript
              Craig Grummitt Level 3
              sorry i'm confused then. earlier you said:
              "...there are 2 of these movable clips and it only happens to the left one..."

              are there two(or more) movieclips on the stage simultaneously that are both created with the drawChildToCenterBox function? if so then i don't understand how there's "only supposed to be one instance of this object "box"."

              you say these variables are disposable, but you're referring to them in your interval handler...
              • 4. Re: Problem moving objects with Actionscript
                yeddish Level 1
                I'm sorry that I didn't explain myself completely. There are several of these child nodes, but only one goes through this function at a time. This function turns the child node into the parent node. Once the function is used, the values in it are no longer needed. The next time it is run, the values are replaced. That is not a problem.
                I'll post the whoel set of code so that it will make more sense for you.
                Thanks for your willingness to help.
                -yeddish

                • 5. Re: Problem moving objects with Actionscript
                  Craig Grummitt Level 3
                  wow that's a lot of code to wade through - to be able to understand it fully it might be handy to see the fla.

                  but before we take that step, i'm not sure that you understand what i've been trying to say, so just in case let me try and say it again.

                  You say: "Once the function is used, the values in it are no longer needed. The next time it is run, the values are replaced. That is not a problem."

                  However, (admittedly without thoroughly reading your new code posting yet!) i suspect that it could be the problem. once the function has been called, the function that your setInterval call created is still accessing the values that this function created, and if it is called again before the interval is cleared, then these values will be changed. for example 'i' will be set back to 0 and both interval functions will be incrementing it...

                  is this your problem? if you think you understand what i'm getting at but this isn't your problem, let me know, post your fla and we'll see if we can't tackle it.