A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: check variable through loop

  1. #1
    Senior Member
    Join Date
    Apr 2001
    Posts
    996

    check variable through loop

    I have a loop that is check to see if three variables are true if so then play animation.

    The problem with my code is it triggers the animation if one out of the three is =true; when it should check if all three are true then and only then should it play the animation
    Code:
    function loopShowsAnim() {
    	for (var i = 0; i < plantArr.length; i++) {
    		if (plantArr[i].deleted) {
    			trace("DELETED = "+plantArr[i].deleted);
    		animation.gotoAndPlay(1);
    		} else {
    			trace("ELse")
    			ranShowsAnim();
    // ranShowsAnim calls the function again to see if all three variables called "deleted" are == true;
    		}
    	}
    }
    What happens is if one is ==true it plays the animation and also goes to the else statement which calls the function again.
    I need to only play the animation if all three are true;

  2. #2
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554
    You won't be able for it to stop doing that unless you redo part of the function, i am still thinking about that i don't have time to rewrite it right now i am at work, sorry.
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

  3. #3
    Senior Member
    Join Date
    Apr 2001
    Posts
    996
    Ok great but if anyone else that has the time can let me know how I can fix this that would be great.

    Thanks,

  4. #4
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554
    code:

    this.onLoad = function() {
    checkdelete = 0;
    };
    function loopShowsAnim() {
    for (var i = 0; i < plantArr.length; i++) {
    if (plantArr[i].deleted) {
    trace("DELETED = "+plantArr[i].deleted);
    checkdelete++;
    }
    if(checkdelete == plantArr.length) {
    animation.gotoAndPlay(1);
    }
    if((i == plantArr.length) && (checkdelete !== plantArr.length)) {
    trace("ELse");
    ranShowsAnim();
    }
    }
    }


    sorry it might not work it is worth a try i haven't scripted since Halo 2 came out
    Last edited by joejoe2288; 01-12-2005 at 09:05 PM.
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

  5. #5
    Senior Member
    Join Date
    Apr 2001
    Posts
    996
    Thanks for the code but I tried it and it didn't work?????????

  6. #6
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554
    what went wrong?
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

  7. #7
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554
    add some traces to check what part ain't workin
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

  8. #8
    Senior Member
    Join Date
    Apr 2001
    Posts
    996
    Here is the file.
    I have changed a few things and it gets to the animation if statement but it won't clear the interval to shut off the loop.

    Here is the file
    FLA FILE

  9. #9
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    Unexpected file format! Can't open your .fla.
    You'd have a better chance of getting an answer if your .fla was in a MX only format.

    You would have to save a copy of your MX2004 .fla, (using Save as...) and changing the Document type to MX only in the Save as... window.

    Joe is on MX2004, but probably playing Halo!

  10. #10
    Senior Member
    Join Date
    Apr 2001
    Posts
    996
    Here you go let me know if this works for you. Thanks for taking the time to look at this file.
    FLASH 5 file

  11. #11
    Flashkit Veteran joejoe2288's Avatar
    Join Date
    Apr 2004
    Location
    Hickville, Oregon
    Posts
    2,554
    LOL you are psycic you newb i was playing Halo, i will check it out when i get home.
    So tired of all the fighting....

    http://joejoe2288.kawanda.net

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