Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 578
  • Last Modified:

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

0
SimonAdrian
Asked:
SimonAdrian
  • 5
  • 3
1 Solution
 
rascalpantsCommented:
why would you pass the #?

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
0
 
SimonAdrianAuthor Commented:
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.
0
 
rascalpantsCommented:
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
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
rascalpantsCommented:
BTW...  

this line of code:  var theNode:String = "#9900FF";

was only used for testing... you would obviously use your XML data there.


rp
0
 
SimonAdrianAuthor Commented:
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.



0
 
rascalpantsCommented:
well, the same code you use to apply the xml-text to dynamic text fields is what youwould use to see the variable named "theNode".

see if you can get that to work, and if not let me know.


rp
0
 
SimonAdrianAuthor Commented:
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].childNodes[0].firstChild.nodeValue.split("#")[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].childNodes[0].firstChild.nodeValue;
    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>
0
 
rascalpantsCommented:
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].childNodes[0].firstChild.nodeValue.split("#")[1];

to this:

var xmlColor:String = this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;

var theNumber:String = xmlColor.split("#")[1];




rp


0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now