flash actionscript:
I am creating a website but need help on the actionscript side (which is why this is in this category). My problem: I have found a perfect Javascript to make random facts appear on my webpage, but after deciding my webpage should be in flash, I havent found a simular script for Flash. So here is what I need: a flash actionscript to make random facts appear as static text on my webpage in Flash. I already have the facts, so i just need a script to enter them in! Thanx
Here is what I would do: 1) create an array to hold all of your random facts (you could also do them in an external source like a DB or txt file) 2) generate a random number and pull that index from the array as the random fact 3) pop that string into a dynamic text field 4) whaala! :D something like this maybe: var facts:Array = ["fact1", "fact2", "fact3", "fact4", "fact5", "fact6"]; var factNum:Number = Math.round(Math.random()*(facts.length-1))+1; var factString:String = String(facts[factNum]); myTextField.text = factString; That picks a random number, pulls that array index, and pops that string into a textfield.
Ah, yes. I copied the code into Flash after creating a small dynamic text box named 'factString'. Your code was great, although i deleated the last line: myTextField.text = factString; I also removed the +1 from the second line: From - var factNum:Number = Math.round(Math.random()*(facts.length-1))+1; To - var factNum:Number = Math.round(Math.random()*(facts.length-1)); This was because of the 'undefined' of fact1, which was counted as 0. Thank you for your help - it help me solve it! Hoathy
Don't see what you're looking for? Try a search.
|