This one works, only problem that it shots off the event listener for the duration. So if I used it for other things I'll need to separate them with other listener/function.
import flash.events.MouseEvent;
import flash.events.Event;
stop();
button1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler1);
function mouseDownHandler1(event: MouseEvent): void {
yesh8gBall21.gotoAndPlay(1);
}
this.addEventListener(Event.ENTER_FRAME, handle8Collision2);
function handle8Collision2(evt: Event): void {
if (yesh8gBall21.hitTestObject(yesh8allBuckets1)) {
removeEventListener(Event.ENTER_FRAME, handle8Collision2);
yesh8allBuckets1.nextFrame();
}
}
then add your event listener when the ball is clicked:
|
import flash.events.MouseEvent;
import flash.events.Event;
stop();
button1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler1);
function mouseDownHandler1(event: MouseEvent): void {
yesh8gBall21.gotoAndPlay(1);
this.addEventListener(Event.ENTER_FRAME, handle8Collision2);
}
function handle8Collision2(evt: Event): void {
if (yesh8gBall21.hitTestObject(yesh8allBuckets1)) {
this.removeEventListener(Event.ENTER_FRAME, handle8Collision2);
yesh8allBuckets1.nextFrame();
}
}
|
p.s. you should also remove the event listener if the bucket is not hit, too.