.
Hit test in actionscript 3
In this Flash tutorial you will learn to use actionscript 3 to make a simple hit test, one of the most used functions and defenently needed if you want to make a flash game.
First off we will need to make two things, and object to move, in this case a ball, then the ground, so with the oval tool draw a ball, right click it and convert it to a movie clip, go to the properties panel and give it an instance name as shown below. I named mine ball.


Now with the rectangle tool make the ground and place it under our ball, right click and convert it to a movie clip, give it an instance name, I called mine ground.

Now the last thing we need so to hit F9 and type in our actionscript code, the lines with // infront of them is comments explaining the code, thats all the grey text, I have tried to explain it as simple as possible.
//Because this is AS3 everything needs to be called through
//eventlisteners, so this first lin calls and listens for the ball
ball.addEventListener(Event.ENTER_FRAME, enter_frame);
//here is our function, it is called at the beginning of the movie
function enter_frame(event:Event):void{
//An if statement, saying if the ball touches the ground,
//then just make a trace of text.
if (ball.hitTestObject(ground)) {
trace("ball is on the ground")
} else {
ball.y += 10
}
}
Now test your movie, if the ball hits the ground it should stop.
Ari says: 2010-04-11
aaron says: 2008-11-10
Kaylan says: 2008-09-07
www.moremoney.tk says: 2008-07-19
Bee says: 2008-06-25
Bee says: 2008-06-25
Bee says: 2008-06-25
Andrew says: 2008-04-10
Hank says: 2008-03-05
Admin Bob says: 2008-03-02
1031 says: 2008-03-02
Admin Bob says: 2008-02-27
Burned says: 2008-02-26
swallowprincess says: 2008-02-25
zeshan says: 2008-02-13
Vlad says: 2008-01-30
Admin bob says: 2008-01-27
Lu says: 2008-01-25

