/** * Copyright (c) 2006 Peter Goodman * Licensed under the MIT License: * http://www.opensource.org/licenses/mit-license.php */ //-------------------------------------------- // Class for dealing with effects and such. //-------------------------------------------- class FA.build.fx extends FA.Query { //-------------------------------------------- // Move a movie clip from where it is to some // point on the stage. //-------------------------------------------- public function moveTo (x:Number, y:Number, speed:String) : FA.Query { if (_object instanceof MovieClip) { var num_milliseconds:Number = (speed == "slow") ? 10 : 5; //-------------------------------------------- // make sure the x and y coordinates of the // object are set. //-------------------------------------------- _object._x = _object._x || 0; _object._y = _object._y || 0; //-------------------------------------------- // Figure out how far left/right and up/down // the movie clip will move. //-------------------------------------------- var diff_x:Number = Math.abs(x - _object._x); var diff_y:Number = Math.abs(y - _objext._y); //-------------------------------------------- // Find out the hypotenuse of the move. //-------------------------------------------- var hypotenuse:Number = Math.sqrt( (diff_x ^ 2) + (diff_y ^ 2) ); //-------------------------------------------- // Figure out how far up/down and left/right the // movie clip should go on each loop. //-------------------------------------------- var interval_x:Number = Math.floor(interval_z / hypotenuse) * (coords[0] < _object._x ? -1 : 1); var interval_y:Number = Math.floor(interval_z / hypotenuse) * (coords[1] < _objext._y ? -1 : 1); this.do_move(x, y, interval_x, interval_y, num_milliseconds); } return this; } private function do_move (x, y, interval_x, interval_y, num_milliseconds) : Void { //-------------------------------------------- // Move the movie clip. //-------------------------------------------- if (_object._x < x or _object._y < y) { _object._x = (_object._x < x) ? _object._x + interval_x : x; _object._y = (_object._y < y) ? _object._y + interval_x : y; setTimeout(this, "do_move", num_milliseconds, x, y, interval_x, interval_y, num_milliseconds); } //-------------------------------------------- // The movie clip has been moved. //-------------------------------------------- else { self._x = x; self._y = y; updateAfterEvent(); } } //-------------------------------------------- // Rotate a movie clip. //-------------------------------------------- public function rotateTo (angle:Number, speed:String) : FA.Query { return this; } //-------------------------------------------- // Scale a movie clip. //-------------------------------------------- public function scaleTo (percent:Number, speed:String) : FA.Query { if(_object instanceof MovieClip or _object instanceof TextField) { var num_milliseconds:Number = (speed == "slow") ? 10 : 5; var interval:Number = (percent < 100) ? -1 : 1; var interval_x:Number, interval_y:Number; //-------------------------------------------- // A little hack so that when we divide x by y, // we don't get NaN. //-------------------------------------------- var width:Number = _object._width == 0 ? 1 : _object._width; var height:Number = _object._height == 0 ? 1 : _object._height; //-------------------------------------------- // Figure out proportional intervals to scale // both sides of the movie clip with. //-------------------------------------------- if(_object._width > _object._height) { interval_x = interval; interval_y = Math.ceil( (width / height) * interval ); } else { interval_y = interval; interval_x = Math.ceil( (width / height) * interval ); } //-------------------------------------------- // Make sure we know the original x and y coordinates // so that we can adjust the movie clip as we scale it. //-------------------------------------------- var x_pos:Number = _object._x; var y_pos:Number = _object._y; this.do_scale(interval_x, interval_y, num_milliseconds, percent); } return this; } private function do_scale (interval_x, interval_y, num_milliseconds, percent) { var continue_scale_x:Boolean = (interval_x < 0) ? _object._xscale > percent : _object._xscale < percent; var continue_scale_y:Boolean = (interval_y < 0) ? _object._yscale > percent : _object._yscale < percent; if (continue_scale_x or continue_scale_y) { _object._xscale = continue_scale_x ? _object._xscale + interval_x : percent; _object._yscale = continue_scale_y ? _object._yscale + interval_y : percent; setTimeout(this, "do_scale", num_milliseconds, interval_x, interval_y, num_milliseconds, percent); } else { self._xscale = self._yscale = percent; updateAfterEvent(); } } //-------------------------------------------- // Fade a movie clip from one percentage to // another. //-------------------------------------------- public function fadeTo (to:Number, speed:String) : FA.Query { var num_milliseconds:Number = (speed == "slow") ? 10 : 5; var interval:Number = (from > to) ? -1 : 1; this.do_fade(interval, num_milliseconds, to); return this; } private function do_fade (interval, num_milliseconds, to) : Void { var continue_fade:Boolean = (interval < 0) ? _object._alpha > to : _object._alpha < to; if (continue_fade) { _object._alpha += interval; setTimeout(this, "do_fade", num_milliseconds, interval, num_milliseconds, to); } else { _object._alpha = to; updateAfterEvent(); } } //-------------------------------------------- // Set the transparency of a movie clip / button / text field. //-------------------------------------------- public function setAlpha (num) : FA.Query { if (_object instanceof MovieClip or _object instanceof Button or _object instanceof TextField) { _object._alpha = 100; } return this; } //-------------------------------------------- // Show a movie clip. //-------------------------------------------- public function show () : FA.Query { _object._visible = true; return this.setAlpha(100); } //-------------------------------------------- // Hide a movie clip. //-------------------------------------------- public function hide () : FA.Query { _object._visible = false; return this.setAlpha(0); } }