Home > Flex > Answer a Flex question, get a Buzzword invite (#3)

Answer a Flex question, get a Buzzword invite (#3)

May 21st, 2007

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: , , , ,

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
Author: David Coletta Categories: Flex Tags:
  1. May 21st, 2007 at 09:48 | #1

    Declare and assign a variable of type XML:

    var x:XML = new XML();

  2. May 21st, 2007 at 09:50 | #2

    my tag inside the XML constructor disappeared

    var x:XML = new XML(<root/>);

  3. May 21st, 2007 at 09:51 | #3

    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

  4. david
    May 21st, 2007 at 09:53 | #4

    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!

  5. May 21st, 2007 at 10:08 | #5

    Slightly similar to Daniel’s answer, you could also declare an XML variable like this:

    var x:XML = ;

  6. May 21st, 2007 at 10:09 | #6

    Er… like this:


    var x:XML =

  7. May 21st, 2007 at 10:32 | #7

    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?

  8. Nathanael de Jager
    May 21st, 2007 at 10:50 | #8

    Use a RemoteObject with Adobe LiveCycle to load XML

  9. May 21st, 2007 at 10:59 | #9

    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.

  10. May 21st, 2007 at 11:09 | #10

    [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));
    }

  11. david
    May 21st, 2007 at 11:12 | #11

    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.

  12. Nathanael de Jager
    May 21st, 2007 at 11:12 | #12

    Use the WebService Object to load XML and bind to a local XMLCollection.

  13. May 21st, 2007 at 11:38 | #13

    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…

  14. Copyleft
    May 21st, 2007 at 11:44 | #14

    XML.ignoreComments = false;
    XML.ignoreProcessingInstructions = false;
    var x1:XML =

    burger
    3.95

    fries
    1.45

  15. Dusty
    May 21st, 2007 at 12:01 | #15

    in an MXML file:
    var xmlData:XML = Yay XML;

  16. Dusty
    May 21st, 2007 at 12:02 | #16

    in an MXML file:
    var xmlData:XML = <root>Yay XML&lt/root>;

  17. Dusty
    May 21st, 2007 at 12:12 | #17

    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}” />

  18. Nathanael de Jager
    May 21st, 2007 at 12:23 | #18

    Wow, thank you for the invite David!! :) :)

  19. May 21st, 2007 at 19:21 | #19

    Load it via AJAX and pass it to Flash through the ExternalInterface. :)

  20. ROMAIN
    May 24th, 2007 at 04:38 | #20

    Old School ;-)


    var myXml:URLRequest = new URLRequest("http://www.foo.com/myXml.xml");

  21. david
    May 24th, 2007 at 05:19 | #21

    OK, I’m declaring this contest closed. I’m surprised that no one mentioned this one:

    <mx:XML source="../xml/version.xml" id="versionXML" />
    
Comments are closed.