【问题标题】:Spawn MC addChild to stage but how to tie in the draggable function? AS3Spawn MC addChild 到舞台但如何配合可拖动功能? AS3
【发布时间】:2014-01-25 02:01:39
【问题描述】:

我在制作影片剪辑时遇到了一些问题,因此我可以在舞台上拖动它。场景:用户单击将影片剪辑生成到舞台的按钮,从那里他们可以在舞台周围移动项目 - 这是一个可拖动的对象。我可以让它生成movieClip,我可以让它拖动……但是一旦我尝试附加拖动功能,我就不能同时做到这两个。请问有什么指点吗?我是 as3 的新手! :-)

spawner_btn.addEventListener(MouseEvent.CLICK, spawnspinkjewel);

function spawnspinkjewel(event:MouseEvent):void
{
  var myChild:pink_jewel= new pink_jewel();
  stage.addChild(myChild)
myChild.x=300; 
    myChild.y=150;
} 
pink_jewel.addEventListener(MouseEvent.MOUSE_DOWN, pickupblack_pink_jewel);
pink_jewel.addEventListener(MouseEvent.MOUSE_UP, dropblack_pink_jewel);

function pickupblack_pink_jewel(event:MouseEvent):void {
event.target.startDrag(true);
}
function dropblack_pink_jewel(event:MouseEvent):void {
event.target.stopDrag();
}

【问题讨论】:

    标签: actionscript-3 flash drag-and-drop mouseevent addchild


    【解决方案1】:

    您将侦听器添加到不正确的对象。

    改变这个:

    pink_jewel.addEventListener(MouseEvent.MOUSE_DOWN, pickupblack_pink_jewel);
    pink_jewel.addEventListener(MouseEvent.MOUSE_UP, dropblack_pink_jewel);
    

    到这里:

    myChild.addEventListener(MouseEvent.MOUSE_DOWN, pickupblack_pink_jewel);
    myChild.addEventListener(MouseEvent.MOUSE_UP, dropblack_pink_jewel);
    

    【讨论】:

    • 您好,看起来很简单,谢谢。如果有机会,我会拥有一辆油轮。
    • 你好,好吧,还是有点卡住了。影片剪辑出现在舞台上……但我无法拖动对象。它出现在我的光标上方,我已将光标移动到时间线的顶层。有什么线索或建议吗?
    • 在你的开始和停止拖动中试试这个:(e.target as MovieClip).startDrag( true );,然后分别是(e.target as MovieClip).stopDrag()
    猜你喜欢
    • 1970-01-01
    • 2012-03-13
    • 2011-09-05
    • 2012-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多