Answer a Flex question, get a Buzzword invite (#3)
See this post for a little more detail, but the short version is that I just got the OK to give out a small number of Buzzword preview invites via this blog, and since this is a Flex blog, we gotta make this about Flex.
So everyone who posts a different correct answer to today’s Flex question in the comments will get a Buzzword invitation emailed to them today. To avoid the spambots, don’t put your email address in the post body, just fill in the email address in the posting form — that way, only I will see it. Only one invite per person. And if you don’t want to bother with the programming question, then please visit our waiting list signup page where you can put in your name and get an invite at some point in the future.
I’ll post a comment declaring each winner for each distinct correct answer to the following question:
There are a number of different ways to get XML data into memory in a Flex application. Describe one!
Technorati Tags: Buzzword, Buzzword Invitations, Flex, Virtual Ubiquity, Word processor




Declare and assign a variable of type XML:
var x:XML = new XML();
my tag inside the XML constructor disappeared
var x:XML = new XML(<root/>);
I’ll start with one, using an HTTPService, you can load an xml file at runtime. Remember to specify the url call the send() method and handle the results
Daniel and Jeff’s posts are both correct. There is at least one more way that I can think of, so today’s contest is still open!
Slightly similar to Daniel’s answer, you could also declare an XML variable like this:
var x:XML = ;
Er… like this:
var x:XML =
You can also load an xml file by using a URLLoader as follows:
private var _xmlLoader:URLLoader;
public function XmlExample() {
this._xmlLoader = new URLLoader();
this._xmlLoader.addEventListener(“complete”,this.parseXML);
this._xmlLoader.load(new URLRequest(“file.xml”));
}
private function parseXML(evt:Event) :void {
var myXML:XML = new XML(this._xmlLoader.data);
}
Is this the third way?
Use a RemoteObject with Adobe LiveCycle to load XML
This is lame but:
var xmlString:String = “model”;
var xml:XML = xmlString as Xml;
….you may do this in an XmlDecode function you define for an HttpService object if the string is passed back from the server.
[Embed(source="file.xml", mimeType="application/octet-stream")]
private var fileClass:Class;
private var xml:XML;
private function initializeXML():void {
var bytes:ByteArray = new fileClass();
xml = new XML(bytes.readUTFBytes(bytes.length));
}
Robin, that way has already been posted.
Alberto, that is a lot like the HTTPService way that was mentioned, but there are good reasons to choose one or the other depending on circumstances, so I’ll count that. But it’s not the third way I had in mind.
JeremyX, sorry, that’s basically the same as a previous approach.
Ben, that’s one I didn’t know! Congrats!
And there’s still one more I’m thinking of that no one has yet posted.
Use the WebService Object to load XML and bind to a local XMLCollection.
David, thanks a lot for the invitation. I can only say WOW! It’s really amazing… I was expecting something cool, but this is really awesome!
thanks again…
XML.ignoreComments = false;
XML.ignoreProcessingInstructions = false;
var x1:XML =
burger
3.95
fries
1.45
in an MXML file:
var xmlData:XML = Yay XML;
in an MXML file:
var xmlData:XML = <root>Yay XML</root>;
Man, it’s hard to write code in these comment boxes!
or using the <model> or <XML> tags:
<model id=”dp” >
<xmlroot>
<dataItem label=”Yay XML” data=”file.jpg” />
</xmlroot>
</model>
Then you can bind from a control:
<list dataprovider=”{dp}” />
Wow, thank you for the invite David!!
Load it via AJAX and pass it to Flash through the ExternalInterface.
Old School
var myXml:URLRequest = new URLRequest("http://www.foo.com/myXml.xml");
OK, I’m declaring this contest closed. I’m surprised that no one mentioned this one: