Sunday, 27 February 2011

Don’t press button

I was contacted with a question about how to create “the delay button” part in the idiot test game (try Googling the game). In the idiot test game you answer a series of questions to determine if you’re an idiot. Here is my solution. 

Step 1

Open a new AS3 file and add the following layers on the timeline in this order: Actions, Win, Lose, and Button. The layers should look like the image below.

Step 2

On the Button layer, add an arcade button onto the stage by going to Window > Common library > Buttons. Locate the folder classic buttons and drag a red button onto the stage. Give the button the instance name: redbutton. Then select the Text tool with static text and type the message: ‘Do not press the button’. I have used Verdana font with 30pt size for my message. Select both the button and text and convert it to a movie clip with the instance name: holder.

Step 3

Lock and hide the Button layer on the timeline and select the Win layer. Select the Text tool with static text and add the following message: ‘Well done, you win nothing.’ Convert the text into a movie clip and give the instance name: win

Step 4 

Repeat the same step as above, but change the message to: ‘You lose’ and give the instance name: lose.

Step 5

Select the Actions layer then open the actions panel and add the following code:

//Time delay of two minutes
var delay:int = 120 * 1000;

//Hides the win and lose messages
win.visible = lose.visible = false;

//This creates a new instance of the timer class and starts the timer
var timer:Timer = new Timer(delay);
timer.addEventListener(TimerEvent.TIMER, timerHandler);

//This function displays the win message if you have waited the delay time
function timerHandler(e:TimerEvent):void{
    win.visible = true;
    lose.visible = false;
    holder.visible = false;

//Adds the mouse click event to the red button
holder.redbutton.addEventListener(MouseEvent.CLICK, clickHandler);

//This function displays the lose message and stop the timer.
function clickHandler(e:MouseEvent):void{
    win.visible = false;
    lose.visible = true;
    holder.visible = false;

Step 6

Test your movie Ctrl + Enter.


  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP