0

私は親指という名前のMcを持っています。そして、私はトラックと名付けられた他のMCを持っています. 以下のスクリプトを使用して thumb_mc を移動すると、track_mc も移動する必要があります。

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);
}
4

2 に答える 2

1

簡単です。コードを 1 行追加して、stage_onMouseMove 関数内で track.x の値を thumb.x に設定するだけです。

注意すべき重要な点の 1 つは、次のように、境界チェックで更新された後に値を受け取るように、関数の最後に追加することです。

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
}
于 2013-07-17T13:45:14.000 に答える
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;
    ...
}
于 2013-07-17T11:33:19.683 に答える