# Draggable MC, Class & Casting

**URL:** <https://forum.kirupa.com/t/draggable-mc-class-casting/233528>\
**Category:** flash\
**Created:** [July 24, 2007, 6:42pm UTC](https://forum.kirupa.com/t/draggable-mc-class-casting/233528 "2007-07-24T18:42:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lonerhino](https://avatars.discourse-cdn.com/v4/letter/l/45deac/32.png) [@lonerhino](https://forum.kirupa.com/u/lonerhino)\
**Post date:** [July 24, 2007, 6:42pm UTC](https://forum.kirupa.com/t/draggable-mc-class-casting/233528/1 "2007-07-24T18:42:24Z")

</div>

Let’s say I wish to drag a panel but only from a strip at the top. I put a MovieClip named mcBar inside a MovieClip named mcPanel.  
When I code frame one in the timeline it works.

[AS]  
mcPanel.mcBar.addEventListener(MouseEvent.MOUSE\_DOWN, downHandle);  
mcPanel.mcBar.addEventListener(MouseEvent.MOUSE\_UP, upHandle);

function downHandle(evtObj:MouseEvent):void{

```
              this.startDrag();

```

}

function upHandle(evtObj:MouseEvent):void{

```
              this.stopDrag();

```

}  
[/AS]

What’s confusing is that it works. Why is the whole thing dragging? I’m assuming it’s event propagation? mcBar’s mouse down is “bubbling” to mcPanel… Even though this is exactly what I want – Don’t completely understand it.

Now, further complication is when I move the code to a class.

[AS]  
package{

```
//imports
import flash.display.MovieClip;
import flash.events.MouseEvent;

public class DraggableClip extends MovieClip{
    
    //constructor
    public function DraggableClip(){
        
        this.addEventListener(MouseEvent.MOUSE_DOWN, downHandler);
        this.addEventListener(MouseEvent.MOUSE_UP, upHandler);
    }
    
    //methods
    function downHandle(evtObj:MouseEvent):void{

        parent.startDrag();
    }

    function upHandle(evtObj:MouseEvent):void{

        parent.stopDrag();

    }
}

```

}  
[/AS]

Now, if I assign mcBar via \*Linkage \*to DraggableClip.as, only the bar drags. This is the behavior I would have expected when I initially coded the timeline. However, I really do want the entire panel to drag so how do I target it?

As the target for the drag methods:

\*\*this \*\*refers to the instance of the class(mcBar only) , \*\*parent \*\*throws a _1061: Call to a possibly undefined method startDrag through a reference with static type flash.display:DisplayObjectContainer. error._

I found a drag MC sample from Jen deHaan that had\*\*: var thisMC:MovieClip = event.currentTarget as MovieClip;\*\*

I barely understand that this is a Casting Operation…Is this what I’m missing?

In Summary:  
[LIST]  
[\*]What do I need to do to get mcBar inside mcPanel to drag _both mcBar and mcPanel from code in a class?  
[]Also if my issue is with casting, why?  
[_]In my deHaan sample, why legacy \*\*as \*\*operator vs **type(expression)**?[/LIST]  
Thanks for any/all insight.
