开发者

Dragging not working on Custom class inherited from Moviclip

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.

Now how to solve the issue where I have a class which has a movieClip loaded from outside.

I have the following code:

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 hav开发者_Go百科e 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)

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

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.


the event is probably being dispatched from the loaded clip, not item itself. Try using the mouseChildren property to catch all events.

 item.mouseChildren = false;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜