A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: wheres a good place to learn about repeater loops? (while, do while, for)

  1. #1
    hi,

    I've got a F5 book on actionscript but its very easy to read

    :-(

    I really want to learn about while, do while and for loops.

    Does anyone know of good resource and tutorial sites that
    could help me learn.

    thanks cris.

    hello to flash guru - liked your 24:7 spiders.

  2. #2
    Senior Member
    Join Date
    Jul 2000
    Posts
    254
    they are really pretty straight-forward...
    the actionscript book that comes w/flash5 should clear
    up the difference between the types of loops...
    they typically work like this...

    (from memory...)

    while (condition){
    statement(s);
    }

    ex.
    ---
    var = 0
    while (var<=10){
    _root["myMC"+var].gotoAndPlay(label);
    var++ // this is the same as saying var + 1
    }

    so each time the statements in the loop run it increments
    one to var and makes myMC1-10, while it is less than or equal to 10.


    a for loop looks like this

    for (init; condition; next){
    statement(s);
    }

    ex.
    ---
    for (i=0; i<10; i++){
    _root["myMC" + i].gotoAndPlay(label);
    }

    so... it's pretty much the same thing... this loop will run while i is less than 10.


    hope that helps.

    //d

  3. #3

    thanks my friend,
    that helped.

    Cris Edinburgh.

  4. #4
    Junior Member
    Join Date
    Apr 2001
    Posts
    24
    also the for each loop is handy for looping through the contents of an array, works like this

    for(item in myArray) {
    trace(myArray[item]);
    }

    or something along those lines.

    Dennis

  5. #5
    Senior Member
    Join Date
    Jul 2000
    Posts
    254
    no problem. loops are relatively simple to learn, and
    are extremely handy.

    glad i could help.

    /d

  6. #6
    Junior Member
    Join Date
    Apr 2001
    Posts
    15

    loopy yes but...

    ok

    so looping is relatively simple but i can add some complicating factors:

    1) my animations follow a 'non flat' guide. does that preclude including the mc's in an array?

    2) my mc's have a down state (or visited link style state) an i would like to ensure that once the movie clip loops the down states stay in the down position. do i need to use variables? is there a script i can utilize?

    fanks

    corncob

  7. #7
    Registered User
    Join Date
    Aug 2000
    Posts
    45

    Thumbs up slowdown a loop?

    new questions... sorry to mess up this thread :\

    I'm trying to build a loop "do while" to slowly change the alpha of a MC. The loop works ok, but TOO DAMN FAST!!!!
    how can I slow down the speed of the loop?

    Code:
    lastAlpha = 1;
    function changeAlpha (state) {
        do {
            _root.pes._alpha = ++lastAlpha;
        } while (lastAlpha < state);
    }
    or instead of this funtions, I must work with diferent actions in diferent frames???

    thanX
    [Edited by Art Vandelay on 05-05-2001 at 12:01 PM]

  8. #8
    proud new daddy! LuxFX's Avatar
    Join Date
    May 2000
    Location
    Dunsinane
    Posts
    1,148
    Art, your problem is that Flash will execute the entire script on each frame before going to the next one--yet will only redraw the screen once per frame. What's happening is that your entire loop is being run before flash redraws your movieclip, so all you see is the results.

    In order to fix this, you need to create a loop between frames. The best way to do this is to create a blank movieclip that has an onClipEvent(enterframe) event set. This will 'fire' once per frame, so you can create a handmade loop like that:

    onClipEvent(enterFrame)
    {
    _root.pes._alpha == lastAlpha;
    lastAlpha++;
    }

    You'll probably have to adapt this a bit to suit your own case, but this should help you get the basics.

    cheers!

  9. #9
    Registered User
    Join Date
    Aug 2000
    Posts
    45

    Post thanX

    thanX Lux.

    I had already come to that conclusion my self, through the reading of a few posts right here in the FK Board.
    but thanks anyway for the cleareance.

    .art

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center