Thursday, 8 October 2009

Clicking game in Actionscript 3

This is an update from the previous clicking game in AS2. The steps in this tutorial are exactly the same as the previous one, only the code has been converted into Actionscript 3.0. So, be sure to checkout the previous tutorial.

//Initially set the ball invisible.
ball_mc.visible=false;

//Variables for the hits and total.
var total:uint=0;
var hits:uint=0;
var end:uint=20;

//Event listener with the click mouse event.
ball_mc.addEventListener(MouseEvent.CLICK, ballClick);

//Increases the hit count by one.
function ballClick(event:MouseEvent):void {
hits++;
}

function seeBall() {
//Displays the hits and the total.
hits_txt.text=String(hits);
total_txt.text=String(total);

//If the end points is less than the total points then the ball will
//will be display randomly on the stage, and the total count will increase.
if (total < end) {
ball_mc.x=Math.random()*300;
ball_mc.y=Math.random()*300;
ball_mc.visible=true;
total++;
} else {
ball_mc.visible=false;
gotoAndStop("1", "Scene 3");
clearInterval(doball);
}
}

var doball=setInterval(seeBall,800);


You should get the following game, once you have completed all the steps from the previous tutorial.



If you have any questions feel free to leave any comments below.

0 comments:

  COPYRIGHT © 2014 · ILIKE2FLASH · Theme by Ourblogtemplates

Back to TOP