A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: creating a random number problem.

  1. #1
    Junior Member
    Join Date
    Feb 2008
    Posts
    4

    creating a random number problem.

    // Ive created an array with three items.Button named random btn is to give the result of a random number of one, two, three.
    // Now the result after the button is pressed is only selecting one random number out of the three. Then the button is repeats the result each time the button is pressed.
    as an example say the number one is chosen number one. Press the random btn and thats the only number which is choosen.



    var targetArray:Array = new Array("one", "two", "three");
    // this makes a random number
    var randomNum = random(targetArray.length);



    randomBtn.onPress = function(){
    trace(randomNum);

    }
    hansolo is online now Report Post Edit/Delete Message

  2. #2
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Not sure if I understand your question. If you limit the number of choices to the random command, then it limits your results.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  3. #3
    Junior Member
    Join Date
    Feb 2008
    Posts
    4
    no ive worked out the problem the randomNum needed to inside the handlers of the button press.


    var randomNum ="";


    var targetArray:Array = new Array("one", "two", "three");




    randomBtn.onPress = function(){
    trace(randomNum);
    randomNum = random(targetArray.length);
    }

  4. #4
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Excellent. Remember to mark this thread as resolved.
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

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