3

我有一个带有背景的richText,我想用鼠标移动它

所以我写了下面的代码:(richText是一个全局字段)

public function createRichText(textPoint:Point):RichText {
richText = new RichText();  
    var measure:String = correlationMeasure.toFixed(4).toString();
    richText.text = measure;
    richText.x = textPoint.x; 
    richText.y = textPoint.y; 
    richText.width = 60;
    richText.height = 24;
    richText.setStyle("fontSize", 11);
    richText.setStyle("horizontalCenter", "0");
    richText.setStyle("verticalCenter", "1");
    richText.setStyle("left", "2");
    richText.setStyle("right", "2");
    richText.setStyle("top", "5");
    richText.setStyle("bottom", "5");
    richText.setStyle("textAlign", "center");
    richText.setStyle("verticalAlign", "middle");
    richText.setStyle("backgroundColor", 0xe6e91f);
    richText.setStyle("backgroundAlpha", 1);
        richText.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler, false, 10);
        richText.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler, false, 10);
return richText
}


private function mouseDownHandler(e:MouseEvent):void {
    e.stopPropagation();
    allowDraging = true;
    richText.addEventListener(MouseEvent.MOUSE_MOVE, dragWithMouse);
}
private function dragWithMouse(e:MouseEvent):void {
    if (allowDraging) {
        e.stopPropagation();
        var temp:Point = richText.contentToGlobal(new Point(e.localX, e.localY));
        mousePoint = rootComponent.globalToLocal(temp);

        removeChild(richText);
        addChild(createRichText(mousePoint));
        e.updateAfterEvent();*/
    }
}

但它不能正常工作......意味着它不会随着鼠标移动而连续移动并且有跳跃!有谁知道为什么?

4

1 回答 1

2

尝试类中定义的startDrag()stopDrag()方法Sprite

  private function mouseUpHandler(e:MouseEvent):void {
      e.stopPropagation();
      richText.stopDrag();
  }

  private function mouseDownHandler(e:MouseEvent):void {
       e.stopPropagation();
       richText.startDrag();
 }
于 2013-06-20T08:40:35.407 回答