Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display of random 4 messages

Status
Not open for further replies.

onressy

Programmer
Mar 7, 2006
421
CA
Hi i have a dynamic text box on the main stage and was wondering how i can randomly display 1 or these 4 message each time:
secMessage="Message1.";
secMessage="Message2.";
secMessage="Message3.";
secMessage="Message4.";

Thanks!
 
// The number of Texts
Make a button with the instance name myBtn and a dynamic text with the instance name rText...
Copy the following code in the first frame:

Code:
var rN:Number = 3;

var rT:Array = new Array(rN);
//The list of random texts
rT[0]="Text 1";
rT[1]="Text 2";
rT[2]="Text 3";

//The button that makes the random text apear in a dynamic text
myBtn.onRelease = function() {
	var a = random(rN);
	rText.text = rT[a];
}
 
thanks brutteforcce,

so would i just set it to the text box name like so:


secMessage = rT[a];

thanks
 
You have to make a button with the instance name myBtn... If you press that button a random text will apear in a dynamic text... Make a dynamic text and give it the instance name textLoading...
Write the array with the random messages...
Set messageNum to be the number of the random messages... If you have 10 messages that var messageNum:Number = 10;


var messageNum:Number = 4;
var secMessage:Array = new Array("Message1.","Message2.","Message3.","Message4.");

myBtn.onRelease = function() {
randomNumber = random(messageNum);
textLoading.text = secMessage[randomNumber];
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top