A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: [RESOLVED] checking dynamic numbers in a loop...

  1. #1
    Animal Flasher RobbieC's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    242

    resolved [RESOLVED] checking dynamic numbers in a loop...

    Hi there, I'm having a bit of trouble with a script to check a 'dynamic number'...

    Basically, I've got a movie which plays in a loop and each time it goes around, it clicks up a number, which I have on the stage as 'dynamic text' called "ImageNumber" - this bit is working fine it uses the following code to add:

    Code:
    var count:uint = count+1;
    ImageNumber.text=count.toString();
    I have a second 'dynamic number' called "numberOfImages" and what I need to happen, is that the 'loop' checks "numberOfImages" and when that number is reached, "ImageNumber" is reset to '0' so that the count begins again...

    Probably really basic if/else statement, but I just can't get my head 'round it...

    If anyone can point me in the right direction, I'd be most grateful

    Thanks in advance

    Rob

  2. #2
    Member
    Join Date
    Dec 2009
    Posts
    50
    Well, really var count will be the equivalent of your ImageNumber, so:
    PHP Code:
    if (count >= numberOfImages) {
    count 0

    Just watch where you put that stuff; make sure that count isn't going to change on you when you DON'T want it to.
    EDIT: I suggest you put it between the two lines you just showed.

  3. #3
    Animal Flasher RobbieC's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    242
    thanks Multihunter, I was thinking along that line earlier, but it comes up with an error:

    1176: Comparison between a value with static type uint and a possibly unrelated type String.

  4. #4
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    numberOfImages should be datatyped to a int or uint.

    var numberOfImages:uint;

  5. #5
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,836
    if a number is contained in a string then it will stay a string until you convert it. You can convert it like this: Number(myString). That will change the number in myString to an actual number that you'll be able to use in the comparison.
    .

  6. #6
    Animal Flasher RobbieC's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    242

    resolved

    Awesome stuff chaps, got it all working now

    Thanks for all your help and enlightenment

    Rob

  7. #7
    Animal Flasher RobbieC's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    242
    Just one more thing on this topic....

    Is it possible using Math.random() to set the start number between 0 and 'numberOfImages' randomly?

    ie. randomize the first image that is shown, then continue as before...

  8. #8
    Member
    Join Date
    Dec 2009
    Posts
    50
    Ok, so if I understand correctly, you have:
    PHP Code:
    var count:uint count+
    looped?

    You're declaring it a new variable every loop. You only need to delcare it once, so at the beginning of your code have:
    PHP Code:
    var count:uint Math.ceil(Math.random()*numberOfImages
    then, in the loop have:
    PHP Code:
    count += 
    Which is the same as:
    PHP Code:
    count count 

  9. #9
    Animal Flasher RobbieC's Avatar
    Join Date
    Aug 2001
    Location
    England
    Posts
    242
    brilliant MultiHunter to the rescue again!

    Thanks for your help buddy

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