Jump to content


  • Posts

  • Joined

  • Last visited


0 Newbie
  1. Maybe this will save somebody some time - and help to keep their code more manageable. In an ever vigilant effort to avoid embedded magic numbers in my code, and, in consideration of the fact that STRINGS are often just another form of magic number, I created a function to return a reference that could be used with calls to the Greensock Tweens. As my ActionScript is always data-driven from an XML file, I embed the easename and easekind in the XML - then use that to create the function reference pass into the Greensock Tween. The advantage here is that I can change behavior without the need to recompile my SWF app. Of course, there's much more contained in the real XML file - the contents shown here are limited for clarity. When I need to create an easement reference to a Tween - it might look something like shown below. // XML textfile contents: <?xml version="1.0" encoding="UTF-8"?> Regular easeInOut Elastic easeOut // CONTAINED IN MY ACTIONSCRIPT SOURCE FILES ... var tween_func:Function = null; var easename:String = ""; var easekind:String = ""; ... try { easename = thexml.items.item[index].easedef.easename; } catch(easenameerr:Error) { ; } try { easekind = thexml.items.item[index].easedef.easekind; } catch(easekinderr:Error) { ; } ... if((null != easename) && (0 < easename.length) && (null != easekind) && (0 < easekind.length)) tween_func = fetchEasingFunction(easename, easekind); ... // ---------------------------------------------------------------- // in a function someplace .... TweenMax.fromTo(dispObj, tween_duration, { x:fXpos, y:fYpos }, { x:tXpos, y:tYpos, ease:tween_func }); ... // ------------------------------------------------------------ // these are in my [b]Contants.as[/b] file - then included into the class file private const PKG:String = "MyClassName::"; private const BACK_FUNCTION:String = "Back"; private const BOUNCE_FUNCTION:String = "Bounce"; private const ELASTIC_FUNCTION:String = "Elastic"; private const REGULAR_FUNCTION:String = "Regular"; private const STRONG_FUNCTION:String = "Strong"; private const NONE_FUNCTION:String = "None"; private const EASEIN_BEHAVIOR:String = "easeIn"; private const EASEOUT_BEHAVIOR:String = "easeOut"; private const EASEINOUT_BEHAVIOR:String = "easeInOut"; private const EASENONE_BEHAVIOR:String = "easeNone"; // ------------------------------------------------------------- private function fetchEasingFunction(functionkind:String, functionname:String):Function { var result:Function = null; trace(PKG+"fetchEasingFunction - functionkind["+functionkind+"] functionname["+functionname+"]"); switch(functionkind) { case BACK_FUNCTION: switch(functionname) { case EASEIN_BEHAVIOR: result = Back.easeIn; break; case EASEOUT_BEHAVIOR: result = Back.easeOut; break; case EASEINOUT_BEHAVIOR: result = Back.easeInOut; break; default: break; } break; case BOUNCE_FUNCTION: switch(functionname) { case EASEIN_BEHAVIOR: result = Bounce.easeIn; break; case EASEOUT_BEHAVIOR: result = Bounce.easeOut; break; case EASEINOUT_BEHAVIOR: result = Bounce.easeInOut; break; default: break; } break; case ELASTIC_FUNCTION: switch(functionname) { case EASEIN_BEHAVIOR: result = Elastic.easeIn; break; case EASEOUT_BEHAVIOR: result = Elastic.easeOut; break; case EASEINOUT_BEHAVIOR: result = Elastic.easeInOut; break; default: break; } break; case REGULAR_FUNCTION: switch(functionname) { case EASEIN_BEHAVIOR: result = Regular.easeIn; break; case EASEOUT_BEHAVIOR: result = Regular.easeOut; break; case EASEINOUT_BEHAVIOR: result = Regular.easeInOut; break; default: break; } break; case STRONG_FUNCTION: switch(functionname) { case EASEIN_BEHAVIOR: result = Strong.easeIn; break; case EASEOUT_BEHAVIOR: result = Strong.easeOut; break; case EASEINOUT_BEHAVIOR: result = Strong.easeInOut; break; default: break; } break; case NONE_FUNCTION: { switch(functionname) { case EASEIN_BEHAVIOR: result = None.easeIn; break; case EASEOUT_BEHAVIOR: result = None.easeOut; break; case EASEINOUT_BEHAVIOR: result = None.easeInOut; break; case EASENONE_BEHAVIOR: result = None.easeNone; break; } } default: break; } return(result); } // -----------------------------------------------------------------
  2. When I tried to perform a fromTo tween, the onComplete:myFunction was executed as soon as the tween became active and not after the tween had run its course, as I had expected. According to the existing documentation reference which was not immediately obvious to me, if you're going to do things like add references to onComplete, then you need to associate all such references with the to portion of the Tween declaration - not the from part. WRONG: TweenMax.fromTo(dispObj, tween_duration, { alpha:fromAlpha, ease:tween_func, delay:tween_delay, onComplete:tweenCompleted, onCompleteParams:[nexttweenID] }, { alpha:toAlpha }); CORRECT: TweenMax.fromTo(dispObj, tween_duration, { alpha:fromAlpha }, { alpha:toAlpha, ease:tween_func, delay:tween_delay, onComplete:tweenCompleted, onCompleteParams:[nexttweenID] });