PDA

View Full Version : Load Color from xml or txt


calufa
09-13-2005, 01:40 AM
Hello, well i was trying to get color from a xml file or txt file, but i cant get it work. What i need is this: a movie clip that load his color from a xml or txt or css file, so if i change the color from the txt file it change the color on the movie clip....

thanks in advanced

moot
09-13-2005, 02:48 AM
use text file with string variables. you loadVar the text file

incomingVars = new LoadVars();
incomingVars.load("textData.txt");

all the variables in the text file will be loaded in incomingVars

the file can look like this:

trash=xxx
&passColor=0xFFFFFF&trash=xxx


then use this code to change the color of something dynamically. if you drew a red box and named it "box" you could then do this:

boxColor = new Color(box);
boxColor.setRGB(incomingVars.passColor);

that will change box's color to whatever hex color you put in - so the box would turn to white

hope that gets you goin - look up this stuff in reference if you need more explanation

logictude
09-13-2005, 03:28 AM
I've used XML files to maintain configuration information before, color wasn't an issue.

You said you couldn't get it to work. What specifically was happening? Was it reading the value but not rendering the color?

calufa
09-13-2005, 03:31 AM
weird dont work... i am using this....

textocargado = new XML();
textocargado.load("color.xml");
textocargado.onLoad = function()
{
texto = textocargado;
trace (texto)
}
boxColor = new Color(box);
boxColor.setRGB(texto);

the movie clip has a name "box"

and the xml file got this: 0xFF0000

but still dont work

MichaelxxOA
09-13-2005, 04:01 AM
you need to convert texto to a number first, you can either cast it with Number(texto) or you can use parseInt(texto);. Take Care.

-Michael;

ps: you might need to add the 0x in front, which you can do as a string before parsing it something like..


texto = "0x"+texto;
texto = parseInt(texto);


bye

logictude
09-13-2005, 04:07 AM
See what happens when you step away from your computer? Someone beats you to the punch.

I can't add much.

If you want to make your XML look a little more like CSS, store your colors as standard hex values (i.e. FF0000) and parseInt(hex, 16);