Skip to main content
Participant
March 31, 2012
Answered

Press button to show random image

  • March 31, 2012
  • 1 reply
  • 975 views

Hello,

I'm used to working with the timeline and don't often go into the actionscript side of things.

I've created a 60 second animation of an hourglass timer counting down, and next to it, is a card showing a word. I need this whole animation to play when you hit a 'start game' button and also I need the word on the card to be a random word. All of the words are saved as separate vector files for now.

What is the best way to manage this on the timeline, and what would be the code to make a random image appear?

The only discussions I've found on this are for memory games and they're over complex for what I need!

This topic has been closed for replies.
Correct answer lauracostelloe

I just thought I'd put the answer incase anyone else needs help with this.

In the end I added each image as an individual frame on the same layer within a movie clip and added a stop(); action to each frame.

I added this line of code to the key frame with the movieclip on the timeline:

this.MovieClipName.gotoAndPlay(Math.round(Math.random()* 4));   //change 4 to the number of frames you have in the movieclip

Works great so far - I'll let you know if it throws up extra problems

1 reply

kglad
Community Expert
Community Expert
March 31, 2012

make your words into movieclips and place them all on-stage and assign instance names for them all.  you can then use the visible property to select one to make visible.

if you name them judiciously (eg, mc0,m1,...,mcN), you'll save yourself some coding effort.

Participant
March 31, 2012

Thanks for the help,

how can I randomise which one is visible?

lauracostelloeAuthorCorrect answer
Participant
March 31, 2012

I just thought I'd put the answer incase anyone else needs help with this.

In the end I added each image as an individual frame on the same layer within a movie clip and added a stop(); action to each frame.

I added this line of code to the key frame with the movieclip on the timeline:

this.MovieClipName.gotoAndPlay(Math.round(Math.random()* 4));   //change 4 to the number of frames you have in the movieclip

Works great so far - I'll let you know if it throws up extra problems