-
drag and drop problem
I have a bunch of movieClips (all in one sprite) in the middle of the stage stacked one over another and one on the top is draggable.
so I start drag the top one and want to be able to drag it anywhere on the stage (within stage bounds) and when i drop it i want to reparent it to another sprite.
sounds simple?
i dont think so :D
now starting with this, when i start the drag not even bounds works as it should, like i said all movieClips are inside a sprite which is centered on stage and this bounds (as far as i figured) is taking 0,0 where a sprite 0,0 actually is, and its not at stage 0,0 because sprite (which holds all movieClips) its moved down.
I want to be able to always drag from stage 0,0... how do i define a bounds for that?
Code:
function drag(e:MouseEvent):void {//mouse down function
var bounds:Rectangle= new Rectangle(0, 0, stage.stageWidth - mcWidth, stage.stageHeight - mcHeight);
e.target.startDrag(false, bounds);
}
when i stop drag and try to reparent currently dragged movieClip to another sprite (centerSprite, which is already added to stage but is empty), i want for a dropped movieClip to stay exactly where i have let it go.... while currently all it doesnt it jumps somewhere else
Code:
function drop(e:MouseEvent):void {//mouse up function
e.target.stopDrag();
if(activeMode == "CENTER"){
if(e.target.parent.name != "centerSprite"){
centerSprite.addChild(e.target as DisplayObject);
not to mention that all this bounds has to work with stage resize as well..
help me before i kill myself :D
-
nevermind, i did manage to make it in the end :D
my bounds looks like this:
Code:
bounds = new Rectangle( - thumbSprite.x, - thumbSprite.y, stage.stageWidth - mcWidth, stage.stageHeight - mcHeight);
and when i drop the mc and reparent it i say this:
Code:
if(activeMode == "CENTER"){
if(e.target.parent.name != "centerSprite"){
var target:DisplayObject = e.target as DisplayObject;
centerSprite.addChild(target);
target.x += thumbSprite.x;
target.y += thumbSprite.y;