|
-
Still having troubles tweening color with Actionscript
I'm trying to use ActionScript to control color ransformations for my background image in a movie that I'm making. Rather than actually animate the different combinations of color transitions by hand, I want to use AS to check to see what the color that I want to change the background to is, and then slowly change the color to match.
I can use setTransform to do that, but it changes the color in one frame, so I'm trying to make the transition gradual with the following code:
code:
onClipEvent(load) {
cVarR = 0;
cVarG = 0;
cVarB = 0;
}
onClipEvent(enterFrame) {
newcVarR = -100;
newcVarG = 80;
newcVarB = 120;
if (newcVarR < cVarR) {
cVarR = cVarR - 20;
} else if (newcVarR > cVarR) {
cVarR = cVarR + 20;
}
if (newcVarG < cVarG) {
cVarG = cVarG - 20;
} else if (newcVarG > cVarG) {
cVarG = cVarG + 20;
}
if (newcVarB < cVarB) {
cVarB = cVarB - 20;
} else if (newcVarB > cVarB) {
cVarB = cVarB + 20;
}var oNewColor:Object = new Object();
oNewColor.rb = cVarR;
oNewColor.gb = cVarG;
oNewColor.bb = cVarB;
var cPict:Color = new Color(pict);
cPict.setTransform(oNewColor);
trace(cVarR+" , "+cVarG+" , "+cVarB);
}
...and I'm having no luck. This code is placed in the movie clip that I want to change the color on, but it doesn't do anything. The trace command shows the variables stepping incrementally from 0 (the value that I defined for each of the cVar colors at onLoad) to the value that I declared in newcVar(color), but the color itself doesn't change.
This is driving me up the wall, here.
I appreciate any help you guys can offer.
Pacem!
--T
"Clearly I cannot choose the cup in front of you!"
-
http://livedocs.macromedia.com/flash...=00001275.html
probably should look it up, the color object seems need more than just rb,gb,bb, but i am not sure if that caused the problem, everything else looks okay.
-The Dancin kidd

-
i think you're running this code while the playhead is moving from frame to frame. these things (an actionscript onEnterFrame action and a 'normal flash stroll along the timeline') don't match very well. try to stop the playhead and see what happens.
-
I've gotten this code to work on a button (kind of):
If I write:
code:
on(press) {
var oNewColor:Object = new Object();
oNewColor.rb = -100;
oNewColor.gb = 80;
oNewColor.bb = 120;
}
on(release) {
var cPict:Color = new Color(pict);
cPict.setTransform(oNewColor);
}
But that makes the transition in one jump, whch defeats my purpose. So the code I'm using for the setTransform object doesn't need to reference the ra, ga, ba, or aa values (indeed, my Flash MX 2004 Actionscript Bible recommends that I don't use any of the "a" values when using a setTransform color object).
So mattCow may be correct and there may be a problem with using this command as I'm advancing the playhead merrily along. If that's the case, though, does anyone have any ideas how I could manage a color shift like this? I don't neccessarily want someone to go, "Poof, here's the code," but a pointer in the right direction would be mightily appreciated.
Currently, the way that I'm faking this is by using the colors involved as mc's and using a step function to reduce one mc's alpha while the other mc's alpha is being increased. An ugly hack, and one that uses up more memory and bandwidth than I want to, ideally, be using for something that's simply a color shift on the background of my image.
As always, help is appreciated;
Pacem!
--T
"Clearly I cannot choose the cup in front of you!"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|