PDA

View Full Version : Problem changing label color



Flexy
February 24th, 2010, 10:01 AM
Hey guys
I am building a dynamic RSS viewer in actionscript 3. I wrote a flex application to create the xml code, now I load the xml into my flash application.

Now the user of my flex app can pick a color for a thread. I import this hex value into flash to assign a background color of a movieclip. The problem is that the movieclip also has dynamic text in it.

With my function changeColor() I seem to be changing this font color aswell. I have tried to solve it by using a TextFormat but no luck. Any solutions? Most appreciated.


for each(var channel:XML in rssInfo.channels.channel)
{
var menuItem:MenuItem = new MenuItem();
changeColor(menuItem,channel.color);

menuItem.x = 512 + i*120;
menuItem.y = 718;

menuItem.menuLabel.text = channel.@name;

var format1_fmt:TextFormat = new TextFormat();
format1_fmt.color = 0xFF0000;
format1_fmt.size = 24;
menuItem.menuLabel.setTextFormat(format1_fmt);

addChild(menuItem);
i++;

}
}
function changeColor(object:MovieClip, color:Number){

var colorchange:ColorTransform = new ColorTransform();
colorchange.color = color;
object.transform.colorTransform = colorchange;
}

cbeech
February 24th, 2010, 11:16 AM
yes - the transform.colorTransform prop will color the 'entire' clip - this also includes any applied filters in most cases.

the only way to do this (well probably some others too) is to create a 'background' MC that is a child of the container MC - then change it's color in the exact same way. this way you wont effect the 'whole' container, just the bg.

another way (LOL) would be to use the drawing API to actually draw a colored box into the container - you may need to send it to the bottom of the display list though, and build it within a Shape DisplayObject.

Flexy
February 24th, 2010, 12:20 PM
Thanks for the solution! Working like a charm now.
Cheers