-
AS£unsure how to
Code:
package com
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.geom.Point;
public class dragitem1 extends MovieClip
{
protected var dropTarget1Full:Number = 0;
protected var dropTarget2Full:Number = 0;
protected var dropTarget3Full:Number = 0;
protected var dropTarget4Full:Number = 0;
protected var dropTarget5Full:Number = 0;
protected var dropTarget6Full:Number = 0;
protected var originalPosition:Point;
public function dragitem1()
{
originalPosition = new Point(x,y);
buttonMode = true;
addEventListener(MouseEvent.MOUSE_DOWN, down);
}
protected function down(event:MouseEvent):void
{
startDrag();
parent.addChild(this);
stage.addEventListener(MouseEvent.MOUSE_UP, stageUp);
}
protected function stageUp(event:MouseEvent):void
{
stage.removeEventListener(MouseEvent.MOUSE_UP, stageUp);
stopDrag();
if (dropTarget)
{
if (dropTarget.parent.name == "dropTarget1" && dropTarget1Full==0)
{
this.x = dropTarget.parent.x
this.y = dropTarget.parent.y
dropTarget1Full = 1
//trace(dropTarget1Full)
}else if(dropTarget.parent.name == "dropTarget2" && dropTarget2Full==0)
{
this.x = dropTarget.parent.x
this.y = dropTarget.parent.y
dropTarget2Full = 1
}else if(dropTarget.parent.name == "dropTarget3" && dropTarget3Full==0)
{
this.x = dropTarget.parent.x
this.y = dropTarget.parent.y
dropTarget3Full = 1
}else if(dropTarget.parent.name == "dropTarget4" && dropTarget4Full==0)
{
this.x = dropTarget.parent.x
this.y = dropTarget.parent.y
dropTarget4Full = 1
}else if(dropTarget.parent.name == "dropTarget5" && dropTarget5Full==0)
{
this.x = dropTarget.parent.x
this.y = dropTarget.parent.y
dropTarget5Full = 1
}else if(dropTarget.parent.name == "dropTarget6" && dropTarget5Full==0)
{
this.x = dropTarget.parent.x
this.y = dropTarget.parent.y
dropTarget6Full = 1
}else if (dropTarget.parent.name == "BinMC")
{
scaleX = scaleY = 0.2;
alpha = 0.2;
x = stage.width + width + 10;
MovieClip(root).BinMC.gotoAndPlay(2);
buttonMode = false;
removeEventListener(MouseEvent.MOUSE_DOWN, down);
}
else
{
returntoOriginalPosition();
}
}
else
{
returntoOriginalPosition();
}
}
protected function returntoOriginalPosition():void
{
x = originalPosition.x;
y = originalPosition.y;
}
}
}
-
Did you have a question?
Why are you using Numbers as booleans? Why does your class not start with a capital letter? Why are you putting it in the com package? This class is also tightly coupled with the structure of the droptargets and the BinMC. You should not be matching using names, and you should be setting the valid targets from outside this class. You have a copy and paste error in the dropTarget6 case where you are checking dropTarget5Full again. If you set the targets from outside and put them in an array, you wouldn't have to repeat your code 6 times, and you could use an arbitrary number of targets.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|