actionscript-video-com-mosesSupposes-fuse-ZigoEngine.ax [swf] flex
* The Fuse Kit [beta1.1z3] * Copyright (c) 2006 Moses Gunesch, MosesSupposes.com * * Distributed under MIT Open Source License, see Fuse-Kit-License.html (in fuse package directory) * Easing Equations (c) 2003 Robert Penner used by permission, see PennerEasing * Visit http://www.mosessupposes.com/Fuse * * @ignore * * A robust central processing engine for all scripted tweens in a swf published to AS2.<br> * <br> * @usage * Your project can be prepared to use @ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine in these ways: * <ul><li>Simply import this class and begin using static methods like {gray #doTween}.<br> * - You may then optionally extend the engine's capabilities using {gray #register}.<br></li> * <li>Or, use {gray #simpleSetup} to add tweening shortcuts like <code>alphaTo</code> to MovieClips, Buttons and TextFields.</li></ul> * <br> * Extending prototypes is entirely optional in this version - all Shortcut functionality is excluded from the core engine class.<br><br> * Events dispatched by @ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine (see {gray #addListener} for more info): * <ul><li><code>onTweenInterrupt</code></li></ul> * Events dispatched by individual target objects (see {gray com.mosesSupposes.fuse.ZManager} for more info): * <ul><li><code>onTweenStart</code></li> * <li><code>onTweenUpdate</code></li> * <li><code>onTweenEnd</code></li></ul> * * @author Moses Gunesch / MosesSupposes.com / @ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine based on concepts by Ladislav Zigo, Zeh Fernando * @version 2.0
* Enables kit version to be retrieved at runtime or when reviewing a decompiled swf.
* Default easing if unspecified. * @description This default is hardcoded in the engine and doesn't require that {gray com.mosesSupposes.fuse.PennerEasing} is registered. * However you will need to register that class with the engine if you wish to set this property to a similar string like "easeOutQuad". * You may also set this property to any standard easing function (like <code>mx.transitions.easing</code>).
* Default tween duration if unspecified.
* If set true the engine always rounds its math (helpful with pixelfonts). * @description Degradation in animation and performance is minor with this feature enabled. Hence it was left a global toggle with the assumption that it should only be set true for projects requiring rounding.
* Controls how much feedback the engine outputs, helpful for debugging. * @usage * <ul> * <li>0 = no traces,</li> * <li>1 = normal errors & warnings</li> * <li>2 = additional Fuse output</li> * <li>3 = additional FuseItem output</li> * </ul>
* (Legacy) Option to stop all tweening props in target as a new tween is added.
* (Advanced) Sets default engine behavior for situations where tweens fail to affect a visible change or have no duration. * @usage <b>1. No-duration tweens:</b><br> * Tweens with a 0-second duration set the property immediately at the time of the tween call, or after any delay.<br> * This behavior has advantages and disadvantages. It is <i>recommended</i> that you purposefully use 0-second tweens * to set properties that are handled by the engine at any time in your program, since this will * effectively stop any potentially running tweens on that property. (Trying to set a property while it is being tweened * usually has no effect.) However in some dynamic programs you may want tweens that end up having no duration to also * skip their delay and/or callbacks and events - this can be controlled with SKIP_LEVEL.<br><br> * <b>2. No-change tweens:</b><br> * Tweens at times end up being generated that affect no visual change. Normally the @ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine operates under its * legacy behavior, which is to run such tweens regardless. This can be good (the program's sequence will continue * on a schedule) or bad (the tween is essentially invisible and will fire callbacks and events on update and end, * which may cause confusion). In some cases you may want to skip past tweens that don't do anything visually.<br> * <br> * The <code>SKIP_LEVEL</code> default, as well as the per-tween <code>skipLevel</code> parameter (see {gray #doTween}) * enable you to control the engine's behavior in these situations more accurately: * <ul><li>0= Default.<br>No-change tweens are run with their full duration, delay, and callbacks/events. * No-duration tweens set the property and execute all callbacks and events immediately or after a delay.</li> * <li>1= Skip no-change tweens.<br>Tweens that affect no change are discarded (both delay and duration are ignored). Callbacks/events are fired immediately. No-duration tweens ignore delay and set properties immediately.</li> * <li>2= Do not fire events or callbacks for no-change or no-duration tweens.<br>No-change tween calls are entirely ignored. No-duration tweens ignore delay and set properties immediately.</li></ul> * <br>To review what property tweens were successfully added, {gray #doTween} returns a formatted list.
* A movieclip is created in the _root timeline to run the engine on an EnterFrame pulse. * @description Use {gray #setControllerDepth} to set the clip's level. By default it is set on depth 6789. A depth of 0 will be more convenient if you'll be using depth management in _root.
* Zmanager instance * @description Broken out to increase speed in as2
* Internal setInterval id memory for ability to clearInterval
* Internal setting for running the engine on a setInterval pulse. * @see setUpdateInterval
* Internal boolean playing switch
* Internal counter for hidden __zigoID__ parameter written into target objects
* Internal table for externally registered classes which are stored via their registryKey string.
* Internal counter used to tag each callback function with a unique id
* Do not use constructor. All methods of engine are static.
* Written by AsBroadcaster * @ignore * (Advanced) Use this method to add a listener for "onTweenInterrupt" event, which is broadcast directly by the engine. * @usage The "onTweenInterrupt" event is fired in the following situations: * <ul><li>A target goes missing, for instance if a MovieClip was removed during a tween.</li><li>Another tween call overwrote one or more property tweens in progress</li><li>A <code>removeTween</code> call stopped one or more tweens in progress.</li><li>A target is deinitialized from the engine during tweens</li></ul> * This event is special in that it is dispatched directly by the @ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine class, unlike target-events such as <code>onTweenEnd</code> (see: {gray com.mosesSupposes.fuse.ZManager} for more info). * This ensures the event is fired even when targets go missing and are thus unable to dispatch the event. * To aid in tracking targets in that situation, the internal <code>__zigoID__</code> property for each target is also passed in the event object. Any initialized/tweening target contains this read-only property, making it possible to advance-query then later identify targets after they're removed. * <pre>var myListener:Object = { * onTweenInterrupt:function(o:Object):Void { * trace("Interruption detected:"); * trace(" -target (may not exist if removed):"+o.target); * trace(" -target id:"+o.__zigoID__); * trace(" -properties interrupted:"+(o.props).toString()); * } * }; * @ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.addListener(myListener); * @ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.doTween(my_mc,"_alpha",0,2); * // click the mouse during the tween to receive the event. * function onMouseDown():Void { * my_mc.removeMovieClip(); * } * </pre> *
parameter: the function or object that should be called */ public static function addListener(handler:Object):Void { AsBroadcaster.initialize(@ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine); @ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.addListener(handler); } /** * Written by AsBroadcaster * @ignore * Remove a listener for onTweenInterrupt event * @param the function or object that should be called */ public static function removeListener(handler:Object):Void {} /** * Returns true if the engine contains tweens and is running updates on a pulse */ public static function isPlaying():Boolean { return _playing; } /** * An alternative setup command that extends prototypes with shortcuts likealphaTo
. * @description This setup command should only be called once at the beginning of your program. * Use either this or {gray #register}, not both. * The difference is thatsimpleSetup
alters base prototypes so that you may call tween methods * directly on targets, such asmy_mc.alphaTo(0);
.
Example: *import com.mosesSupposes.fuse.*; * @ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.simpleSetup(Shortcuts,PennerEasing);* Note that to keep filesize to a minimum you should only register the features you intend to use. Use publish settings to "omit trace actions" to further reduce filesize. * @param shortcutsClass It is madadory to pass the {gray #Shortcuts} class during this call! You may additionally pass any of the following classes (all are optional), as in the way PennerEasing is added above. ** PennerEasing
Enables shortcut strings like "easeOutQuad" to be used with the engine. See {gray com.mosesSupposes.fuse.PennerEasing}* Fuse
Enables Fuse for animation sequencing. Note that if animation won't be sequenced you do may simply import and use Fuse without @ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine. See {gray com.mosesSupposes.fuse.Fuse}* FuseFMP
Enables shortcut strings likeDropShadow_distance
to be tweened in the engine. See {gray com.mosesSupposes.fuse.FuseFMP}*/ public static function simpleSetup(shortcutsClass:Function):Void { if (arguments.length>0) register.apply(@ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine,arguments); _global.@ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine = @ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine; // This allows you to skip using import statements in the timeline. if (extensions.fuse!=undefined) _global.Fuse = extensions.fuse; if (extensions.fuseFMP!=undefined) extensions.fuseFMP.simpleSetup(); // adds _global.FuseFMP reference initialize(MovieClip.prototype, Button.prototype, TextField.prototype); if (extensions.shortcuts==undefined) { // ignores OUTPUT_LEVEL since it's crucial FuseKitCommon.error('001'); } } /** * An optional setup command that registers additional classes for use with the @ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine. * @description This setup command should only be called once at the beginning of your program. * Use either this or {gray #simpleSetup}, not both. * The difference is that FuseItem
Enables Fuse-style Object Syntax to be used with the@ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.doTween
. Note that Fuse does not need to be registered to use this feature. See {gray com.mosesSupposes.fuse.FuseItem}register
links additional classes to the engine without altering base prototypes. *import com.mosesSupposes.fuse.*; * @ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.register(PennerEasing, Fuse, FuseFMP);* Note that to keep filesize to a minimum you should only register the features you intend to use. Use publish settings to "omit trace actions" to further reduce filesize. * @param classReference Pass any of the following classes (all are optional): **/ public static function register(classReference:Function):Void { if (extensions==undefined) extensions = {}; var supported:String = '|fuse|fuseItem|fuseFMP|shortcuts|pennerEasing|'; for (var i:String in arguments) { var key:String = (arguments[i]).registryKey; if (extensions[key]==undefined && supported.indexOf('|'+key+'|')>-1) { extensions[key] = (arguments[i]); //retain class if (key=='fuseFMP' || key=='shortcuts') Object(extensions[key]).initialize(); // not entirely necessary. } } } /** * (Advanced) Prepares targets for use with engine. * @description This method is never needed when extending prototypes with
- *
Shortcuts
Enables {gray #doShortcut}, "easyfunc" callback parsing, and the option to copy / remove shortcuts on any target or prototype manually using {gray #initialize}. See {gray com.mosesSupposes.fuse.Shortcuts}- *
PennerEasing
Enables shortcut strings like "easeOutQuad" to be used with the engine. See {gray com.mosesSupposes.fuse.PennerEasing}- *
Fuse
Enables Fuse for animation sequencing. Note that if animation won't be sequenced you do may simply import and use Fuse without @ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine. See {gray com.mosesSupposes.fuse.Fuse}- *
FuseFMP
Enables shortcut strings likeDropShadow_distance
to be tweened in the engine. See {gray com.mosesSupposes.fuse.FuseFMP}FuseItem
Enables Fuse-style Object Syntax to be used with the@ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.doTween
. Note that Fuse does not need to be registered to use this feature. See {gray com.mosesSupposes.fuse.FuseItem}simpleSetup
. * It can be used to initialize specific targets to accept listeners prior to tweening - see {gray com.mosesSupposes.fuse.ZManager} for an example. * If the Shortcuts class was passed to {gray #register}, this method also copies all tweening shortcuts to targets. * * @param One or more targets to initialize. */ public static function initialize(target:Object):Void { if (arguments.length>0) { initializeTargets.apply(@ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine, arguments); if (extensions.shortcuts!=undefined) { extensions.shortcuts.addShortcutsTo.apply(extensions.shortcuts, arguments); } } } /** * (Advanced) Clears targets from being used with the engine. * @description Removes AsBroadcaster functionality (and tweening shortcuts if the Shortcuts class was registered) * from any object previously initialized usinginitialize
.
* @param One or more targets to initialize, or nothing/null to deinitialize base prototypes (for example to undo simpleSetup) * @see initialize */ public static function deinitialize(target:Object):Void { if (arguments.length==0 || target==null) { arguments.push(MovieClip.prototype, Button.prototype, TextField.prototype); } deinitializeTargets.apply(@ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine, arguments); if (extensions.shortcuts!=undefined) { extensions.shortcuts.removeShortcutsFrom.apply(extensions.shortcuts, arguments); } } /** * @return Number set usingsetUpdateInterval
, orundefined
if unset. * @see #setUpdateInterval */ public static function getUpdateInterval():Number { return updateTime; } /** * When set, the engine will run on a setInterval pulse instead of a frame pulse. * @param time Pulse duration in milliseconds, or null/undefined to return to an frame-based pulse. * @description In most cases it is best to leave the engine in its default state since a frame-based pulse usually renders more smoothly. * The engine always uses seconds for tween duration so using a longer interval will only reduce animation quality, not slow tweens down. * This may be desirable in some cases, for instance to reduce CPU usage in banners. */ public static function setUpdateInterval(time:Number):Void { if (_playing) { setup(true); updateTime = time; setup(); }else{ updateTime = time; } } /** * Depth of the @filePulse clip. * @return numeric depth in _root */ public static function getControllerDepth():Number { return tweenHolder.getDepth(); } /** * Creates a clip in the _root timeline called "@filePulse" or sets its depth * @param If null or nothing passed the beacon clip is placed at depth 6789, but a depth of 0 will be more convenient if you'll be using depth management in _root. */ public static function setControllerDepth(depth:Number):Void { if (depth==null || _global.isNaN(depth)==true) { depth = 6789; } if(Object(tweenHolder).proof!=null) { tweenHolder.swapDepths(depth); } else { tweenHolder = _root.createEmptyMovieClip("@filePulse", depth); } } /** * An alternative to {gray #doTween} that accepts Shortcut syntax. Requires registration of the Shortcuts class. * @description This idea thanks to Yotam Laufer. Example: *@ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.doShortcut(my_mc, 'scaleTo', 200, 1, 'easeOutQuad');* See {gray com.mosesSupposes.fuse.@ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine} introduction for instructions on registering Shortcuts to enable this feature. * @param targets Tween target object or array of target objects * @param methodName The shorcut as a string, such as "alphaTo", followed by parameters that follow that shortcut's format. * @return A comma-delimited string of props successfully added. When multipe targets were passed, a pipe-delimited series is returned to enable verification of individual properties per target. */ public static function doShortcut(targets:Object, methodName:String):String { if (extensions.shortcuts==undefined) { if (OUTPUT_LEVEL>0) FuseKitCommon.error('002'); return null; } return (extensions.shortcuts.doShortcut.apply(extensions.shortcuts, arguments)); } /** * Generates and immediately begins one or more property-tweens running on one or more targets. * @description@ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.doTween(my_mc, '_x,_y', [100,150], 1, Strong.easeInOut);* {gray com.mosesSupposes.fuse.Fuse}-style Object Syntax may also be used if the {gray com.mosesSupposes.fuse.FuseItem} class is registered: *@ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.doTween({ target:my_mc, start_alpha:0, y:150, ease:Strong.easeInOut });* @param targets Tween target object or array of target objects * @param props String like"_x"
, comma-delimited list of properties like"_x,_y"
, or Array of properties like["_x","_y"]
. *
The engine accepts any existing property in the target including custom variables, and the following special properties: **
* When {gray com.mosesSupposes.fuse.FuseFMP} is registered, a large number of BitmapFilter properties are tweenable: *- *
_scale
Sets _xscale and _yscale to the same value.- *
_size
Sets _width and _height to the same value.- *
_frame
Tweens a MovieClip's timeline to a frame using easing specified.- *
_tint
Accepts 0x000000 and "#000000" formats, null (full reset), or object{tint:Number/null/hexString, percent:Number/String}
.- *
_tintPercent
Value range 0-100- *
_brightness
Value range 0-100- *
_brightOffset
Burn effect. -100=black, 0=normal, 100=white- *
_invertColor
Value range 0-100- *
_colorReset
Value range is current tint - 100. Acts like the opposite of tintPercent where 100 is a full reset.- *
_contrast
0=gray, 100=normal, 200=high-contrast, higher=posterized- *
_colorTransform
Generic object in Flash7 transform format{ra:,rb:,etc.}
- *
_bezier_
Generic object with some or all of the properties{x:,y:,controlX:,controlY:}
. Relative (string) values are okay. * Note that only one control param is necessary to generate a curved motion path, simply omit other values.
* Example - swoop up then down while sliding right:
*@ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.doTween(clip1, "_bezier_", {x:"100",controlY:"-25"});
* @param endvals tween end-value or Array of corresponding end-values *
Blur_blurX, etc.
Format follows the convention short-filtername+"_"+filter property.
Relative values: Passing a string instead of a number like"-10"
vs.will treat the endvalue as relative to the start position of the tween. * @param seconds tween duration. If nothing is passed, defaults to @ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.DURATION
. * @param ease function, shortcut-string, or custom-easing-panel object. If nothing is passed, defaults to@ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.EASING
. * @param delay seconds to wait before performing the tween. Start callback andonTweenStart
event are fired at end of delay. * @param callback function, string, or object *
1. Function **
- myfunc
*- function(){ ... }
*- Delegate.create(....) - adds scope
*@ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.doTween(clip1,"_x","100",1,"easeOutQuad",0, myCallback);
* 2. String (also known as easyfunc in Fuse) - Note that you need to register Shortcuts to use this feature. **
- "myscope.callback();"
*- "myscope.myscope.myfunc(someexpression,'somestring',{someparam:someval});" - Scope can be complex, * plus various param formats including object and array are parsed.
*@ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.doTween(clip1,"_x","100",1,"easeOutQuad",0, "myCallback();");
* 3. Callback Object - a generic object with the parseable params: **
*- *
func
Function or string name of function- *
scope
The this Object where the callback should execute- *
args
One argument or an array of arguments to pass to the callback- *
startfunc
- *
startscope
- *
startargs
- *
updfunc
- *
updscope
- *
updargs
@ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.doTween(clip1,"_x","100",1,"easeOutQuad",0, {scope:this, func:"myCallback"});
*
* Additional engine parameters - Include any of these in a callback object: **
- *
cycles
Tweens back and forth between start and end.
* 0 or "LOOP" = infinite cycles, default = 1, 2 or more to specify cycles.- *
skipLevel
0,1, or 2. See {gray #SKIP_LEVEL} for details.
* Including this paramter in a callback object overrides the engine default on a per-tween basis.- *
extra1
Elastic easing amplitude or Back easing overshoot- *
extra2
Elastic easing period- * @return A formatted string:
easyfunc
String like "myClip.doSomething(true);" as in option 1 above.
* The engine reports which properties have been added to its active tween list by returning a comma-delimited string of just the properties that were successfully added, such as"_x"
or"_x,_y"
. * These may occasionally differ from what was tweened, such as"_width,_height"
when"_size"
was tweened.
* If multiple targets are passed to the engine, a pipe-delimited series of properties is returned in target order, which enables granular review of whether specific properties for each target.
*var results:String = @ax-actionscript-video-com-mosesSupposes-fuse-ZigoEngine.doTween([clip1,clip2,clip3],"_scale",100,null,0,{skipLevel:1}); * // results: "_xscale,_yscale||_xscale,_yscale" * // because clip2's scale was already set to 100 and the skipLevel is set to skip no-change tweens.*/ public static function doTween(targets:Object, props:Object, endvals:Object, seconds:Number, ease:Object, delay:Number, callback:Object):String { if (extensions.fuse.addBuildItem(arguments)==true) return null; // used by Fuse Simple Syntax // initialize + setup (ZManager singleton required prior to parse) if (instance==undefined || (Object(tweenHolder).proof==undefined && updateTime==undefined)) { if (MovieClip.prototype.tween!=null && typeof _global.