Click on Stage and using the keyboard arrows bring the disc to the base, and both will disappear !
CLICK HERE TO SEE A LIVE DEMONSTRATION OF THIS TUTORIAL COMPLETED
On this Actionscript 3.0 Flash HD High Definition Tutorial we create a base for our Flying Saucer and testing collision with an IF statement a visible property change is fired. X Files Theme is the background music.
DOWNLOAD THIS TUTORIAL TO YOUR HARD DRIVE
CLICK HERE FOR A COMPLETE ACTIONSCRIPT 3.0 CARTOON SMART TUTORIAL
Here is the source code
// Collision Between Two Objects on Stage Example
// by Avraham Saltoun
// solutions at say-web dot com
// FREE TO USE COPY AND DISTRIBUTE
stage.addEventListener(KeyboardEvent.KEY_DOWN,MoveSaucer);
//This will set the compiler
//waiting for a key stroke, and then
// execute the MoveSaucer function
function MoveSaucer (event:KeyboardEvent):void
// the void states that the function returns no value
// but receives the value of the key stroke
{
switch (event.keyCode){
case Keyboard.RIGHT:
FlyingSaucer_mc.x = FlyingSaucer_mc.x+5;
break;
// x is the coordinate for the horizontal position
// break will exit the switch and wait for
// next key stroke.
case Keyboard.LEFT:
FlyingSaucer_mc.x -=5;
// “FlyingSaucer_mc.x = FlyingSaucer_mc.x-5″
// is the same as
// “FlyingSaucer_mc.x -=5;”
break;
case Keyboard.UP:
FlyingSaucer_mc.y -=5;
break;
case Keyboard.DOWN:
FlyingSaucer_mc.y +=5;
break;
}
// This will check the collision
// between the Flying Saucer and
// the base.
if (FlyingSaucer_mc.hitTestObject(Base_mc))
{trace (“BOOOM !!!”);}
// Note both objects can be in separate layers
// instance names have to be identical to the objects
// This will happen every keystroke (Key Down) event
// Thanks for watching.
}






One Response to “ActionScript 3.0 Lesson 17: Detecting Stage Collisions Between Objects in Different Layers”
Trackbacks/Pingbacks
high bounce rates, and speedy exits on…
their most interesting pages.what’s going on?although the content is good, no-one is reading it. the way you have set out your blog means that readers leave before they realize just how good your writing is.fortunately, there are three easy steps you…