How do i get Random pick on screen

Posted on 2008-11-11
Last Modified: 2012-08-13
Hello Flash Expert,

I want to make a simple quiz program in flash.
i have 4 words,   word 1, word 2, word3, word4.
Now i want flash to pick randomly one of these words and show
them on the stage in dynamic textfield.

Underneath the word i would like another dynamic textfield
where flash will randomly pick a number between 1 and 10 and show this on the screen.
You're help is very appreciated.
Question by:stevenvervliet
    LVL 39

    Accepted Solution

    Hi, I'm not using CS4 but how to create a random number,  straight out of the help file

    //Returns a pseudo-random number n, where 0 <= n < 1. The number returned is called a "pseudo-random" number because it is, technically, calculated in an undisclosed manner.

    function randRange(min:Number, max:Number):Number {
        var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
        return randomNum;

    how you'd implement this

    mytextfield.text = randRange(1, 10);

    to pick a word store your words in an array, use the random number generator to generate a number from 0 to the length of the array minus 1 and the word will be

    var selectedWord:String  = yourArray[numberGenerated];


    Author Comment

    Hello Blue-genie,

    Thank you very much for you're reply.
    Ok, like you say i store my 4 words in an array,
    So in the first frame i put in actionscript


    Now in Frame 2 i put a dynamic textfiled
    but the Variable line is in grey, and when i click on it says

    This feature is not supported by actionscript 3.0
    To use these feature you must target 2.0 of 1.0

    Is there another way to get this done in actionscript 3.0?

    Kind regards

    LVL 39

    Expert Comment

    yeah you have to set i manually

    ie. mytextfieldname.text = myvaraiblevalue.

    ps. how's your experience with CS4 so far?

    Author Comment

    Hello Bleu-Genie,

    Well, to be honest the only thing i can say about it, it looks good, better
    then the previous versions, if it works better then previous ones, I Don't Know.
    I think i'd learn more from you're comment on this, you're a proffesional flash user,
    why didn't you upgrade yet to CS4?  Are there bad things about it?

    Now i notice using variables is not an option anymore in Actionscript 3.0
    When i target action script 2.0 or 1.0, i still can put variables, and my words display
    randomly on the screen. I only worry that if i continue like this, i would miss out
    on the benefits of using actionscript 3.0 further on in my project.
    So if variables are not used anymore in actionscript 3.0, by what have they been replaced?

    Kind regards

    LVL 39

    Expert Comment

    you can't specify a variable on a dynamic textfield and it just pops up anymore
    variables haven't been replaced, it's just now following good Object Oriented Programming practice :-)
    you have to create instance variables etc.

    its tedious but like most things once you know how its easy.
    i haven't upgraded yet because i haven't been able to convince my boss to buy it yet

    Author Closing Comment

    Thanks for you're help Blue-Genie

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    Title # Comments Views Activity
    SWF won't scale? 4 510
    Download slideshow or picture elements 16 411
    Action Script commands 4 300
    video live streaming 1 107
    This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
    Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
    In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
    The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now