Actionscript 3.0 Event Listeners
May 22, 2013
Hello All,
Just trying to import an interaction I built with AS3 into Storyline. It works perfectly published as swf. and as html. When I import it and publish it seems that the listeners do not work. It's your basic collision detection function, here's the code if anyone knows what I'm missing or has the same issue please let me know. The drag and drop works fine for the bottle, but when you drag it over the boat movie clip the collision is not detected.
import flash.display.MovieClip;
import flash.events.*;
bottleMc_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);
this.addEventListener(Event.ENTER_FRAME, detectCollision);
bottleMc_mc.buttonMode = true;
function pickMe(event:MouseEvent):void
{
event.target.startDrag(true);
}
function detectCollision(event:Event)
{
if (SailBoat_mc.hitTestPoint(bottleMc_mc.x,bottleMc_mc.y,true))
{
bottleMc_mc.play();
SailBoat_mc.play();
bottleMc_mc.buttonMode = false;
bottleMc_mc.stopDrag();
this.gotoAndPlay("Deploy");
}
}
stop();
4 Replies
Hi Michael,
Try converting your local coordinates to global ones:
function detectCollision(event:Event)
{
var pt:Point = new Point(bottleMc_mc.x,bottleMc_mc.y);
pt = bottleMc_mc.parent.localToGlobal(pt);
if (SailBoat_mc.hitTestPoint(pt.x,pt.y,true))
{
bottleMc_mc.play();
SailBoat_mc.play();
bottleMc_mc.buttonMode = false;
bottleMc_mc.stopDrag();
this.gotoAndPlay("Deploy");
}
}
Thank you for that. Theodore. I'll let you know how I get on.
I tried converting coordinates to global but no joy.
OK this worked. Instead of detecting the collision through coordinates. I used the hitTestObject function and it works just fine. I don't need it to be as accurate as the hitTestPoint. but might see if I can get it to work in case I need it later. Would be good to know.
This discussion is closed. You can start a new discussion or contact Articulate Support.