I’m creating a flash application that lets you drag and drop items from a toybox or library area onto specific landing pads, to create custom designs within rooms.
I have movieclip landing pads/targets on the main timeline named drop1, drop2, drop3… through drop7. I have the following code attached to a toy (movieclip) in the toybox:
onClipEvent (load) {
// determine starting point of item
origin_x = this._x;
origin_y = this._y;
// holds which landing pad is selected
_root.dropSelection = 1;
// build array for landing pads
var drops = new Array(8);
for (var i = 1; i<=drops.length-1; i++) {
drops* = "_parent.drop"+i;
trace(drops*);
}
// build array for snap position for x coordinate when mouse is released
var dropPosX = new Array(8);
for (var i = 1; i<=dropPosX.length-1; i++) {
dropPosX* = "_parent.drop"+i+"._x";
}
// build array for snap position for y coordinate when mouse is released
var dropPosY = new Array(8);
for (var i = 1; i<=dropPosY.length-1; i++) {
dropPosY* = "_parent.drop"+i+"._y";
}
}
onClipEvent (enterFrame) {
// landing pad detection script
}
onClipEvent (mouseDown) {
// test if the mouse is within the movieclip and if so do stuff
if (this.hitTest(_root._xMouse, _root._yMouse)) {
// hide movieclip containing initial user instructions text
_root.helpTag._visible = false;
// pick up the item
this.startDrag();
// changes the look of the movieclip while dragging
gotoAndStop(2);
}
}
onClipEvent (mouseUp) {
// drop item
this.stopDrag();
// tests if the item is over the intended target and if so does stuff
if (this.hitTest(drops[_root.dropSelection])) {
this.gotoAndStop(2);
// this should snap the item to the land pad's position but it doesn't
this._x = dropPosX[_root.dropSelection];
this._y = dropPosY[_root.dropSelection];
} else {
// if object isn't over a landing pad, push it back to the toybox
this.gotoAndStop(1);
this._x = origin_x;
this._y = origin_y;
trace("not in the zone");
}
}
I’m having trouble figuring out why the array I’ve built isn’t triggering the snap into place when I let go of the item. Also I’m trying to determine the best method for detecting which landing pad the item is being dragged over. I’ve set the root variable dropSelection to 1 just to test the interaction over the first landind pad. Currently with the gotoAndPlay(2) command the movieclip that is being dragged changes to different icon that is just as big as the landing pads. All the landing pads are close togethor so right now it would be easy to overlap which could be a problem in determining which pad to snap to which I’m not sure how to fix.
Any help would be appreciated. Thank you.
Chris