- Flash Action Script: 연속버튼 -

연속버튼

버튼을 누른 후, 놓기전까지 반복하게하는 버튼으로 콜백함수를 이용, 만들 수 있다.

1

_root.B.onPress = function(){
_root.A.onEnterFrame = function(){

_root.A._x = _root.A._x + 1;
}
}

B버튼을 누르고 있는 동안 A라는 무비클립이 계속 오른쪽으로 이동한다.

2

_root.onMouseUp = function(){
_root.A.onEnterFrame = null;
};

B버튼을 놓으면 A 무비클립이 멈춘다.

ex] 마우스를 누르고 있는 동안 연속적으로 액션스크립트가 진행하는 버튼과 키보드로 무비클립 제어하기.

연속버튼

프레임에 입력

_root.front.onPress = function(){
_root.munch.onEnterFrame = function(){

_root.pirate.mouth.play();
_root.pirate.hand.play();
_root.munch.GotoandStop("front");
if(_root.munch._y < 405){
_root.munch._xscale = _root.munch._xscale +2;
_root.munch._yscale = _root.munch._yscale +2;
_root.munch._y = _root.munch._y + 5;
};
};
};

_root.back.onPress = function(){
_root.munch.onEnterFrame = function(){
_root.pirate.mouth.play();
_root.pirate.hand.play();
_root.munch.GotoandStop("back");
if(_root.munch._y > 120){
_root.munch._xscale = _root.munch._xscale -2;
_root.munch._yscale = _root.munch._yscale -2;
_root.munch._y = _root.munch._y - 5;
}
}
}

_root.left.onPress = function(){
_root.munch.onEnterFrame = function(){
_root.pirate.mouth.play();
_root.pirate.hand.play();
_root.munch.GotoandStop("left");
if(_root.munch._x > 30){
_root.munch._x = _root.munch._x - 5;
}
}
}

_root.right.onPress = function(){
_root.munch.onEnterFrame = function(){
_root.pirate.mouth.play();
_root.pirate.hand.play();
_root.munch.GotoandStop("right");
if(_root.munch._x < 350){
_root.munch._x = _root.munch._x + 5;
}
}
}

_root.onMouseUp = function(){
_root.munch.onEnterFrame = null;
};

bonus: 키보드로 제어

중간의 오렌지색 버튼에 입력 (이 버튼은 화면밖에 배치해도 상관없다)

on(keyPress "<Down>"){
_root.pirate.mouth.play();
_root.pirate.hand.play();
_root.munch.GotoandStop("front");
if(_root.munch._y < 405){
_root.munch._xscale = _root.munch._xscale +2;
_root.munch._yscale = _root.munch._yscale +2;
_root.munch._y = _root.munch._y + 5;
}
}

on(keyPress "<Up>"){
_root.pirate.mouth.play();
_root.pirate.hand.play();
_root.munch.GotoandStop("back");
if(_root.munch._y > 120){
_root.munch._xscale = _root.munch._xscale -2;
_root.munch._yscale = _root.munch._yscale -2;
_root.munch._y = _root.munch._y - 5;
}
}

on(keyPress "<Left>"){
_root.pirate.mouth.play();
_root.pirate.hand.play();
_root.munch.GotoandStop("left");
if(_root.munch._x > 30){
_root.munch._x = _root.munch._x - 5;
}
}

on(keyPress "<Right>"){
_root.pirate.mouth.play();
_root.pirate.hand.play();
_root.munch.GotoandStop("right");
if(_root.munch._x < 350){
_root.munch._x = _root.munch._x + 5;
}
}