Friday, July 25, 2008

Tweener and onEnterFrame

Today I figured out how to use Tweener and onEnterFrame together to create tweens of dynamically drawn content. This allows you to easily change the nature of the tween via the transition equation.

Like this (three transition equations shown here):

The code:
 public function animateLine(e:MouseEvent){   
   var easeType:String =;
   addEventListener(Event.ENTER_FRAME, drawLine);
   lineLength = 0;
   //the ease outs work much better here
   Tweener.addTween(  this, 
                      {  lineLength:stage.stageWidth, 
                         time:2, transition:easeType, 
                         onCompleteParams:[Event.ENTER_FRAME, drawLine]
  public function drawLine(e:Event){;, 0xff0000);, 0);
   line.x = (stage.stageWidth - line.width)/2;
(Sorry about the formatting, I'm still working on that.)

The animateLine function first sets up an enterFrame event listener. This event listener (drawLine) will redraw a line each time it is called using the variable lineLength for the length of the line.

Next we use Tweener.addTween to update the value of lineLength. So the value of lineLength is now changing based on a transition equation over time. Tweener.addTween also allows you to set a callback function (and the arguments). So I used this feature to call the removeEventListener function when lineLength has finished tweening.

Click here to download full source.

Saturday, March 29, 2008

DataProvider Issues

So today I decided to learn about the DataProvider as I need to use it with a TileList in my current project. The Adobe documentation was lacking (no big surprise there) so I turned to my handy Essential ActionScript 3.0. I found nothing. WTF Colin Moock? His previous AS books totally helped me learn AS 2.0. The only thing this book has been good for is the XML section.

I'll bet you though that this post was going to contain something useful about the DataProvider class didn't you? Well it's not. The whole point of this post is to say don't buy the Colin Moock Essential AS 3.0 book.

(I'll try to post more on the DataProvider later.)

Sunday, February 17, 2008

Javascript test

This is just a test post. Please ignore.