A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: How to loop a movie twice?

  1. #1
    Junior Member
    Join Date
    Apr 2000
    Posts
    4

    Question

    Hi,

    I would like to loop a movie twice. How should I write the script?

    I add an action to the last frame of the movie, a ball jumping for example which has one layer only. Below are the codes I wrote:

    Set Variable:"index" = "1"
    If (index < 3)
    Go to and Play (1)
    Set Variable:"index" = "index + 1"
    End If

    The above codes seems to cause the movie to loop infinitely. How should I loop a movie twice? And how should I loop a movie that has a lot of layers?


    Thanks for your help.

  2. #2
    The Supreme Shaman and Keeper of Polar Lights
    Join Date
    Apr 2000
    Posts
    1,175

    Post

    Hi !

    Just say in last keyframe

    If (something=1)
    Stop
    Else
    Set Variable: "something" = "1"
    End If



    ------------------
    Good luck !
    Ilya. -Polar Lights Studios-
    Flash sources page

  3. #3
    Junior Member
    Join Date
    Apr 2000
    Posts
    4

    Smile

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Ilya:
    Hi !

    Just say in last keyframe

    If (something=1)
    Stop
    Else
    Set Variable: "something" = "1"
    End If


    <HR></BLOCKQUOTE>

    ==============================
    Thanks Ilya. It works.

    However, why when it is replayed, it won't loop twice?

  4. #4
    The Supreme Shaman and Keeper of Polar Lights
    Join Date
    Apr 2000
    Posts
    1,175

    Post

    Hi !

    Before replaying try say
    Set Variable: "something" = "0"



    ------------------
    Good luck !
    Ilya. -Polar Lights Studios-
    Flash sources page

  5. #5
    Junior Member
    Join Date
    Apr 2000
    Posts
    4

    Smile

    Hi Ilya,

    I have tried putting this line:

    Set Variable:"something" = "0"

    before the if..else statements. But this will cause the movie to loop infinitely.

    What could be wrong?

  6. #6
    Junior Member
    Join Date
    Mar 2000
    Posts
    18

    Post

    Set Variable:"index" = "1"
    If (index &lt; 3)
    Go to and Play (1)
    Set Variable:"index" = "index + 1"
    End If


    You need to remove some quotes:


    Set Variable:"index" = 1
    If (index &lt; 3)
    Go to and Play (1)
    Set Variable:"index" = index + 1
    End If


    Try That...

    DD

  7. #7
    Senior Member
    Join Date
    Mar 2000
    Posts
    235

    Post

    your problem is;
    Set Variable:"index" = "1"

    every time it get to the frame it resets "index" to 1 so it will never be 3

    you don't need;
    Set Variable:"index" = "1"

    has it will assume that it is zero

    you just need

    if (index &lt; 2)
    Go to and Play (1)
    Set Variable:"index" = "index + 1"
    End If

    This should work

    CheerZ
    rosie


  8. #8
    Junior Member
    Join Date
    Mar 2000
    Posts
    18

    Post



    Didnt see that problem with setting index to 1 every loop. That's a problem too.

    Good luck in fixing it


    DD

  9. #9
    Junior Member
    Join Date
    Mar 2000
    Location
    Seattle, WA
    Posts
    19

    Post

    I recommend incrementing your index before your go to and play...better coding practice, plus I'm not sure how flash interprets commands after a Goto statment..

    if (index &lt; 2)
    Set Variable:"index" = "index + 1"
    Go to and Play (1)
    End If


  10. #10
    The Supreme Shaman and Keeper of Polar Lights
    Join Date
    Apr 2000
    Posts
    1,175

    Cool

    Hi again onk !

    I dont know why, but now i don't understand what is the problem
    Can you just put .fla somethere and say URL ?

    ------------------
    Good luck !
    Ilya. -Polar Lights Studios-
    Flash sources page

  11. #11
    Junior Member
    Join Date
    Apr 2000
    Posts
    4

    Wink

    Hi all,

    Thanks for your help. It still loops infinitely.

    The following code works but it will not loop when it is replayed:

    If(index = 1)
    stop
    Else
    Set Variable:"index" = "1"
    End If

    So the following statement is added before the if...else statement:

    Set Variable:"index" = "0"

    But this cause the infinite loop again.

    I think the reason is because....
    when the index is first set to 0, it will enter the else loop, so index will become 1 and come out of the loop. Then it will start from the begining of the coding again. And the index is set to 0 again and went into the else loop again.

    This will cause it to loop infinitely.

    So I tried to search Flash Help whether it has while loop. I think it doesn't, only have Loop While(). So I tried the following:

    Set Variable:"index" = "0"
    Loop While(index &lt; 2)
    If(index = 1)
    stop
    Else
    Set Variable:"index" = "1"
    End If
    End Loop

    However, this doesn't help too. Anyway, my assignment is done. Just want to know why it cannot loop twice when it is replayed.

    Thanks a lot. If you have a better way to loop a movie, do let me know.

  12. #12
    Senior Member
    Join Date
    Mar 2000
    Posts
    472

    Cool

    I assume when you say "loop a movie twice", what you want is to play your movie 2 times and stop it. Following that theory:

    Last frame of movie:

    If (count &lt; 1)...(or N)
    Set Variable: "count" = count + 1
    Go to and Play(1)
    Else
    Stop
    End If

    Where "count" will always = (boolean)0 if it hasn't been initialized, as in the first play of the movie. This makes the movie into a 2 frame loop...another way to loop instead of using "Loop While"...you can also control the speed of the loop by adding frames between the keyframes.

    For frame 1's initializing of "count" = 1 (or more):

    Frame 1:

    Set Variable: "count" = 1 (or n)

    Frame 2:

    No actions

    Frame 3

    If (count &lt; N)
    Set Variable: "count" = count + 1
    Go to and Play(2)
    Else
    Stop
    End If

    ------------------

    Count ends at N, movie stops.

    ------------------
    Wright Internet Solutions
    productions@wisolutions.london.on.ca
    DickeeDive: Your Stringed Instruments Connection

    [This message has been edited by Dickee (edited 28 April 2000).]

  13. #13
    Junior Member
    Join Date
    Apr 2000
    Posts
    7

    Post

    Make the 1rst and 2nd frames of your movie identical.
    Use the loop code that was working for you without reseting the variable to 0 at the beginning.
    Except have the go to pointing at frame 2.

    have variable = 0
    at frame 1
    then a go to a play frame 3
    (so that you don't play the duplicate frame in 2)

    Hope this works for you.

  14. #14
    Junior Member
    Join Date
    Apr 2000
    Posts
    11

    Post

    Guys, allways use initialisiton frames, and whole bunch of such problems simply go away.

    Just use some dummy keyframes before *real* start to setup global vars (vars that should be static) and youre done. In the example above do:

    1st dummy keyframe - Set Variable "z" = 1

    (movie starts at 2nd - label "Start")

    last keyframe - If (z=2)
    Stop
    Else
    Set variable "z" = z + 1
    Go to and Play (Start)
    EndIf
    It will loop exactly twice.
    Best,
    Igor

  15. #15
    Junior Member
    Join Date
    May 2006
    Posts
    3

    Best solution

    Answer of all answers
    ===============

    Create a new layer in your flash file, name it Actionscript. On the first frame of the movie on the actionscript layer, insert this :

    _global.z = 0;

    Now, move the rest of your movie layers (not actionscript layer) so that there is nothing else on frame 1 besides the actionscript layer.

    Now, make a new keyframe one frame after the last frame of your movie on the actionscript layer. Insert this code :

    if (_global.z == 3)
    {
    stop();
    }
    else
    {
    _global.z = _global.z + 1;
    gotoAndPlay(2);
    }

    You can change 3 to be however many times you want the movie to loop. That's all.

  16. #16
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    Just put this in the last frame of you movie..u dont need to do anything else:

    Code:
    var noOfLoops = 2;
    
    if (loop == undefined) {
    	loop = 1;
    } else {
    	loop++;
    	if (loop == noOfLoops) {
    		stop();
    	}
    }
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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