A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [F8] random update

  1. #1
    Senior Member gordonart's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    267

    [F8] random update

    I have a button when pressed gives random words from an Array. My idea was that every time I press the button two new random words appear in the dynamic textbox but it doesn´t. I have a button which remove the words but when press the random-word-button again, the same words as before appear again.
    Something basic is missing I guess.

    ------

    words = new Array;
    words =["jaså","evert","olle","affär","bostad","julknapp "];
    var val1 = words [Math.round(Math.random()*6)];
    var val2 = words [Math.round(Math.random()*6)];

    _root.ord1 = ""; //dynamic textbox
    _root.ord2 = ""; //dynamic textbox

    _root.knapp.onPress = function(){
    _root.ord1 = val1;
    _root.ord2 = val2;
    }

    ////
    _root.knapp2.onPress = function(){
    _root.ord1 = "";
    _root.ord2 = "";
    }
    Mattias Gordon
    illustrator/ animator

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe try something like this...

    Code:
    words = new Array();
    words = ["jaså", "evert", "olle", "affär", "bostad", "julknapp"];
    _root.ord1 = "";
    //dynamic textbox
    _root.ord2 = "";
    //dynamic textbox
    _root.knapp.onPress = function() {
    	_root.ord1 = words[Math.round(Math.random()*5)];
    	_root.ord2 = words[Math.round(Math.random()*5)];
    };
    ////
    _root.knapp2.onPress = function() {
    	_root.ord1 = "";
    	_root.ord2 = "";
    };
    Last edited by dawsonk; 12-12-2006 at 05:20 PM.

  3. #3
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    well
    Code:
    number = random(100);
    will generate a random number between 0 -100 then you could use the number as a variable identifier something like var 1 = myword.

  4. #4
    Senior Member gordonart's Avatar
    Join Date
    Jun 2003
    Location
    Sweden
    Posts
    267
    Yes of course, I had the random variable outside the onPress-function so it would only update when the film loaded. thanks.
    Mattias Gordon
    illustrator/ animator

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