PDA

View Full Version : Changing Color in ActionScript 3 with Transition



ventolinmono
July 23rd, 2009, 08:39 PM
Hi all.

This is my first post here and i'm also new with FlashCS4 and ActionScript3.

I was reading Changing Color in ActionScript 3 (http://www.kirupa.com/developer/as3/changing_color_as3.htm) and i was wondering how to make a transition (cross fade) or blend effect between colors.

Thankyou

vxd
July 24th, 2009, 02:45 AM
Check out tweenLite

http://blog.greensock.com/tweenliteas3/

TweenLite.to(object, seconds, {tint:colour});

example

TweenLite.to(ball_mc, 2, {tint:FF00FF00});

greensock
July 24th, 2009, 11:17 AM
TweenLite.to(ball_mc, 2, {tint:FF00FF00});

I think you meant TweenLite.to(ball_mc, 2, {tint:0x00FF00});

("0x" at the beginning of the hex value tells Flash it's a color)

Play around with the Plugin Explorer - it even writes the code for you. Click "EXAMPLE" next to the tint plugin. Don't forget to activate the plugin first if you're using v11 or later. You can also use colorMatrixFilter for a different type of colorization, or hexColors if you need to work with custom hex properties. http://www.tweenlite.com

ventolinmono
July 24th, 2009, 03:43 PM
Thanks guys.

I tried TweenLite demo and its very nice.
However as i said before i am new with AS3.
I assume TweenLite download has to be located on the publish settings so the classes are available to the project.

Then this is what I'm doing:
import gs.*;
import gs.easing.*;
myBtn.addEventListener = (MouseEvent.MOUSE_DOWN, miTween);
function miTween(arg:MouseEvent)
{
TweenLite.to(Symbol1, 1, {tint:0xff0000});
}

And i get this:
1119: Access of possibly undefined property addEventListener through a reference with static type Class.

greensock
July 24th, 2009, 03:53 PM
That error isn't TweenLite-related. It sounds like your "myBtn" isn't an InteractiveObject (like a MovieClip, Sprite, etc.) It's difficult to troubleshoot without seeing your FLA. Assuming your code is in a keyframe on a timeline, you should have a MovieClip/Sprite/Button on the stage that has the name "myBtn" (an instance name). And don't check that "export for ActionScript" checkbox in the properties dialog box. I'm wondering if maybe you did that and named the library asset "myBtn" as a Class name. In your scenario, I bet that's unnecessary. Just name your instance on the stage.

For some basic info on getting up and running with TweenLite/Max, see http://www.greensock.com/as/docs/GreenSock-Tweening-Intro-Chapter.pdf (4MB)

ventolinmono
July 24th, 2009, 06:43 PM
Thanks Greensock

Indeed i was exporting to ActionScript my library items.
I fixed that.
However i get: 1168: Illegal assignment to function addEventListener.

import gs.*;
import gs.easing.*;
myBtn.addEventListener = (MouseEvent.MOUSE_DOWN, miTween);
function miTween(arg:MouseEvent)
{
TweenLite.to(Symbol1, 1, {tint:0xff0000});
}

BTW thanks for the PDF, I'm reading it right now.

creatify
July 24th, 2009, 06:44 PM
import gs.*;
import gs.easing.*;

// this is improper AS3 syntax:
//myBtn.addEventListener = (MouseEvent.MOUSE_DOWN, miTween);


myBtn.addEventListener(MouseEvent.MOUSE_DOWN, miTween);

function miTween(arg:MouseEvent) {
TweenLite.to(Symbol1, 1, {tint:0xff0000});
}

greensock
July 24th, 2009, 07:07 PM
Ah yes, I missed the fact that you were adding an "=" between addEventListener and (. creatify is exactly right.

ventolinmono
July 24th, 2009, 07:29 PM
Goood

This (http://sietemedia.com.mx/elocho/flocking.html) is what it looks like
The thread is nearly solved.
Theres a thing left: to use removeTint or figure out a way to tween between tweens.
I'm working on that.

By far the fastest replies from a forum i ever had. :hugegrin:

greensock
July 24th, 2009, 08:39 PM
To remove a tint, you can just do TweenLite.to(mc, 1, {tint:null});

Not sure what you mean by "tween between tweens".

vxd
July 25th, 2009, 03:12 AM
Those birds are cool

ventolinmono
July 25th, 2009, 02:14 PM
Not sure what you mean by "tween between tweens".

What i mean by tween between tweens is that one button changes the background color to a different color each time it is pressed. (from last tween to new tween).

Thanks vxd i made those birds with the Flint Particle System (http://flintparticles.org/) it is easy to use even for a begginer like me. And the complexity can easily be increased.

greensock
July 25th, 2009, 02:22 PM
What i mean by tween between tweens is that one button changes the background color to a different color each time it is pressed. (from last tween to new tween).

Oh, all you'd have to do is start a new tween each time you want to tween to another color. TweenLite/Max will automatically overwrite the old tween, and take over from there.