Tweener and tweening colors

I did a previous post about the static method Color.interpolateColor, but at that time, I hadn't really tried Tweener yet. Let me tell you this, tweening colors has never been easier than with Tweener. I'm am going to redo the same example showing you how simple it is to use Tweener instead of Color.interpolateColor form the fl.motion.Color package. Here is the code, you just have to paste it on a frame an compile it to swf to make it work (you have to have the Tweener classes in your folder or in one of the default class folder).

Actionscript:
  1. import caurina.transitions.*;
  2.  
  3. var simpleSprite:Sprite = new Sprite();
  4. simpleSprite.x = 100;
  5. simpleSprite.y = 100;
  6. simpleSprite.graphics.lineStyle();
  7. simpleSprite.graphics.beginFill(0xff0000);
  8. simpleSprite.graphics.drawRect(0,0,200,100);
  9. addChild(simpleSprite);
  10. simpleSprite.buttonMode = true;
  11.  
  12. simpleSprite.addEventListener(MouseEvent.MOUSE_OVER, makeBlue);
  13. simpleSprite.addEventListener(MouseEvent.MOUSE_OUT, makeRed);
  14.  
  15. function makeBlue(e:MouseEvent):void{
  16. Tweener.addTween(simpleSprite, {_color:0x0000ff, time:1, transition:"easeOutQuart"});
  17. }
  18. function makeRed(e:MouseEvent):void{
  19. Tweener.addTween(simpleSprite, {_color:null, time:1, transition:"easeOutQuart"});
  20. }

That's it. And it does exactly the same thing and probably faster than the Tween classes. Notice that it takes only one line of code to change the color instead of the more complex method I used previously . Also you only have to import the Tweener classes as opposed to six import statements.

Well that's it for today, I'll try and investigate on more Tweener properties because it just keep surprising me.

4 Responses to “Tweener and tweening colors”

  1. jim Says:

    I was trying to get the color tween example working but I get the following error:

    ## [Tweener] Error: The property ‘_color’ doesn’t seem to be a normal object property of [object MovieClip] or a registered special property.

    I am not sure why I am getting this error. Do you know the reason why?

    Jim

  2. jim Says:

    The problem is that I hadn’t imported the color shortcuts class and initialized it. Adding the following code at the begining makes it work fine.

    import caurina.transitions.properties.ColorShortcuts;
    ColorShortcuts.init();

  3. Judie Says:

    I need Tweener code assistance. I need to change the color (to 50% black) on multiple movie clips when one movie clip is in the roll over state. When you roll off that movie clip the 50% black movie clips to to 0% black (or, normal). What would the Tweener code look like in a rollOver function? Thanks in advance.

  4. Steve Says:

    It would be the same……but it’ll be inside a onRollOver function;

    yourButton.addEventListener (’mouseOver’, function()
    {
    Tweener.doTween(yourMC, {_color:0×000000, _alpha:50, transition:”easeOutExpo”});
    }

Leave a Reply


Close
E-mail It