I'm attempting to create a Jigsaw Puzzle in Flash cs6 (Actionscript 3.0), here is my code:
import flash.events.Event;
import flash.events.MouseEvent;
addEventListener(Event.ENTER_FRAME,onenter);
stop();
function pickupObject(event:MouseEvent):void
{
event.target.startDrag(true);
}
function dropObject(event:MouseEvent):void
{
event.target.stopDrag();
}
function dropTarg(event:MouseEvent):void
{
event.target.stopDrag(x,y);
}
function onenter(event:Event)
{
var pieces = [p1,p2,p3,p4,p5,p6];
var targets = [target1,target2,target3,target4,target5,target6]
var targ = [p1.targ1,p2.targ2,p3.targ3,p4.targ4,p5.targ5,p6.targ6]
var xcoord = [241.00,374.40,529.85]
var ycoord = [224.65,224.65,224.65]
for each (var i in pieces)
{
i.buttonMode = true;
i.addEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
i.addEventListener(MouseEvent.MOUSE_UP, dropObject);
if (targets[i].hitTestObject(i.targ[i]))
{
//i.removeEventListener(MouseEvent.MOUSE_UP,dropObject);
i.x = xcoord[i];
i.y = ycoord[i];
//i.addEventListener(MouseEvent.MOUSE_UP,dropObject);
}
}
}
What I am trying to achieve is basically, if user clicks on say p1 (this object has another known as targ within its layers) and that targ hits the corresponding target, then the object will snap into play at x, y coordinate.
The error I am getting is TypeError: Error #1010: A term is undefined and has no properties. at JigSawWithArrays_fla::MainTimeline/onenter()
Which leads me to believe I am not referencing/accessing the arrays correctly.
Is this doable? I am a newbie to Flash cs6 and would appreciate some guidance on this.
Thanks in advance.