Skip to main content
Inspiring
September 3, 2011
Question

Hunting the yoyo blue box

  • September 3, 2011
  • 2 replies
  • 1537 views

Hello world,

As I said in an earlier post, I am ready to do some target shooting. I drew a box, gave it a name, and making it move in a yoyo manner horizontally. What I want to, is the following:

Every time I detect a collision, I will hear a different sound. Instead of my usual bang.mp3, it's going to be bang2. mp3.  But I have a problem about the collision. Is it going to be between my movieclip_1 and my_box, or

boom( the impact hole) and the my_box. I understand the collision thing, but it is still a mystery, like the seasons and the tide of the sea. here the code:

import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;

var myTween = new Tween(my_box,"x",Strong.easeInOut,10,600,1,true);

myTween.addEventListener(TweenEvent.MOTION_FINISH, onFinish);
function onFinish(e:TweenEvent):void
{
e.target.yoyo();
}

var mySound1:Sound = new Sound();
var myChannel1:SoundChannel = new SoundChannel();
mySound1.load(new URLRequest("bang2.mp3"));


var mySound:Sound = new Sound();
var myChannel:SoundChannel = new SoundChannel();
mySound.load(new URLRequest("bang.mp3"));

stage.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);

this.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_2);
function fl_MouseClickHandler_2(event:MouseEvent):void
{
if (movieClip_1.hitBool)
{
  mySound.play(1,1);

  var boom:Boom=new Boom();

  addChild(boom);


  boom.x = mouseX;// not sure this is what you want form x,y

  boom.y = mouseY;


}
}

stage.addChild(movieClip_1);
movieClip_1.mouseEnabled = false;
movieClip_1.addEventListener(Event.ENTER_FRAME, fl_CustomMouseCursor_2);
function fl_CustomMouseCursor_2(event:Event)
{

if (movieClip_1.hitTestPoint(stage.mouseX,stage.mouseY))
{

  movieClip_1.hitBool = true;

}
else
{

  movieClip_1.hitBool = false;

}

movieClip_1.x = stage.mouseX;
movieClip_1.y = stage.mouseY;
}
Mouse.hide();

This topic has been closed for replies.

2 replies

SamsimmsAuthor
Inspiring
September 3, 2011

problem solved.

SamsimmsAuthor
Inspiring
September 3, 2011

Hi again

I mean, when I click my button ( movieclip_1), and my impact hole(boom) hits the moving box(my_box), it'll be a different sound(bang1.mp3). My intuition is telling me that the contact should be between the impact hole(boom) and the blue box(my_box).

StoneChameleon
Inspiring
September 3, 2011

Your intuition is correct. You'll want the collision to happen between two objects, not just when a user clicks the button (they'd never miss that way). So, yes, impact hits target and bang.

SamsimmsAuthor
Inspiring
September 3, 2011

Hi

But pratically, what should I do ? Do I create a new function for the purpose of the collision between the impact hole movie clip and the box, or just use an existing function and incorporate the if condition. Je n'en ai aucune idée. Nothing. Nada. Walou. Nimic. Niente. Because, I already have a hit test in the code.

stage.addEventListener(Event.ENTER_FRAME, detectHit);
function detectHit(e:Event) :void {
    if(boom.hitTestObject(my_box)){

      ??????????????

     }
}