This is my first real programming endeavor and this is the last thing holding my little project back from being a success.
My goal with this code is to add event listeners to an array of Movie Clips that will drag and drop them on the stage.
Here is the code:
var itemBank:Array = new Array(d1_anim.drawer1.test01.movieClip_1, d1_anim.drawer1.test01.movieClip_2);
for(var i:int = 0; i < itemBank.length; i++) {
itemBank[i].buttonMode = true;
itemBank[i].addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
itemBank[i].addEventListener(MouseEvent.MOUSE_UP, dropOff);
trace("pickUp added to " + itemBank[i]);
}
function pickUp(event:MouseEvent):void
{
event.target.startDrag(true);
trace("Draging " + event.target);
}
Right now the MC does not drag and the trace statement says:
pickUp added to [object MovieClip]
EDIT:
Here is my fla, I give up. I don’t know why it wont work. Please help.
[Download it here](Edit: removed download link)
Your current code has been tested and works fine. The error must be somewhere else.
If you want the test code i used you can download the source here: Drag & Drop Source File (Same code as yours, this is just a proof that it works).
EDIT: Here are the changes that i made to your code to make it work. Read the comments for better understanding. I also changed the registration point of the
d1_anim.drawer1.test01.hair1movie clip to center instead of top-left, this is needed to make it work.And here is a link to the working .fla