我給你2個exemples,所以我只是刪除它,我不很瞭解的intrustep對象;)
下面的代碼只是用來將gamefacetemplate對象拖到一個位置(i增加利潤率的位置,它更靈活),如果拖動到正確的位置,則轉到第5幀,否則對象將返回到初始位置。因此,有兩種解決方案: 如果你想拖動到位置
激活下一步:
gamefacetemplate.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2);
// maybe you want to keep te original position of the dragin object
var originalPos:Point;
function fl_ClickToDrag_2(event:MouseEvent):void
{
// keep original position
originalPos = new Point(gamefacetemplate.x, gamefacetemplate.y);
// start dragging
gamefacetemplate.startDrag();
// listen mouse mouve event
gamefacetemplate.addEventListener(MouseEvent.MOUSE_MOVE, fl_ObjectPosition);
// listen mouse up event
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
}
function fl_ObjectPosition(event:MouseEvent):void
{
// test if the object is in a range of acceptable position
if(gamefacetemplate.x > 650 && gamefacetemplate < 750 && gamefacetemplate.y > 250 && gamefacetemplate.y < 350)
{
// place item at the right position
gamefacetemplate.x = 706;
gamefacetemplate.y = 311;
// stop dragging
gamefacetemplate.stopDrag();
// and so remove the listeners
stage.aremoveEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
gamefacetemplate.removeEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2);
gamefacetemplate.removeEventListener(MouseEvent.MOUSE_MOVE, fl_ObjectPosition);
// and maybe activate next step
gotoAndStop(5);
}
}
function fl_ReleaseToDrop(e:MouseEvent):void
{
// stop dragging
gamefacetemplate.stopDrag();
// replace item at original position
gamefacetemplate.x = originalPos.x;
gamefacetemplate.y = originalPos.y;
// and so remove the listeners
stage.aremoveEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
gamefacetemplate.removeEventListener(MouseEvent.MOUSE_MOVE, fl_ObjectPosition);
}
,或者如果你想在降位置激活下一步:
gamefacetemplate.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2);
// maybe you want to keep te original position of the dragin object
var originalPos:Point;
function fl_ClickToDrag_2(event:MouseEvent):void
{
// keep original position
originalPos = new Point(gamefacetemplate.x, gamefacetemplate.y);
// start dragging
gamefacetemplate.startDrag();
// listen for mouse up event
stage.addEventListener(MouseEvent.MOUSE_UP, fl_ObjectPosition);
}
function fl_ObjectPosition(event:MouseEvent):void
{
// maybe here you want to stop dragging
gamefacetemplate.stopDrag();
// test if the object is in a range of acceptable position
if(gamefacetemplate.x > 650 && gamefacetemplate < 750 && gamefacetemplate.y > 250 && gamefacetemplate.y < 350)
{
// place item at the right position
gamefacetemplate.x = 706;
gamefacetemplate.y = 311;
// and so remove the listeners
stage.aremoveEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
gamefacetemplate.removeEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2);
// and maybe activate next step
gotoAndStop(5);
}
else
{
// replace item at original position
gamefacetemplate.x = originalPos.x;
gamefacetemplate.y = originalPos.y;
}
}
第一,大括號之間的最後兩行不正確。看起來你可能想在那裏定義一個函數?其次,我沒有看到任何看起來像條件的東西。 – Ronnie