• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 508
  • Last Modified:

How do i get Random pick on screen

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.
0
stevenvervliet
Asked:
stevenvervliet
  • 3
  • 3
1 Solution
 
blue-genieCommented:
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];

blu
0
 
stevenvervlietAuthor Commented:
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

my_arr=["word1","word2","word3","word4"];
num=random(4);
whichword=my_arr[num];

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
Steven

0
 
blue-genieCommented:
yeah you have to set i manually

ie. mytextfieldname.text = myvaraiblevalue.

ps. how's your experience with CS4 so far?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
stevenvervlietAuthor Commented:
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
Steven


0
 
blue-genieCommented:
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
:-)
0
 
stevenvervlietAuthor Commented:
Thanks for you're help Blue-Genie
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now