A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: New To Action Script - Random # generator

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    4

    New To Action Script - Random # generator

    So I am new to flash and totally confusing php syntax and other syntax when trying to join together variables with static strings.

    Here is my code below.


    var ranimage = "images/good";
    var rannumimage = ranimage + [Math.floor(Math.random() * 3) + 1] + ".gif";

    loadMovie(rannumimage, luck);



    Pretty much this is what I want to happen....

    runnuimage should create

    images/good1.gif
    images/good2.gif
    images/good3.gif

    Am I on the correct path?

  2. #2
    Junior Member
    Join Date
    Oct 2011
    Posts
    4
    Ok so I kind of got it.

    var i:Number = Math.floor(Math.random() * 3) + 1;
    var mcname:String = "images/good" + i + ".gif";

    This works when I trace it.... But now I am loading this into my movie.... I will tell you guys if I have any other issues!

    Thanks

  3. #3
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    yes you are..

    this what you';d get:

    var ranimage = "images/good";
    var rannumimage = ranimage + [Math.floor(Math.random() * 3) + 1] + ".gif";
    trace(rannumimage); //ie: images/good2.gif


    now it will NOT load those images in the order you posted.. (as you have it randomly getting the image name)..

    you will also have duplicates possibly..


    I suggest getting used to using TRACE() actions..so you can follow your code..

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