我不知道如何获取有关字母放在哪个插槽上方的信息,因此这些字母只会捕捉到最后一个插槽,因为它是唯一正确引用的插槽。谁能告诉我一种方法来检查字母落在哪个对象(插槽)上方?我创建的两种电影剪辑只是字母的背景和放置它的插槽。
var myFormat:TextFormat = new TextFormat();
myFormat.color = 0xFFFFFF;
myFormat.font = "Verdana";
myFormat.size = 35;
myFormat.bold = true;
myFormat.align = TextFormatAlign.CENTER;
var myString:String = "firefly"
myString = myString.toUpperCase();
var myArray:Array = myString.split('');
for(var i:Number = 0; i < myString.length; i++) {
var myBogstav:bogstav = new bogstav();
var myBogstavSlot:bogstavSlot = new bogstavSlot();
var myText:TextField = new TextField();
myText.selectable = false;
myText.width = 50;
myText.height = 50;
addChild(myBogstavSlot);
addChild(myBogstav);
myBogstav.addChild(myText);
myText.defaultTextFormat = myFormat;
myText.text = myArray[i];
myBogstavSlot.name = "bogstavSlot" + i;
myText.name = "bogstav" + i;
myBogstav.name = "bogstavBG" + i;
myBogstavSlot.x = i*60 + 10;
myBogstavSlot.y = myBogstav.y - 100;
myBogstav.x = i*60 + 10;
myBogstav.addEventListener(MouseEvent.MOUSE_DOWN, ClickToDrag);
myBogstav.addEventListener(MouseEvent.MOUSE_UP, releaseToDrop);
}
var startPosition:Point;
function ClickToDrag(event:MouseEvent):void
{
setChildIndex(event.target.parent, numChildren - 1);
event.target.parent.alpha = 0.6;
startPosition = new Point(event.target.parent.x, event.target.parent.y);
event.target.parent.startDrag();
}
function releaseToDrop(event:MouseEvent):void
{
setChildIndex(event.target.parent, 0);
event.target.parent.alpha = 1;
event.target.parent.stopDrag();
if (event.target.parent.hitTestObject(MovieClip)){
event.target.parent.x = MovieClip.x;
event.target.parent.y = MovieClip.y;
} else {
event.target.parent.x = startPosition.x;
event.target.parent.y = startPosition.y;
}
}
任何帮助深表感谢。