ActionScript 3.0 Lesson 17: Detecting Stage Collisions Between Objects in Different Layers


Click on Stage and using the keyboard arrows bring the disc to the base, and both will disappear !

This movie requires Flash Player 9


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 THE SOURCE FILE

DOWNLOAD THIS TUTORIAL TO YOUR HARD DRIVE
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.

}

Related Articles:



Post Footer automatically generated by Add Post Footer Plugin for wordpress.

5 Comments For This Post

  1. Wesley Nunes Says:

    Realmente é muito bom. Parabens. BRASIL Olimpiadas 2016.

  2. admin Says:

    muito obrigado, faca a assinatura, que eh gratis, e visite sempre que possa, aumentando nosso transito. Avraham Saltoun.

  3. johannes Says:

    great,it is good tutorial for beginner

  4. kevin Says:

    Hey,

    How can I get to lesson 1,2,3 etc.?

    Thanks in advance.

  5. admin Says:

    here:

    http://say-web.com/?page_id=3457

Leave a Reply

Security Code:

Adobe Flash CS4 125x125 Get Paid to Upload Video Clips
iContact.com - Email Marketing Service
Learn Creative Visualization
Web Design Top Blogs Web design blogs
Folllow LCV on Twitter Subscribe to Learn Creative Visualization on Twitter

Twitter Followers

Archives

Skype Me™!

This blog is monetized using Are-PayPal WP Plugin