Saturday, 27 March 2010

Create a scratch card in Actionscript 3 part 2

This is part 2 of the scratch card tutorial where I will add a random background to the scratch card. So every time you scratch the card you get a different background. You could also add a different message if you wish.

Create a scratch card in Actionscript 3 part 2

Step 1

Open up part 1 of the tutorial. Then Import the images you want to use into the library by selecting File > Import > Import to library on the menu bar. I have used free stock images, but you can use any images you wish.

Step 2

On the stage, double click on the maskedbg_mc movie clip to enter its timeline. Now insert a new key frame (F6) and add a new image on to the stage. Repeat this if you have more images. On timeline insert a new layer and call it Actions then open up the actions panel and the following code: stop().

Step 3

Return to the main timeline and open up the Actions panel and add the following lines of code.

//This gets a random number between the number of frames in the 
//masked_bg movie clip.
var r:int = 1 + Math.random() * maskedbg_mc.totalFrames;

//This will stop at a random frame so you will get a random image.

Step 4

Test your movie Ctrl + Enter.

Try refreshing the page after you have scratch the card and you should get a different image.


  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP