/** * Copyright (c) 2006 Peter Goodman * Licensed under the MIT License: * http://www.opensource.org/licenses/mit-license.php */ //-------------------------------------------- // Some simple wrappers for events. //-------------------------------------------- class FA.build.evt extends FA.Query { //-------------------------------------------- // Bind a function to an event. To use this function, // supply a lower case version of the event name // without the 'on'. E.g.: supply 'data' for 'onData'. //-------------------------------------------- public function bind (event_name:String, event_function:Function) : FA.Query { _object['on' + event_name] = event_function; return this; } //-------------------------------------------- // When the mouse hovers over this movie clip //-------------------------------------------- public function hover (on_hover:Function, on_leave) : FA.Query { if (_object instanceof MovieClip) { _object.onRollOver = function() { if (this.hitTest(_root._xmouse, _root._ymouse, true)) { on_hover.apply(this, []); } else { if(on_leave != undefined) { on_leave.apply(this, []); } } }; if (on_leave != undefined) { _object.onRollOut = on_leave; } } return this; } //-------------------------------------------- // Add an event for when a movie clip is pressed // and an optional event for when it's released. //-------------------------------------------- public function click (on_press:Function, on_release) : FA.Query { if (_object instanceof MovieClip) { _object.onPress = on_press; if (on_release != undefined) { _object.onRelease = on_release; } } return this; } //-------------------------------------------- // Create a loader. This is used in the following // way: $.loader() //-------------------------------------------- public function loader (loader_function:Function, finished_function:Function) : FA.Query { if (_is_dirty) { if (_framesloaded >= _totalframes) { if (finished_function != undefined) { finished_function.apply(null, []); } else { gotoAndPlay(1); } } else { var loaded_bytes:Number = _root.getBytesLoaded(); var total_bytes:Number = _root.getBytesTotal(); loader_function.apply(null, [Math.ceil((loaded_bytes / total_bytes) * 100)]); } } return this; } }