Clicking game part 1
Step 1
Open a new flash document. Set the width to 500px and height to 400px. And then choose whatever background colour you wish.
Import your image you wish to use as your clicking object by selecting File > Import > Import in stage select your object then click ok. I used a football as my clicking object, but you use whatever you wish.
If you don’t want to import an image you could alternatively create your clicking object using the oval tool at this stage.
Step 2
Convert your clicking object into a button by selecting F8. Give your object an appropriate name > check button and click ok. And give your button the instance name “btn”.

Now convert your button instance into a movie clip by selecting F8. Give your object an appropriate name > check movie clip and click ok. And give your movie clip the instance name “ball”.

So, you should now have button instance inside a movie clip instance.
Step 3
On the top right hand corner of the stage create the following:

The “Hits” and “Total” are static text. And the boxes adjacent the static texts are dynamic text with the border around text checked.

Give each of the corresponding dynamic text the variable name “hits” and “total”.
Step 4
On the timeline insert a new layer called “actions” right click on the 1st frame and select actions from the drop down menu.
Add the following code:
ball._visible = false;
total = 0;
hits = 0;
end = 20;
ball.btn.onPress = function(){
_root.hits++;
};
seeBall = function(){
if (total < end){
ball._x = Math.random()*400;
ball._y = Math.random()*400;
ball._visible = true;
total++;
}else{
ball._visible = false;
}
};
setInterval(seeBall,800);
**This piece of code makes your clicking object move to a random place on the stage. The “hits” increment by a factor of 1 when the object is clicked. The object moves randomly 20 times, but this can be easily changed. When the total reaches 20 the game ends. You can alternatively use a countdown timer.
The setinterval function moves the object repeatedly every 800 milliseconds. Decreasing the time will make the object move faster.
Step 5
Test your movie clip Ctrl + enter.
You should now have a clicking game.
Checkout Clicking game part 2.



6 comments:
hi., i think there are bugs in the code provided
@Gangadhar - The bugs are now fixed.
is there a way to have the "ball" appear all over the screen. Not just up and down?
I want a text to appear when the game is "done" - after the 20 showups. Like "Well done - you scored 18!" or "Try again"
How to do this?
@Jebee checkout Clicking game part 2
@Elcid812
The ball should appear ramdomly on the screen.
Post a Comment