A Flash Developer Resource Site

Results 1 to 20 of 20

Thread: Stopping A "while" Loop

  1. #1
    Member
    Join Date
    Feb 2001
    Posts
    61

    Stopping A "while" Loop

    Hi,

    I'm using Flash MX

    I got this open source code to create a lighting effect off of text. I am using the effect for an intro to a website. My problem is that I have not been able to stop the loop.

    i = "1";
    alpha = "0.8";
    maxlight = "20";
    while (Number(i)<=Number(maxlight)) {
    duplicateMovieClip("ray0", "ray" add i, 800-i);
    setProperty("/ray" add i, _xscale, getProperty("/ray" add (i-1), _xscale)+i*alpha);
    setProperty("/ray" add i, _yscale, getProperty("/ray" add (i-1), _yscale)+i*alpha);
    setProperty("/ray" add i, _alpha, 10-i*(0.5/50));
    i = Number(i)+1;
    }
    setProperty("ray0", _visible, "0");

    I have tried 'break' but, because I'm not entirely sure of the syntax, it breaks the entire clip before it even starts. I've used "removeMovieClip" as well, but I think the problem here is addressing the the duplicated movie clip correctly. I have tried addressing it as, "ray0," "ray" and "/ray" and none of them work.

    I just want this thing to iterate about three times and then jump to another clip.

    Any help would be appreciated. Thanks beforehand!

  2. #2
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    you need to set an instance on your created mc instead of just naming it

    ive named the mc your copying to mctocopy
    and named the new mc to copiedmc
    thats easy enough for you to see
    use:
    Code:
    var copiedmc = mctocopy.duplicateMovieClip("copiedmc", 1);
    1 is the depth, so change that with your 800-i or whatever, now your new mc is named copiedmc so then you use it as a instance inside of the setproperty so

    setProperty(copiedmc, _xscale, 200);

    the rest of the script looks right and your while loop should end when Number(i)<=Number(maxlight)
    if you need it to end before that for whatever reason then just kill the loop by writing Number(i) = Number(maxlight); inside the loop, if you understand what ive done there only because i dont particularly know how to end the while loop properly :/ ive never used it as ive only ever really used for and i use break to end it, hope that helps

  3. #3
    Member
    Join Date
    Feb 2001
    Posts
    61
    Thanks for the detailed info. I'll give this a shot and see how it works. I think that giving an instance name to the copied movie clip will make it much more manageable. Thanks. I'll get back about this.

  4. #4
    Member
    Join Date
    Feb 2001
    Posts
    61
    Okay. If I replace out "/ray" with "copiedmc" this is the renewed code:

    i = "1";
    alpha = "0.8";
    maxlight = "20";
    var copiedmc = mctocopy.duplicateMovieClip("copiedmc", 1);

    while (Number(i)<=Number(maxlight)) {
    duplicateMovieClip("ray0", "ray" add i, 800-i);
    setProperty("copiedmc" add i, _xscale, getProperty("copiedmc" add (i-1), _xscale)+i*alpha);
    setProperty("copiedmc" add i, _yscale, getProperty("copiedmc" add (i-1), _yscale)+i*alpha);
    setProperty("copiedmc" add i, _alpha, 10-i*(0.5/50));
    i = Number(i)+1;
    }
    setProperty("ray0", _visible, "0");

    The movie doesn't run at all with this code. I probably misinterpreted something. Any idea? Should I also add "copiedmc" to this line:

    duplicateMovieClip("ray0", "ray" add i, 800-i);

    so it now becomes:

    duplicateMovieClip("ray0", "copiedmc" add i, 800-i);
    Last edited by vincognito; 07-17-2010 at 04:22 PM.

  5. #5
    Member
    Join Date
    Feb 2001
    Posts
    61
    Looks like I answered my own question. It is running now. Thanks. I'll see what I can do now to manipulate it...

  6. #6
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    hey sorry for my slow reaction on your reply, does it work now yes ?

  7. #7
    Member
    Join Date
    Feb 2001
    Posts
    61
    Nope. I can't control it yet.

  8. #8
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    ahh i see your mistake already i think it is, youve used "" on the already created object

    you put::
    setProperty("copiedmc" add i, _xscale, getProperty("copiedmc" add (i-1), _xscale)+i*alpha);

    it should be::
    setProperty(copiedmc add i, _xscale, getProperty(copiedmc add (i-1), _xscale)+i*alpha);

    NOTE
    "copiedmc" is a string
    copiedmc is a variable/instance/name

    you get it ?

  9. #9
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    what do you mean you cant control it yet ?

  10. #10
    Member
    Join Date
    Feb 2001
    Posts
    61
    Quote Originally Posted by milna93 View Post

    you get it ?
    Yep. I understand. I'll change that out, even though, for some reason it still works the way it is.

    What I mean about controlling it is that I want the effect to simply stop (or better, alpha out to zero), at frame 440 on the main timeline. I'm having hell getting it to stop. I mean, I can throw the "break" command in but then it doesn't run at all.

    Basically, whatever I've tried either doesn't start the movie, or starts it and it goes infinitely. Basically, I want to get it to stop entirely after about two or three iterations of the effect.

    I hope I'm making sense here...

  11. #11
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    well if you want it to only do it 2 or 3 times then why are you using while ? haha ill write the whole script out for you how it should be hang on a minute

  12. #12
    Member
    Join Date
    Feb 2001
    Posts
    61
    Quote Originally Posted by milna93 View Post
    well if you want it to only do it 2 or 3 times then why are you using while ? haha ill write the whole script out for you how it should be hang on a minute
    I didn't write the script. It was open source. Sometimes I can look at scripts and figure out what they're doing and then tweak them from there, but I've always been crappy at building code from scratch.

    I appreciate your help!

  13. #13
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    haha no problem sorry i taking ages :P ive got 2 computers, my coding one which has flash on but without internet and this computer with internet but without flash haha so i have to type everything back up into my other comp to test and the write back into this

  14. #14
    Member
    Join Date
    Feb 2001
    Posts
    61
    Quote Originally Posted by milna93 View Post
    haha no problem sorry i taking ages :P ive got 2 computers, my coding one which has flash on but without internet and this computer with internet but without flash haha so i have to type everything back up into my other comp to test and the write back into this
    You're one patient, dude. Thanks a lot. I'll hang on for your next reply.

  15. #15
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    ahh i just realised why you dont actually see the animation thing, because it does it all at once mate, because the loop happens the millesecond the swf is opened

  16. #16
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    there you go, editted code for you to mess round with that will actually work this time :P paste that code into frame 1 of a new actionscript 2 flash file, dont have any more frames, then draw a box in the middle of the screen and give it a black border and a lightish blue inside, select it all and press F8, then make it into a movieclip, then go onto propertys and change the instance name to mctocopy and then play the movie 8)

    Code:
    maxlight = 10;
    j = 0;
    timer = 100;
    
    countdown = function(){
    	
    j++
    ralpha = 100 - (10 * j);
    rxyscale = 100 + (10 * j);
    raynew = "ray" + [j];
    var raynew = mctocopy.duplicateMovieClip(raynew, j);
    
    setProperty("ray" + [j], _xscale, rxyscale);
    setProperty("ray" + [j], _yscale, rxyscale);
    setProperty("ray" + [j], _alpha, ralpha);
    
    if(timer==0){
    clearInterval(countdownInterval);
    }
    }
    countdownInterval = setInterval(countdown,500);

  17. #17
    Member
    Join Date
    Feb 2001
    Posts
    61
    Thanks. I'll give it a shot. Much appreciated. I'm running out to do some stuff, but I'll get back later or tomorrow on it.

  18. #18
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    okay dude :P i will edit the script a lil bit and make it better then haha then i helpin sum other dude with his thing, he seems rather impatient and if he continues being so impatient i wont help him

  19. #19
    Member
    Join Date
    Feb 2001
    Posts
    61
    Okay. Well, I did everything exactly as you wrote, but nothing at all happened. But that's okay. I solved the problem by using a loadMovie into an empty movie clip. When I want it to go away, I just use unloadMovie.

    So, problem solved! Thanks for all of your help. It is totally appreciated!

  20. #20
    Senior Member
    Join Date
    Apr 2009
    Posts
    117
    haha no problem man

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