EDIT: If I have a class called Items and it has a movieclip instance which is loaded from a url. The startDrag on item fails. If Items contains a movieclip which we initiate from a SWC (not load it) on Drag works fine.
编辑:如果我有一个名为Items的类,它有一个从网址加载的movieclip实例。项目的startDrag失败。如果Items包含一个动画片段,我们从一个SWC(不加载它)开始拖动工作正常。
Now how to solve the issue where I have a class which has a movieClip loaded from outside.
现在如何解决我有一个从外面加载movieClip的类的问题。
I have the following code:
我有以下代码:
package { import flash.display.Sprite; import flash.events.MouseEvent;
package {import flash.display.Sprite; import flash.events.MouseEvent;
import lib.CustomEvents.ItemLoadCompleteEvent;
import lib.Room.Item;
import lib.Room.ItemStruct;
public class DragTest extends Sprite
{
private var itemInstance:Item;
public function DragTest()
{
var tempItemStruct:ItemStruct = new ItemStruct("test",0,0,200,250,"wall","","inventory");
itemInstance = new Item(tempItemStruct);
itemInstance.addEventListener(ItemLoadCompleteEvent.CONTROL_TYPE,loadComplete);
stage.addEventListener(MouseEvent.MOUSE_UP,mouseUp);
}
private function loadComplete(e:ItemLoadCompleteEvent):void
{
itemInstance.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
this.addChild(itemInstance);
}
private function mouseUp(e:MouseEvent):void
{
itemInstance.stopDrag();
trace("MouseUp");
}
private function mouseDown(e:MouseEvent):void
{
itemInstance.startDrag();
trace("MouseDown");
}
}
}
I have used the same code with a normal clip and it works. When I use it with my own defined item it does not work. Here are the details.
我使用相同的代码与普通剪辑,它的工作原理。当我将它与我自己定义的项目一起使用时,它不起作用。这是细节。
itemStruct: containing the properties of the item to be made. item : Loads the itemstruct defined item and puts it in a movieclip (item is inherited from movieclip)
itemStruct:包含要生成的项的属性。 item:加载itemstruct定义的项目并将其放入movieclip(项目继承自movieclip)
Traces from the above code, show that only the mouseUp function works mouseDown does not work. Though the same code works fine for a simple movieclip
从上面的代码跟踪,显示只有mouseUp函数工作mouseDown不起作用。虽然相同的代码适用于简单的动画片段
I have already tried
我已经试过了
stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDown);
EDIT: I have tried put the mouseDown on stage again if I click outside the item and drag from stage it both mouseDown and Up seem to work. But If I click on the item and drag. Still no luck. I have also added the item as movieclip on stage.
编辑:我已经尝试将mouseDown再次放在舞台上,如果我在项目外单击并从舞台拖动它mouseDown和Up似乎都工作。但如果我点击该项目并拖动。仍然没有运气。我还在舞台上将项目添加为movieclip。
1 个解决方案
#1
0
the event is probably being dispatched from the loaded clip, not item itself. Try using the mouseChildren property to catch all events.
事件可能是从加载的剪辑发送的,而不是项目本身。尝试使用mouseChildren属性捕获所有事件。
item.mouseChildren = false;
#1
0
the event is probably being dispatched from the loaded clip, not item itself. Try using the mouseChildren property to catch all events.
事件可能是从加载的剪辑发送的,而不是项目本身。尝试使用mouseChildren属性捕获所有事件。
item.mouseChildren = false;