dcsimg
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Problem getting Values of little XML Document in vars.

  1. #1
    Junior Member
    Join Date
    Feb 2001
    Posts
    8
    Hello Everybody,

    i tried the hole evening, getting the following xml Dokument
    in variables in flash.
    The xml Document looks like this ( The [ should mean "<" and ">":

    [?xml version="1.0" ?]
    [menuepunkt]
    [mp id="1"]
    [bez]one[/bez]
    [bes]Description one[/bes]
    [/mp]
    [mp id="2"]
    [bez]two[/bez]
    [bes]Description two[/bes]
    [/mp]
    [/menuepunkt]

    The Code i tried, was:

    objxml = new XML();
    objxml.load("menue.xml");
    xmenu = objxml.firstChild;
    // These are the vars I want to declare
    test1 = xmenue.childNodes[0].firstChild.nodeValue;
    test2 = xmenue.childNodes[1].firstChild.nodeValue;


    I don´t know if this is the right way. The only thing I know is that it isn´t going.
    Could anybody help me with this problem ?

    Thanks
    Regards
    s.Schacht

  2. #2
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    The best way to process your XML is to use the XML onload call back routine.

    Basically your XML is not loaded when you run:


    xmenu = objxml.firstChild;

    Have a look at page 412-413 of the ActionScript Dictionary or the XML.Onload online help it has an example of using XML.onLoad.

    Or you could look at my FAQ with pointers to some good XML tutorials to help you along:

    http://www.tupps.com/flash/faq/xml.html

    Thanks

    Luke

  3. #3
    Hello mr. Schacht,
    I think I know what prob you got there:
    you assign the xml to load an then you try to readout values directly after this.. but the load command woun't be as fast and it is not framebased (asyncron).

    Use the .onLoad eventhandle in your case it would look like this:
    Code:
    objxml.onLoad = myOnLoad;
    
    function myOnLoad(success) {
      if (success) {
       var xmenu = new XML();
       xmenu = this.firstChild; 
       // These are the vars I want to declare 
       _level0.test1 = xmenu.childNodes[0].firstChild.nodeValue; 
       _level0.test2 = xmenue.childNodes[1].firstChild.nodeValue; 
      } else {
        _level0.gotoAndStop("connectionFailed")
      }
    }
    PS: Keep in mind the myOnLoad or how ever you call your function is a child of the XMLObject you assigned it to so you have to use 'this' to access it...
    And _level0 or _root to do actions and assignment to vars outside of the myOnLoad...

    regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center