import mx.transitions.BroadcasterMX;
import com.showjean.utils.Adapter;
class SimpleButtonHandler {
//
public var addListener:Function;
public var removeListener:Function;
public var broadcastMessage:Function;
///*
public var onPress:Function;
public var onRelease:Function;
public var onReleaseOutside:Function;
public var onRollOver:Function;
public var onRollOut:Function;
public var onDragOut:Function;
public var onDragOver:Function;
//*/
//
public function SimpleButtonHandler(mc:MovieClip) {
mc.gotoAndStop(1);
BroadcasterMX.initialize(this);
this.addListener(this);
initialize(mc);
}
private function initialize(_mc:MovieClip):Void {
_mc.onPress = Adapter.wrap(this, sendEvent, "onPress", _mc);
_mc.onRelease = Adapter.wrap(this, sendEvent, "onRelease", _mc);
_mc.onReleaseOutside = Adapter.wrap(this, sendEvent, "onReleaseOutside", _mc);
_mc.onRollOver = Adapter.wrap(this, sendEvent, "onRollOver", _mc);
_mc.onRollOut = Adapter.wrap(this, sendEvent, "onRollOut", _mc);
_mc.onDragOut = Adapter.wrap(this, sendEvent, "onDragOut", _mc);
_mc.onDragOver = Adapter.wrap(this, sendEvent, "onDragOver", _mc);
}
private function sendEvent(evt:String, _mc:MovieClip):Void {
switch (evt) {
case "onRollOver" :
_mc.gotoAndStop(2);
break;
case "onRollOut" :
_mc.gotoAndStop(1);
break;
}
this.broadcastMessage(evt, _mc);
}
}
- 모든 버튼에 동일한 액션을 주고 싶을 때 이용할 수 있는 심플버튼핸들러
- 위 예제처럼 롤오버와, 롤아웃시에 액션을 모든 버튼에 추가할 수 있다.
- 사용법
var sbh:SimpleButtonHandler = new SimpleButtonHandler(test_btn);
sbh.onRollOver = function(){ //actions };
sbh.onRollOut = function(){ //actions };
sbh.onPress = function(){ //actions };