1

嗨,我之前在 AS3 中做过一些 Flash 动画,所有这些动画都可以在 Captivate 5.5 中导入并运行良好。然而,其中之一,一个简单的拖放游戏是行不通的。它导入并在迷人的情况下可见,一切都解决了一个(恼人的)问题。也就是说,对象不会掉落到适当的放置区域。动画在我的浏览器中作为 SWF 可以正常工作,但在吸引任何想法时无法正常工作?代码大纲如下。我正在撕扯我的头发,任何建议将不胜感激。

代码:

right_mc.visible=false; 
wrong_mc.visible=false;
var orig1X:Number=item1_mc.x;  
var orig1Y:Number=item1_mc.y;
item1_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
item1_mc.addEventListener(MouseEvent.MOUSE_UP, item1Release);
item1_mc.buttonMode=true;    

function dragTheObject(event:MouseEvent):void { 
    var item:MovieClip=MovieClip(event.target); 
    item.startDrag(); 
  var topPos:uint=this.numChildren-1; 
    this.setChildIndex(item, topPos);    
}  

function item1Release(event:MouseEvent):void { 
    var item:MovieClip=MovieClip(event.target); 
    item.stopDrag();       
    if (dropZone1_mc.hitTestPoint(item.x,item.y)) { 
        item.x=dropZone1_mc.x; 
        item.y=dropZone1_mc.y; 
    } else { 
       item.x=orig1X; 
       item.y=orig1Y; 
    } 
};    

done_btn.addEventListener(MouseEvent.CLICK,checkAnswers);
function checkAnswers(event:MouseEvent):void { 
    if (dropZone1_mc.hitTestPoint(item1_mc.x,item1_mc.y) &&
     dropZone16_mc.hitTestPoint(item16_mc.x,item16_mc.y)) {
        wrong_mc.visible = false;
        right_mc.visible = true;
    } else {
        wrong_mc.visible = true;
        right_mc.visible = false;
    }
}

reset_btn.addEventListener(MouseEvent.CLICK,reset);
function reset(event:MouseEvent):void { 
    item1_mc.x=orig1X; 
    item1_mc.y=orig1Y;     

    right_mc.visible=false; 
    wrong_mc.visible=false; 
}
4

1 回答 1

1

因为hitTestPoint仅适用于全局坐标。当您在浏览器中打开 SWF 时,本地和全局坐标是相同的,这就是它起作用的原因。但是当您将其加载到 Captivate 中时,它们会有所不同。

尝试这个:

import flash.geom.Point;

// ...

var localPoint:Point = new Point(item.x, item.y);
var globalPoint:Point = item.parent.localToGlobal(localPoint);
if (dropZone1_mc.hitTestPoint(globalPoint.x, globalPoint.y)) { 
    item.x = dropZone1_mc.x;
    item.y = dropZone1_mc.y;
}

// ...
于 2014-12-18T03:14:19.477 回答