actionscript 3 - Can any one explain this code how i use this in my application -
i have problem similar this question i'm not able understand answer code, can 1 explain code.
private function attachlisteners():void { this.addeventlistener(mouseevent.mouse_down, selfmousedownhandler, false,0,true); this.addeventlistener(moveevent.move, selfmovehandler, false,0,true); } private function selfmovehandler(event:moveevent):void { redrawconnectedlinks(); } private function selfmousedownhandler(event:mouseevent):void { stage.addeventlistener(mouseevent.mouse_up, stagemouseuphandler, false,0,true); stage.addeventlistener(mouseevent.mouse_move, stagemousemovehandler, false,0,true); } private function stagemouseuphandler(event:mouseevent):void { stage.removeeventlistener(mouseevent.mouse_up, stagemouseuphandler, false); stage.removeeventlistener(mouseevent.mouse_move, stagemousemovehandler, false); } private function stagemousemovehandler(event:mouseevent):void { dispatchevent(new moveevent(moveevent.move)); }
please suggest me how use in flex application.
this code tracking mouse movement flash's mouseevent.mouse_up, mouseevent.mouse_move , mouseevent.mouse_down. along events, code using custom event: moveevent.move.
any time, moveevent.move being dispatched, app redraw connectors. so, listener moveevent.move being added once , @ beginning.
also, track drag, code waits mouse_down , keep on dispatching moveevent.move each mouseevent.mouse_move until mouse_up event occurs.
now, let me associate above explanation lines of code:
private function attachlisteners():void { /*wait mouse down event initiate mouse move , mouse tracking*/ this.addeventlistener(mouseevent.mouse_down, selfmousedownhandler, false,0,true); /*always track moveevent.move , start redrawing connectors whenever it's dispatched*/ this.addeventlistener(moveevent.move, selfmovehandler, false,0,true); } private function selfmovehandler(event:moveevent):void { /*redraw connectors when custom event moveevent.move received*/ redrawconnectedlinks(); } private function selfmousedownhandler(event:mouseevent):void { /*wait mouse event on receiving mouse down*/ stage.addeventlistener(mouseevent.mouse_up, stagemouseuphandler, false,0,true); /*track mouse movement once mouse down*/ stage.addeventlistener(mouseevent.mouse_move, stagemousemovehandler, false,0,true); } private function stagemouseuphandler(event:mouseevent):void { /*once mouse happens stop tracking mouse up... */ stage.removeeventlistener(mouseevent.mouse_up, stagemouseuphandler, false); /*don't track mouse movement once mouse button gets released*/ stage.removeeventlistener(mouseevent.mouse_move, stagemousemovehandler, false); } private function stagemousemovehandler(event:mouseevent):void { /*dispatch moveevent.move when mouse moved. if read above setup again, should dispatched on mouse moves happening after mouse down , before mouse */ dispatchevent(new moveevent(moveevent.move)); }
hth.
explanation of custom events asked in comment op
custom events useful add custom message passing semantics. e.g. in case, mouse drag detected series of mouse events, , once events happen custom event dispatched notify connectors should redrawn. similarly, might have refresh button , clicking on might dispatch same event force redraw.
Comments
Post a Comment