• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Press button to show random image

Community Beginner ,
Mar 30, 2012 Mar 30, 2012

Copy link to clipboard

Copied

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!

TOPICS
ActionScript

Views

858

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Mar 31, 2012 Mar 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

Votes

Translate

Translate
Community Expert ,
Mar 30, 2012 Mar 30, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 30, 2012 Mar 30, 2012

Copy link to clipboard

Copied

Thanks for the help,

how can I randomise which one is visible?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 31, 2012 Mar 31, 2012

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines