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.