我给你2个例子,我不太了解intrustep对象,所以我把它删除了;)
下面的代码只是用来将gamefacetemplate对象拖到一个位置(我在该位置添加了边距,所以它更灵活)如果你拖动到正确的位置,您转到第 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;
}
}