Skip to main content
Inspiring
May 21, 2011
Answered

startDrag movie Clip disapears

  • May 21, 2011
  • 1 reply
  • 993 views

I'm making a game where I have units that can move from square to square  kind of like a game of risk but with squares.  I want the units to be able to be dragged from one square to another.  When I use the startDrag function on my unit it disapears.

public function Unit(mainMC:MovieClip){
        mainClip = mainMC;
        addEventListener(MouseEvent.CLICK, clicked);
        addEventListener(MouseEvent.MOUSE_DOWN, heldDown);
        addEventListener(MouseEvent.MOUSE_UP, released);
    }

//this is in Worker which extends Unit

override public function heldDown(e:Event):void{
            var posX = currentSquare.x - currentSquare.width;
            var posY = currentSquare.y - currentSquare.height;
            var w = currentSquare.width * 3;
            var h = currentSquare.height * 3;
            startDrag(false, new Rectangle(posX, posY, w, h));
        }

so my workers show up in the square just fine.  they just disapear when I drag them.  some other minor details are:

everything is in a big main MovieClip, class Square extends MovieClip and there is a .jpg on the bottom on the main MC.  so the child level order is .jpg, then Squares, then the squares have Units (if they have units).  Units are added to the Squares not the main MC

any help would be great

This topic has been closed for replies.
Correct answer Ned Murphy

So for now I took out the bounding rectangle (I still want it) and now I can move my units.  However, this brings up another problem.  I have an image in each square and sometimes my units is above that image and sometimes it's below it.  I want the unit to be above the image all the time.  any suggestions


In your heldDown function you should be able to use the addChild() method to bring the dragged object above other content.

1 reply

markerline
Inspiring
May 21, 2011

I have run into similar problems before and the only solution at the time was setting the attribute

mouseChildren=false;

So in your case I guess you would use mainClip.mouseChildren=false;

I'm not positive that will work and I'm not sure I'm addressing the correct instance with that example but whichever the event target is you should try to set that property and see if the problem goes away.

-markerline

Inspiring
May 21, 2011

mainClip.mouseChilden?  I can't find that attribute in the docs and it doesn't turn blue in flash.  But it doesn't throw a runtime error either.  I'm confused about that one.

but I figured out that the unit is draging.  It just got moved off the stage.  can anyone spot the error in my code that would allow that

markerline
Inspiring
May 21, 2011

Here's the link for the Display Object mouseChildren Boolean property:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObjectContainer.html

It's the ActionScript 3.0 reference .

By the way, are you a soccer player or a football player?