2013-06-20 103 views
3

鼠標移動而移動的富文本我有背景的富文本,我想用鼠標移動與柔性

,所以我下面寫的代碼移動這樣的:(富文本是一個全球性的領域)

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();*/ 
    } 
} 

但它不能正常工作......意味着它不會隨着鼠標移動而連續移動並跳躍!有誰知道爲什麼?

回答

2

嘗試在Sprite類中定義的startDrag()stopDrag()方法:

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

    private function mouseDownHandler(e:MouseEvent):void { 
     e.stopPropagation(); 
     richText.startDrag(); 
} 
+0

謝謝@Pan它的工作...但我有問題,我得出兩個矩形之間的線路連接器,這是富文本中的中間那條線......你知道如何用這個richText移動這條線嗎? – sami

+0

嘗試將richText和line放入像sprite,canvas等容器中,然後將鼠標事件添加到容器中,就像上面 – Pan

+0

我會......謝謝 – sami