13 Replies Latest reply on Aug 9, 2007 1:42 PM by clbeech

    Make flash wait before looping data from xml

    shurleynova Level 1
      Ok now the fun part was getting flash to plot all the points based on an xml (Thanks again Patrick) but now they want me to make the time between them appearing a variable too. I can add extra lines to the XML to make the object appear in the same location for a set number of frames but that makes the xml get longer and longer the more points I add and it also make it very tedious to do.

      What I would like to do is pass one more variable from my xml that I will parse in the actionscript and make that number relative a period of time I want flash to wait before it grabs the next node and displays the clip in that new location.

      Anyone Help
        • 1. Make flash wait before looping data from xml
          shurleynova Level 1
          Ok for some better explanation. Here is the code that I am working with. I left the comment tags in so you can sort of see what I am trying to accomplish. My problem is if I put the wait function before the script incriments the variable for plotpoints it gets stuck on the first plotpoint,
          If I place it after the plotpoint is incrimented it does me no good because it has moved on to the next point.

          • 2. Re: Make flash wait before looping data from xml
            shurleynova Level 1
            Made a few little fixes and now I am sure that the variable is a number.

            var waitTime=Number(currentNode.attributes.rpp);
            trace (waitTime);

            however now if I place it above pointCount++; like above it simply keeps outputting the first node value

            if I place it below the pointCount++; it outputs the values of each line but it has no effect on the display time as it just sits with the first point plotted.
            • 3. Re: Make flash wait before looping data from xml
              clbeech Level 3
              How about changing from an onEnterFrame event to an setInterval event, this way each time the loop increaments only at the rate of the interval.

              change the onLoad handler to:

              var waitTime:Number;
              var Time:Number = [whatever in milliseconds];

              timelineXML.onLoad=function(success:Boolean) {
              clearinterval(waitTime);
              waitTime = setInterval(this, "frameloop", Time);
              }

              and remove the 'wait' function from the interior of the XML iteration loop. On the final loop iteration, clearInterval(waitTime) to stop the action.
              • 4. Make flash wait before looping data from xml
                clbeech Level 3
                PS. you may need to run a separate function to 'get' the Time variable out of the XML first I guess. should be a small function if you can point right to the node. Do that just before the setInterval call in the onLoad function.
                • 5. Re: Make flash wait before looping data from xml
                  shurleynova Level 1
                  I think that it is something along those lines but it is not working like that even if I give Time a definate value instead of parsing it from the XML

                  I am going to repost the code as it looks now without all the extra comments and stuff to make it look a bit less messy

                  • 6. Re: Make flash wait before looping data from xml
                    shurleynova Level 1
                    This feels like it is missing something now that I look at it again. I just dont see what.
                    • 7. Re: Make flash wait before looping data from xml
                      clbeech Level 3
                      hmmm ... ya know come to think of it, sometimes I've experienced that you can't set intervals from 'inside' certain handlers. Try taking the interval setup outside the onLoad and into it's own function to 'start' it up. something like:

                      function startLoop() {
                      clearInterval(waitTime);
                      waitTime = setInterval(this, "frameloop", Time);
                      }

                      then in the onLoad handler use the call: startLoop();

                      also, inside 'frameloop' change the 'this.onEnterFrame=undefined;' to stop the interval as: clearInterval(waitTime);
                      • 8. Re: Make flash wait before looping data from xml
                        shurleynova Level 1
                        Did you mean something like this?

                        the movie runs just as it did before but it is not tracing the 'Time' properly if someone could look at this with a fresh set of eyes to see if I missed something that would be groovy.
                        • 9. Re: Make flash wait before looping data from xml
                          clbeech Level 3
                          Hi there, yes that's about right, although try removing the 'onEnterFrame' from the onLoad handler. This would explain why it's 'running'.

                          Try testing to see if the interval is getting called and running by assigning 'Time' a constant. Also try tracing the values for 'currentNode...' in the startLoop function and see if your getting anyting passed in.

                          One other thing, I see in the frameLoop function you have brackets: this[currentNode.attributes.omc]; and in the startLoop function you have parenthesis: this(currentNode.attribute.rpp); could this be part of the problem?

                          I haven't seen it written in this way before, instead of just:
                          var Time:Number = currentNode.attribute.rpp;

                          OH! I also notice that the 'L' in the setInterval function call is not capitalized.
                          • 10. Re: Make flash wait before looping data from xml
                            shurleynova Level 1
                            Eureka - It almost works.For some reason it is not loading the rpp from the XML
                            when I trace(Time) I get undeffined but if I give Time a constant value like 2000 it works like I want it to. So now I just need to figure out why it is not loading the value from the XML.
                            • 11. Re: Make flash wait before looping data from xml
                              shurleynova Level 1
                              Thanks for all the help. It is finally working. Now I have to get to the interactive portion of the app

                              Just for anyone interested is the complete actionscript. Once everything is working I will post alink to the completed application I am kind of excited because this is the most extensive flash application I have ever done. It is actually a prescreening eye exam for Vision restoration therapy for people who have sufferred a stroke or other brain injury. The goal is to determine where the vision loss is in their field of vision.

                              • 12. Re: Make flash wait before looping data from xml
                                shurleynova Level 1
                                You can see I had to move some items around to get it to work and I had to specify the first Time interval manually but that is fine for this because that is a constant value, so it all worked out.
                                • 13. Re: Make flash wait before looping data from xml
                                  clbeech Level 3
                                  GREAT! shurley, glad it's finally working like you want, interesting that you weren't able to grab the time value, I wonder ... oh well, as long as you've got it working, now you can move on, good luck!