2013-07-17 3 views
0

나는 엄지라는 이름의 Mc가 있습니다. 그리고 저는 다른 트랙을 트랙으로지었습니다. 아래 스크립트를 사용하여 thumb_mc를 움직일 때 track_mc가 필요합니다.다른 mc가 as3으로 이동하는 동안 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); 
} 

답변

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

가 간단하고, 단지 stage_onMouseMove 기능 내부 thumb.x에 track.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 
} 
관련 문제