/* WWW.PIPPOFLASH.COM - SmoothMover SmoothMover can move smoothly any property of a MovieClip. Properties can be standard properties,such as _alpha, _rotation, _x, _xscale, etc. as well as any other property we have defined. Once imported, the SmoothMover entity will accept infinite properties and values. Initial value is the one already stored in the MovieClip. VERSION 1.8 LAST UNIVERSAL VERSION 1.0 TYPE Static Class HELPERS none USAGE SmoothMover.slide(clip, params); params Object containing all function parameters props A all properties to be affected AS STRINGS!!!!!. i.e. ["_alpha","_x","_y","myProperty"] endPos A all final vlues of properties. i.e. [50,120,120,-30] speed N divider for the smooth moton. The higher is the speed, the slower will be the motion kill B if true, kills the clip after motion listener R Reference to the listener object BROADCASTED EVENTS listener.onSmoothMoverFeedback({object}); object.message S "SMSTART", "SMCOMPLETE" object.clip R Reference to the moovieclip who's motion just started or finished EXAMPLE This example affects the MovieClip "myClip" on the x axis, horizontal scale, and alpha value. On motion start and end, a message is displayed in the trace window. _root.onSmoothMoverFeedback = function(feedbackObj) { if (feedbackObj.message == "SMSTART") trace(feedbackObj.clip + " Motion Started"); else if (feedbackObj.message == "SMCOMPLETE") trace(feedbackObj.clip + " Motion Complete"); } paramsObject = { props:["_x","_xscale","_alpha"], endPos:[100,200,30], speed:12, listener:_root } SmoothMover.slide(myClip, paramsObject); TO BE IMPLEMENTED Quadratic motion related to time based and frame based units. DEBUG More motions in the same clip Properties which do not exist Put properties but not values */ /* COPYRIGHT This code has been written by Filippo Gregoretti (www.pippoflash.com). Free to use in non-profit projects, but ask for my permission please. Not to be used in commercial projects without my written approval, and not for resale. Filippo Gregoretti - pippo@pippoflash.com */ class PippoFlash.SmoothMover { static function slide(clip:MovieClip, p:Object) { // Kills existing motion if there is one clip.SmoothMover_motionClip.removeMovieClip(); // Activates the motion activate(clip, p); } static function removeMotion(clip:MovieClip) :Void { clip.SmoothMover_motionClip.removeMovieClip(); } private static function activate(clip, p) { // Attiva la motionClip var motionClip = createMotionClip(clip); motionClip.p = new Object(); for (var i in p) motionClip.p[i] = p[i]; checkBiggerDifference(clip, motionClip); activateMotion(motionClip); } private static function checkBiggerDifference(clip, motionClip) { // Checks which property to change in time has the bigger difference thus to perform a finer check... // And creates the array of differences var clip = motionClip._parent; var diff = 0; var p = motionClip.p; p.diff = new Array(); for (var i in p.props) { p.diff[i] = p.endPos[i] - clip[p.props[i]]; var newDiff = Math.abs(p.diff[i]); if (newDiff > diff) { diff = newDiff; motionClip.checkProp = i; } } } private static function activateMotion(motionClip) { motionClip.p.listener["onSmoothMoverFeedback"]({message:"SMSTART",clip:motionClip._parent}); motionClip.count = 0; motionClip.onEnterFrame = function() { for (var i in this.p.props) { this._parent[this.p.props[i]] = this.p.endPos[i] - (this.p.diff[i] -= this.p.diff[i] / this.p.speed); } // Check if motion is over if (Math.abs(this.p.diff[this.checkProp]) < 0.1) { if (this.p.kill) this._parent.removeMovieClip(); // Sets al values to final position for (var i in this.p.props) this._parent[this.p.props[i]] = this.p.endPos[i]; motionClip.p.listener["onSmoothMoverFeedback"]({message:"SMCOMPLETE",clip:motionClip._parent}); this.removeMovieClip(); } } } private static function randomName(prefix) { return prefix + getTimer() + "_" + Math.random().toString().substr(2) + "_mc"; } private static function createMotionClip(clip) { var n = randomName("motionClip"); var d = clip.getNextHighestDepth(); var mc = clip.createEmptyMovieClip(n,d); clip.SmoothMover_motionClip = mc; return mc; } }