startDrag、stopDrag有个很蛋碎的地方,浪费了我一早上。蛋疼的地方如一下代码:
package
{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
public class testDrag extends Sprite
{
private var bg:Sprite=new Sprite();
private var bg1:Sprite=new Sprite();
public function testDrag()
{
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.align=StageAlign.TOP_LEFT;
bg.graphics.beginFill(0xcccccc,0.5);
bg.graphics.drawRoundRect(10,10,50,50,8,8);
bg.graphics.endFill();
addChild(bg);
bg.addEventListener(MouseEvent.MOUSE_DOWN,dowmHander);
bg.addEventListener(MouseEvent.MOUSE_UP,upHander);
bg1.graphics.beginFill(0xff0000,0.5);
bg1.graphics.drawRoundRect(100,100,50,50,8,8);
bg1.graphics.endFill();
addChild(bg1);
stage.addEventListener(MouseEvent.MOUSE_DOWN,stagupHander)
}
protected function stagupHander(event:MouseEvent):void
{
bg1.stopDrag();
}
protected function upHander(event:MouseEvent):void
{
bg.stopDrag();
}
protected function dowmHander(event:MouseEvent):void
{
bg.startDrag(false,new Rectangle(10,10,100,50));
}
}
}
这样的bg是拖动不了的,因为有一个bg1停止拖动了,所以导致全部都停止了。