5 Replies Latest reply on May 12, 2008 9:37 AM by Rothrock

    ActionScript 2.0

    CoastalBluff
      I am new to Flash/ActionScript. Here's my problem.

      I've loaded an XML file into AS2. The XML file has coordinates that I want to use to place a movie clip. The FOR LOOP that I'm using to get the coordinates and place the MC into position works fine and I am removing the old MC at the end of each loop. Of course you ActionScript experts know what is happening. All I see is the last placement of the MC. I've tried setInterval to slow it down, but that didn't work. Help, please. I am way into this project and just can't get past this problem. --Thanks in advance.
        • 1. Re: ActionScript 2.0
          Rothrock Level 5
          As you know what you are doing won't work. But it would be helpful to us to see what you mean by, "I've tried setInterval to slow it down..."

          An interval should allow you to do what you want, so if it isn't working there is something else going on. So use the attach code button to attach only the parts of your code that are relavant to this problem. Then we can see if we can get you straightened out!
          • 2. Re: ActionScript 2.0
            CoastalBluff Level 1
            I attached the entire code.
            • 3. Re: ActionScript 2.0
              Rothrock Level 5
              Still not clear on what is happening. So are you not seeing the wait function trace? Or are you seeing it once for each myTracks and then it keeps on for ever?

              Since you have the stuff at the bottom there indented were you thinking that the for loop would pause for the wait function to be called and then execute the attaching and all? Like you said before that isn't going to work.

              A for loop executes (if possible) completely before each frame of your animation runs. There is no way to slow it or make it go one step at a time. What you need to do is spread the looping bit out over time and that is where the setInterval comes in. You need to set up some kind of counter -- outside of your XML object -- and then have the attaching and removing happen with that function.

              Actually most everything in your for loop needs to be pulled outside of the onLoad and be put in a setInterval or an onEnterFrame.


              • 4. Re: ActionScript 2.0
                CoastalBluff Level 1
                Thanks Rothrock. I was thinking that I could pause the for loop. I took your suggestion and set a counter and am running the for loop for each storm track position causing the mc to animate.
                • 5. Re: ActionScript 2.0
                  Rothrock Level 5
                  Glad that worked out for you. The for-loop trap often gets folks who are first stepping into AS controlled animation. The two choices really are to use setInterval or to use an onEnterFrame event handler. So if you plan to do much more of this I would recommend trying some little experiments with each to learn about their respective strengths and weaknesses. Good luck.