这是一个简单的拖放游戏"。我有4个拖动的movieClips(巴黎,伦敦等)和4个放置的movieClips,你需要放置拖动的对象(paris_match,london_match等)。
1)那么,如何使用删除的movieClip创建正确的数组? 2)如何在掉落的地方之间交换拖拽的物体?
非常感谢。
package {
import flash.display.MovieClip;
import flash.events.*;
import flash.geom.Point;
public class Travelling extends MovieClip
{
protected var originalPosition:Point;
protected var hitArray:Array; // EDIT
public function Travelling()
{
originalPosition = new Point(x, y);
hitArray = new Array("paris_match" , "berlin_match" , "rome_match" , "london_match"); // Edit
buttonMode = true;
addEventListener(MouseEvent.MOUSE_DOWN, down);
}
protected function down(e:MouseEvent):void
{
parent.addChild(this);
startDrag();
addEventListener(MouseEvent.MOUSE_UP, stageUp);
}
protected function stageUp(e:Event):void
{
stage.removeEventListener(MouseEvent.MOUSE_UP, stageUp);
stopDrag();
if(dropTarget) {
for (var i = 0; i < hitArray.length; i++) { // Edit
// !!!!!------This Array works not correctly-----!!!!!
if (dropTarget.parent.name == hitArray[i]) { // Edit
x = dropTarget.parent.x;
y = dropTarget.parent.y;
} else {
returnToOriginalPosition();
}
} // EDIT
} else {
returnToOriginalPosition();
}
}
protected function returnToOriginalPosition():void
{
x = originalPosition.x;
y = originalPosition.y;
}
}
}