{"id":107,"date":"2011-01-24T02:33:55","date_gmt":"2011-01-24T00:33:55","guid":{"rendered":"http:\/\/blog.teleranek.org\/?p=107"},"modified":"2025-06-29T12:29:14","modified_gmt":"2025-06-29T10:29:14","slug":"fixing-twease-tweaxing","status":"publish","type":"post","link":"https:\/\/blog.teleranek.org\/?p=107","title":{"rendered":"Fixing Twease &#8211; tweaxing"},"content":{"rendered":"<p>Yup, I know that everyone&#8217;s using TweenLite or Tween-something from GreenSock, but some time ago TweenLite wasn&#8217;t free for commercial use so I had to grab something different. I&#8217;ve found Twease &#8211; nice&#8217;n&#8217;small tweening lib with bezier tweening and several other fancy options. Then I&#8217;ve used to it, and it appeared in various projects. But there is annoying bug &#8211;  Twease (newest version, 2.0) doesn&#8217;t render tween if your computer slowed down during the time the tween was taking place.<br \/>\nImagine &#8211; you are building an app which initializes thousands of different stuff at the beginning and animates an alpha component of DisplayObject&#8217;s, so that they could appear after launching your app. But they won&#8217;t appear if somebody has 300Mhz Athlon or 1000 tabs opened in firefox.<br \/>\nDebugging a tweening classes is quite unpleasant, due to asynchronousity and hundreds of anonumous classes with strange short names and properties (yup, I think that majority of Tweening libraries are written in this hard-to-read way ;) ), so I never fixed this but used different hacks&#8230; until now. Jeez&#8230; the fix is simple and I could do this two years ago, but I wanted to write a pile of workarounds rather than to look into Twease&#8217;s code.<\/p>\n<p>Ok, so finally, this is the fix &#8211;<\/p>\n<p>1. You get rid of the &#8220;import flash.utils.getTimer;&#8221; at the beginning<br \/>\n2. You define some global vars<br \/>\n<code><br \/>\nprivate static var frameCounter:uint = 0;<br \/>\n\/\/ 1000 miliseconds \/ 50 frames per second = 20ms for displaying one frame<br \/>\nprivate static var _ms:Number = 1000\/50;<br \/>\n<\/code><br \/>\n3. you write your own getTimer function<br \/>\n<code><br \/>\nprivate static function getTimer():uint{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;return frameCounter*_ms;<br \/>\n}<br \/>\n<\/code><br \/>\n4. at the beginning of an &#8220;update&#8221; function you increment &#8220;frameCounter&#8221;:<br \/>\n<code><br \/>\npublic static function update(timerevent:Event):void {<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;frameCounter++;<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;(...)<br \/>\n<\/code><br \/>\n5. And to add a pinch of a spice to our masterpiece, we  add setter and getter of &#8220;_ms&#8221; variable:<br \/>\n<code><br \/>\npublic static function set fps( val:Number ):void{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;_ms = 1000\/val<br \/>\n}<br \/>\npublic static function get fps( ):Number{<br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;return 1000\/_ms;<br \/>\n}<br \/>\n<\/code><\/p>\n<p>What we do here, we change Twease&#8217;s getTimer() method which gets time since flash vm start, to quasi-getTimer which returns the same, but with respect to frame-drops &#8211; so if we will loose some frames during tweening, our getTimer will slow down too. This is rather a hack than a bug fix &#8211; a real fix would involve changing something in Twease&#8217;s &#8220;render&#8221; function, to force rendering of the tween at the end.<br \/>\nAt the beginning we should provide our movie&#8217;s frameRate:<br \/>\n<code><br \/>\nTwease.fps = stage.frameRate;<br \/>\n<\/code><br \/>\nOtherwise we assume that the framerate is 50. Ok, Im talkin obvious things right now so this is the end of this post. (&#8220;hacked&#8221; twease: <a href=\"http:\/\/dl.dropbox.com\/u\/1268089\/Twease.as\">here<\/a>)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yup, I know that everyone&#8217;s using TweenLite or Tween-something from GreenSock, but some time ago TweenLite wasn&#8217;t free for commercial use so I had to grab something different. I&#8217;ve found Twease &#8211; nice&#8217;n&#8217;small tweening lib with bezier tweening and several other fancy options. Then I&#8217;ve used to it, and it appeared in various projects. But [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[18,13,62,63],"class_list":["post-107","post","type-post","status-publish","format-standard","hentry","category-flash-experiments","tag-as3","tag-bug","tag-twease","tag-tweening"],"_links":{"self":[{"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/posts\/107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=107"}],"version-history":[{"count":7,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/posts\/107\/revisions"}],"predecessor-version":[{"id":114,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=\/wp\/v2\/posts\/107\/revisions\/114"}],"wp:attachment":[{"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.teleranek.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}