📄 mc_tween2.as
字号:
/*
===============================================================================
= MOVIECLIP/TEXTFIELD/SOUND TWEENING PROTOTYPE(s)
=------------------------------------------------------------------------------
=
= MC_TWEEN
= Created to be a helpful tweening extension for mortal users
= Find documentation and examples at the site:
= http://hosted.zeh.com.br/mctween/
=
= By Zeh Fernando
= z [AT] zeh.com.br
= 2003-2005
= Sao Paulo, Brazil
= http://www.zeh.com.br
=
=------------------------------------------------------------------------------
=
= This tweens given movieclip properties from their current values to new values,
= during an specified time. It's inspired by Jonas Galvez's simpleTween method
= and created to be *easy* to non-experienced coders (designers).
=
= ALL easing/tweening equations used here (and a bunch of other auxiliary
= calculations) were based on Robert Penner's work. I merely coded Flash MX-
= friendly prototypes. You can find more information and his original source
= code here:
= http://www.robertpenner.com/easing/
=
=------------------------------------------------------------------------------
= Version: 2.27.29
= Latest changes:
= (2003) apr 05 (1.0.0) - first version
= apr 06 (1.1.0) - added callback property to mc.tween()
= (1.1.1) - code fixing/cleaning
= (1.2.1) - added mc.isTweening(), mc.getTweens()
= apr 07 (1.3.1) - added initial delay property to mc.tween()
= apr 08 (1.3.2) - using onEnterFrame instead of setInterval
= apr 11 (1.3.3) - added some comments, deleted some old code
= (1.4.3) - added some shortcut methods (easier to use)
= apr 29 (1.5.3) - updated with robert penner's equations v1.4
= may 02 (1.6.3) - updated with robert penner's equations v1.5
= (1.7.3) - added mc.colorTo(), a shortcut/helper method
= may 06 (1.7.4) - fixed a callback bug on the slideTo method -
= props to Gregg Wygonik for pointing that out
= may 11 (1.8.4) - added mc.stopTween() to stop tweenings
= may 12 (1.8.5) - fixed a really stupid colorTo() error
= may 12 (1.9.5) - added mc.colorTransformTo(), a shortcut/helper
= method which enables color.setTransform tweens
= may 13 (1.9.6) - ditched mc.colorTo()'s original code. now it's
= based on a mc.colorTransformTo() call
= jul 23 (1.10.6) - added another shortcut, scaleTo()
= jul 25 (1.11.6) - added another shortcut, rotateTo() (duh)
= jul 27 (1.11.7) - made colorTransformTo() better handle
= undefined properties and not create unneeded
= tween movieclips (faster)
= aug 26 (1.12.7) - completely revamped the frame control, to use
= one submovieClip for each movieclip instead
= of a submovieClip for each property (cleaner)
= oct 01 (1.12.8) - minor fix (mispell) on stopTween() (thanks kim)
= dec 02 (1.12.9) - fixed minor alphaTo+colorTo+colorTransformTo
= issue that broke simultaneous calls
= (2004) jan 23 (2.12.9) - completely revamped the frame control system
= (again): it now uses one single mc at _root
= (faster, cleaner)
= - callback functionality scope changed. NOT
= BACKWARDS COMPATIBLE BY DEFAULT! search for
= "backwardCallbackTweening" for help on how
= to make it compatible
= feb 10 (2.13.9) - better time control for synch start
= feb 10 (2.14.9) - made it possible to tween the same property
= several times (not direct overwritting) - ie,
= complex animations are now possible with
= sequence tweenings
= feb 11 (2.14.10) - optimizations for speed
= feb 17 (2.15.10) - added lockTween() and unlockTween()
= feb 18 (2.15.11) - stoptween() fixed, not updating $_tweenCount
= mar 01 (2.16.11) - added textfield methods: tween(), alphaTo(),
= colorTo(), rotateTo(), slideTo(), scaleTo(),
= as well as stopTween(), lockTween(),
= unlockTween(), getTweens(), isTweening(),
= AND a new one, scrollTo()
= may 23 (2.16.12) - added *real* synchronization for tweenings
= issued on the same frame (thanks to laco)
= jun 22 (2.16.13) - rewrote colorTransformTo() in a more cleaner,
= intelligent and faster way - and fixed the
= inability to issue multiple colorTransformTo()
= calls (thanks to Martin Klasson for finding
= this error)
= (2.16.14) - rewrote part of the property set algorithm,
= making it clearer and more logic, as well as
= the textfield.colorTo() method (fixed a
= potential bug for sequential calls)
= jul 17 (2.16.15) - fixed elastic equations problems that'd
= appear on flash mx 2004 when exporting a
= version 7 swf - updated to Robert Penner's own
= solution, in fact (thanks BrianWaters for
= pointing that out)
= aug 17 (2.17.15) - added sound methods: tween(), stopTween(),
= getTweens(), isTweening(), lockTween(),
= unlockTween() AND two new ones, volumeTo() and
= panTo(), for volume and panning tweens that
= can be applied to sound objects
= oct 20 (2.18.15) - added bezierSlideTo(), which does a slideTo()
= using a bezier control point to do a curve
= path - similar to curveTo()'s parameters.
= based on Robert Penner's pointOnCurve method:
= http://actionscript-toolbox.com/samplemx_pathguide.php
= nov 28 (2.18.16) - cleaned comments and removed syntax help since
= nobody reads it anyways, moved to the new site
= (2.18.17) - added _global.$stopTween() -- handler method
= for *all* tweening stops (from stopTween() and
= for internal tween ends). this makes the code
= a bit more cleaner and fix some old variable
= leaks on stopTween()
= (2.18.18) - removed some legacy, non-needed code
= (2.18.19) - fixed ASSetPropFlags for findPointOnCurve()
= dec 14 (2.18.20) - avoids tweening deleted objects, and removes
= the tween data altogether
= dec 29 (2.19.20) - added xScaleTo(), yScaleTo(), xSlideTo() and
= ySlideTo - simple shortcuts, for readability's
= sake
= (2.19.21) - added the ability do to a colorTo(null) - that
= will restore a MovieClip's original color,
= with no tinting at all. This has no effect on
= TextFields.
= (2.19.22) - made it possible to use a colorTransformObject
= as the parameter on the colorTransformTo()
= method, so it detects if you are using a lot
= of numbers as the parameter or just an object.
= (thanks to rdoyle720 for the suggestion)
= dec 31 (2.19.23) - fixed: callbacks were not executed sometimes
= because of the new tween end control (small
= typing error) :/
= (2005) jan 3 (2.19.24) - fixed: other error when calling stopTween()
= with no parameters
= jan 12 (2.20.24) - added frameTo() -- a kind of a gotoAndPlay()
= with equations, suggested by Martin Claesson
= some time ago (sorry it took so long)
= (2.21.24) - added *outin equations too (so now you have
= easeoutexpo, easeinexpo, easeinoutexpo, and
= the new easeoutinexpo, for example)
= feb 08 (2.21.25) - added error warning when trying to use an
= animation type that doesn't exist
= feb 16 (2.22.25) - added pauseTween() and resumeTween()! both
= accept a property name (string) or a list of
= property names (several strings, or an array
= of strings) as parameter
= (2.22.26) - made stopTween() also allow several string
= arguments instead of requiring an array
= feb 17 (2.23.26) - added new events: onTweenUpdate (called after
= each property change) and onTweenComplete
= (called when an specific tween is completed)
= mar 07 (2.24.26) - re-reorganization of the internal code: moved
= all core code out of the tweening methods
= themselves: added internal $addTween(),
= $updateTweens(), $createTweenController() and
= $removeTweenController()
= (2.24.27) - minor fix for speed on $stopTween()
= (2.25.27) - fixed the inability to do sequential
= bezierSlideTo() calls - a whole bunch of code
= was missing to allow data to be carried
= through different tweens correctly
= (2.26.27) - added option to use rounded values when
= updating; this is for internal use only, but
= it means that new sliding methods that snap to
= rounded pixels have been added: roundedTween(),
= roundedSlideTo(), roundedXSlideTo(),
= roundedYSlideTo(), and roundedBezierSlideTo()
= sep 21 (2.26.28) - undefined or 0 in time apply value immediately
= (2.27.28) - Flash 8 compatible filters (AS1 and AS2) for
= MovieClips and TextFields: blurTo(), xBlurTo(),
= yBlurTo(), xyBlurTo(), glowTo(), xGlowTo(),
= yGlowTo(), xyGlowTo(), bevelTo(), xyBevelTo()
= dec 16 (2.27.29) - fixed an issue with stopTween() and multiple
= parameters when using AS2 (thanks Henrique for
= noticing that)
===============================================================================
*/
/*
===============================================================================
Real hidden methods/functions
-------------------------------------------------------------------------------
These functions are the real core of MC Tween. They control all tweenings, and
are kept separated from the methods themselves for organization's sake.
-------------------------------------------------------------------------------
*/
_global.$createTweenController = function() {
// INTERNAL USE: Creates the tween controller that will do all tween updates remotely
var tweenHolder = _root.createEmptyMovieClip ("__tweenController__", 123432); // Any level
tweenHolder.$_tweenPropList = new Array(); // Will hold the list of properties beeing tweened. an array of objects.
tweenHolder.$_tTime = getTimer();
tweenHolder.onEnterFrame = _global.$updateTweens;
};
ASSetPropFlags(_global, "$createTweenController", 1, 0);
_global.$removeTweenController = function() {
// INTERNAL USE: Destroys the tween controller in a centralized, clean, functional and paranoid way
delete _root.__tweenController__.$_tweenPropList;
delete _root.__tweenController__.$_tTime;
delete _root.__tweenController__.onEnterFrame;
_root.__tweenController__.removeMovieClip();
};
ASSetPropFlags(_global, "$removeTweenController", 1, 0);
_global.$addTween = function(mtarget, prop, propDest, timeSeconds, animType, delay, callback, extra1, extra2, extras) {
// INTERNAL USE: Adds a new tween for an object
// Sets default values if undefined/invalid
if (timeSeconds == undefined) timeSeconds = 0; // default time length
if (animType == undefined || animType == "") animType = "easeOutExpo"; // default equation!
if (delay == undefined) delay = 0; // default delay
// Starts tweening.. prepares to create handling mcs
// Faster this way
if (typeof(prop) == "string") {
// Single property
var properties = [prop]; // Properties, as in "_x"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -