2013-07-17 55 views
0

我有一個名爲拇指的麥克。我有其他MC命名爲曲目。當我使用下面的腳本移動thumb_mc時,我還需要我的track_mc移動。如何移動MC而其他MC移動在AS3

thumb.addEventListener(MouseEvent.MOUSE_DOWN, thumb_onMouseDown); 
function thumb_onMouseDown(event:MouseEvent):void { 
xOffset = mouseX - thumb.x; 
stage.addEventListener(MouseEvent.MOUSE_MOVE, stage_onMouseMove); 
stage.addEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp); 
} 

function stage_onMouseMove(event:MouseEvent):void { 
thumb.x = mouseX - xOffset; 
//restrict the movement of the thumb: 
if(thumb.x < 8) { 
    thumb.x = 8; 
} 
if(thumb.x > 540) { 
    thumb.x = 540; 
} 

event.updateAfterEvent(); 
} 
function stage_onMouseUp(event:MouseEvent):void { 
stage.removeEventListener(MouseEvent.MOUSE_MOVE, stage_onMouseMove); 
stage.removeEventListener(MouseEvent.MOUSE_UP, stage_onMouseUp); 
} 

回答

0

您可以修改您的MOUSE_MOVE一點:

function stage_onMouseMove(event:MouseEvent):void { 
    thumb.x = mouseX - xOffset; 
    // move your track also 
    track.x = mouseX - someXOffset; 
    track.y = mouseY - someYOffset; 
    ... 
} 

或者,如果你需要移動的軌道,只有當拇指移動,你可以做以下操作:

添加變量來存儲先前的拇指位置var previousPos:int;

在mouse_down中添加此類代碼previousPos = thumb.x;

然後修改這樣的方式移動鼠標:

function stage_onMouseMove(event:MouseEvent):void { 
    thumb.x = mouseX - xOffset; 
    //restrict the movement of the thumb: 
    if(thumb.x < 8) { 
     thumb.x = 8; 
    } 
    if(thumb.x > 540) { 
     thumb.x = 540; 
    } 
    if(previousPos != thumb.x){ 
     //moving track here 
     track.x = somevalue; 
    } 
    previousPos = track.x; 
    ... 
} 
+0

我不這裏有什麼y值爲我的代碼。 。我只需要像滾動條那樣從右向左和從左向右移動事物。而且我需要用鼠標點擊一下鼠標 – Venki

+0

無論如何,我更新了一下我的答案,請檢查它是否可以幫助您 – jfgi

+0

確定讓我檢查它。謝謝。 – Venki

1

簡單,只需添加一行代碼來設置track.x價值的stage_onMouseMove函數內部的thumb.x。

需要注意的重要一點是,這樣它與邊界檢查更新後,這樣收到的值,它在函數的末尾添加:

function stage_onMouseMove(event:MouseEvent):void { 
thumb.x = mouseX - xOffset; 
//restrict the movement of the thumb: 
    if(thumb.x < 8) { 
     thumb.x = 8; 
    } 
    if(thumb.x > 540) { 
     thumb.x = 540; 
    } 

    track.x = thumb.x; // move track with the thumb 
} 
相關問題