2010-04-03 62 views
0

所以我試圖在畫布中拖動一些圖像。在flex中拖動組件

我添加事件監聽器的組件和調用的startDrag()和調用stopDrag()來接他們和東西:

component.addEventListener(的MouseEvent.MOUSE_DOWN,component.startDrag)

的問題是它在(0,0)位置選擇圖像,而不是最初點擊它的位置。所以當我點擊圖像時突然出現「跳躍」。這不光滑。

我注意到startDrag()有兩個默認參數,其中一個是lockCenter,它默認爲false。也許我以某種方式將它設置爲真? (我不知道如何將參數傳遞給addeventlistener中的第二個參數)

另一個問題:如果我想向它添加更多條件,比如創建一個使用component.startDrag()的新函數,我該如何將組件傳遞給此函數,同時向其添加事件監聽器?例如: 例如:我想要做:

component.addEventListener(MouseEvent.MOUSE_DOWN,some_other_function);

where some_other_function uses component.startDrag();

謝謝!

回答

1

你應該有你的事件監聽器直接調用的事件處理程序,而不是起拖 - 這樣你可以傳遞參數:

即:

component.addEventListener(MouseEvent.MOUSE_DOWN, dragStartHandler); 

public function dragStartHandler(event:MouseEvent):void{ 
    component.startDrag(true); 
}