SimonAdrian
asked on
How do I set the bgcolor through xml
I want to set the background color of a movie through xml.
Im using the flash.geom classes to colorize the bg color:
import flash.geom.ColorTransform;
import flash.geom.Transform;
var colorTrans:ColorTransform = new ColorTransform();
var trans:Transform = new Transform(car_mc);
colorTrans.rgb = 0xFF0000;
trans.colorTransform = colorTrans;
The xml should be something like beyond (shortversion) and it's deliberately not CDATA, because I'm goin' to update the xml through an asp solution and have no idea how that should be done with CDATA:
<item>
<bgcolor>#990000</bgcolor>
</item>
Which means that I need a solution that can change the '#' to '0x' and also a practice for the xml-node to replace the colorTrans.rgb
Im using the flash.geom classes to colorize the bg color:
import flash.geom.ColorTransform;
import flash.geom.Transform;
var colorTrans:ColorTransform = new ColorTransform();
var trans:Transform = new Transform(car_mc);
colorTrans.rgb = 0xFF0000;
trans.colorTransform = colorTrans;
The xml should be something like beyond (shortversion) and it's deliberately not CDATA, because I'm goin' to update the xml through an asp solution and have no idea how that should be done with CDATA:
<item>
<bgcolor>#990000</bgcolor>
</item>
Which means that I need a solution that can change the '#' to '0x' and also a practice for the xml-node to replace the colorTrans.rgb
ASKER
Well because Ive found an asp colorpicker component that pass the color as #FF0000. And in the frontend users shouldnt have to know colorcodes.
Thanks anyway.
But the primary problem is how to change the bgcolor through xml.
Thanks anyway.
But the primary problem is how to change the bgcolor through xml.
actually, you mean the primary problem is you need to turn a "#" to a "0x"
you are able to get the XML into Flash I assume... so you take that node value... lets call it "theNode"
var theNode:String = "#9900FF";
import flash.geom.ColorTransform;
import flash.geom.Transform;
/// the code you need
var theNumber:String = theNode.split("#")[1];
var theBGColor:Number = Number("0x" + theNumber );
///
var colorTrans:ColorTransform = new ColorTransform();
var trans:Transform = new Transform(car_mc);
colorTrans.rgb = theBGColor;
trans.colorTransform = colorTrans;
now, just let me know if you need help getting XML into Flash
rp
you are able to get the XML into Flash I assume... so you take that node value... lets call it "theNode"
var theNode:String = "#9900FF";
import flash.geom.ColorTransform;
import flash.geom.Transform;
/// the code you need
var theNumber:String = theNode.split("#")[1];
var theBGColor:Number = Number("0x" + theNumber );
///
var colorTrans:ColorTransform = new ColorTransform();
var trans:Transform = new Transform(car_mc);
colorTrans.rgb = theBGColor;
trans.colorTransform = colorTrans;
now, just let me know if you need help getting XML into Flash
rp
BTW...
this line of code: var theNode:String = "#9900FF";
was only used for testing... you would obviously use your XML data there.
rp
this line of code: var theNode:String = "#9900FF";
was only used for testing... you would obviously use your XML data there.
rp
ASKER
Thanks, that seems to solve one part of the problem.
Actually I dont know how to apply the xml-data so that it can replace the colorcode in the above example.
So far I've only been using the xmlconnector, so Im not familiarized with applying xml to anything else than the UI-components.
I get the idea about how to apply xml-text to dynamic textfields, but how to apply the content of a xml-node to anything else - there Im lost.
Actually I dont know how to apply the xml-data so that it can replace the colorcode in the above example.
So far I've only been using the xmlconnector, so Im not familiarized with applying xml to anything else than the UI-components.
I get the idea about how to apply xml-text to dynamic textfields, but how to apply the content of a xml-node to anything else - there Im lost.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot.
It works excellent.
Just for others to be enlightened here is the complete code:
function loadXML(loaded) {
import flash.geom.ColorTransform;
import flash.geom.Transform;
var theNumber:String = this.firstChild.childNodes [0].childN odes[0].fi rstChild.n odeValue.s plit("#")[ 1];
var theBGColor:Number = Number("0x" + theNumber );
var colorTrans:ColorTransform = new ColorTransform();
var trans:Transform = new Transform(car_mc);
colorTrans.rgb = this.firstChild.childNodes [0].childN odes[0].fi rstChild.n odeValue;
trans.colorTransform = colorTrans;
colorTrans.rgb = theBGColor;
trans.colorTransform = colorTrans;
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("cars.xml");
and the xml in short:
<?xml version="1.0"?>
<cars>
<brand>
<color>#60ABCA</color>
<year>2003</year>
</brand>
</cars>
It works excellent.
Just for others to be enlightened here is the complete code:
function loadXML(loaded) {
import flash.geom.ColorTransform;
import flash.geom.Transform;
var theNumber:String = this.firstChild.childNodes
var theBGColor:Number = Number("0x" + theNumber );
var colorTrans:ColorTransform = new ColorTransform();
var trans:Transform = new Transform(car_mc);
colorTrans.rgb = this.firstChild.childNodes
trans.colorTransform = colorTrans;
colorTrans.rgb = theBGColor;
trans.colorTransform = colorTrans;
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("cars.xml");
and the xml in short:
<?xml version="1.0"?>
<cars>
<brand>
<color>#60ABCA</color>
<year>2003</year>
</brand>
</cars>
glad to here it...
and just a pointer for you...
to make it easier to update later, I would change this line of code:
var theNumber:String = this.firstChild.childNodes [0].childN odes[0].fi rstChild.n odeValue.s plit("#")[ 1];
to this:
var xmlColor:String = this.firstChild.childNodes [0].childN odes[0].fi rstChild.n odeValue;
var theNumber:String = xmlColor.split("#")[1];
rp
and just a pointer for you...
to make it easier to update later, I would change this line of code:
var theNumber:String = this.firstChild.childNodes
to this:
var xmlColor:String = this.firstChild.childNodes
var theNumber:String = xmlColor.split("#")[1];
rp
it is not necessary at all. just pass the Hex value itself into Flash...
then when you parse your XML in Flash, just use code like this...
var theBGColor:Number = Number("0x" + theNumber );
rp