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 };
'Flash > AS2.0' 카테고리의 다른 글
XMLLoaderNE (0) | 2012.06.05 |
---|---|
Adapter (0) | 2012.06.05 |
한글 워드랩 메쏘드 //2007/03/10 17:49 (0) | 2012.06.05 |
loadBitmap() //2007/03/01 22:52 (0) | 2012.06.05 |
Stage //2007/02/12 18:37 (0) | 2012.06.05 |