1 Reply Latest reply on Nov 1, 2007 7:02 AM by sixofeight

    Looping question?


      Okay, I have been noodling around with a pretty simple exercise in order to learn some Flash basics.

      I have a rectangular frame, upon which four separate graphical objects "parade by". These objects can be clicked and dragged around the frame, and the entire thing loops.

      In order to learn the basic tools to make the animation & controls happen, I simply took the block of code which worked for ONE object, and pasted it at three later frames on the timeline, changing the relevant terms with a numerical identifier. (i.e., in frame 1, a clip might be "img1_mc", but when copied to frame 12, it is changed to "img2.mc".)

      This allowed me to get the whole thing working the way it should (with each object appearing in series), and to understand a few of the necessary functions, methods, etc. Since each "block" of code only differs by a numerical identifier, I presumed it would be a simple matter to then condense everything into a SINGLE block of code (at frame 1), and use a loop or some other tool in order to increment that identifier and load all four objects in a stepped fashion.


      I have pored through dozens of tutorials on loops, arrays, and loading variables ... but I cannot seem to figure out how to adjust this code to eliminate the duplicate blocks and loop everything. Some of the material I have read seems to indicate that a "for loop" will NOT work in this case, because the loop completes prior to the objects being animated in the live movie?

      At any rate, I assume there is likely more than one way to code this, and I am hoping to LEARN which is the most concise & efficient, as well as what drawbacks there may be to different solutions. I have the code block below. It looks twice as long as it really is, because I pasted TWO sections in the window, so you could see the example of the code after I changed the numerical identifier.

      I'm not necessarily asking for someone to give me ready-made code ... but some advice about which functions/methods are best, along with some details on structure (such as, is sequence of the code elements critical?) would be most appreciated!

        • 1. Re: Looping question?
          sixofeight Level 1
          Someone (on another forum) suggested I take a look at setInterval ...

          And now I have another option to consider, but I still don't clearly understand the syntax or structure for any of them! Let me see if I can elaborate on what I am struggling with.

          I understand the general logic of what I need to do from a programming standpoint (at least I think I do), but I am not clear on how the various solutions are correctly coded in ActionScript.

          The code block I am using has several "nested" things happening, and I am not getting how to apply loops, intervals, etc "around" those existing bits of code in order for the structure & syntax to be correct.

          In an abstract sense, I have something like this in the code block:

          / / / / / / /

          - Create empty box

          - - - define what happens to the box when the mouse drags it

          - - - define movement across the frame for the box

          - put a graphic image into the empty box

          / / / / / / /

          * * * What I want to accomplish is (more or less):

          / / / / / / /

          For X = 1 to 4

          - Create one of several empty boxes(X)

          - - - define what happens to this instance of box(X) when the mouse drags it

          - - - define movement across the frame for this instance of box(X)

          - put one of several graphic images(X) into this instance of empty box(X)

          Next X

          / / / / / / /

          So ... what I need is help understanding which ActionScript function/method/etc is best to accomplish this. Maybe I am misunderstanding some of the logic, if so, please feel free to make suggestions.

          I am happy to provide the .fla file, graphic images or a .swf file also if it is helpful.