A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Flash MX XML parser does not work like Flash 5 ?

  1. #1
    Member
    Join Date
    Apr 2003
    Location
    detroit, mi usa
    Posts
    53

    Flash MX XML parser does not work like Flash 5 ?

    Hey Flashkit,

    I have just finished lengthy project for a client in Flash 5 where it parses a single long xml file at the beginning of the flash movie and then displays different content depending on where you navigate through the rest of the movie. I have perfected it and it is snag free until now. The client would like to export the project in Flash MX. Once I did this the project no longer displays any XML content. I am not sure but I do not think the XML is being parsed anymore whatsoever.

    I have put these checks in the place and no xml status errors appear nor does the "we made it" text.

    brochureXML = new XML();
    brochureXML.load("brochure.xml");

    tellmekid = brochureXML.status; //Just a text field

    if (brochureXML.loaded == true) {
    doesitload = "we made it"; //Just a text field
    brochureXML.parseXML("brochure.xml");
    }

    Sorry I do not have a soure files to post, and I know this may be a wide open question. But would any of you suggest where I may begin? I feel it may be an encoding issue for the xml file in Flash MX.

    Any help is appreciated, Thanks,
    - Jimmy

  2. #2
    Senior Member
    Join Date
    Feb 2001
    Location
    Provo, Utah
    Posts
    1,112
    You need to use the onLoad handler... loading XML is asyncronous - it'll happen when it happens... the code will keep going even if the XML doc hasn't finished.

    Code:
    brochureXML = new XML();
    brochureXML.onLoad=handleLoad;
    brochureXML.load("brochure.xml");
    function handleLoad(booleanStatus){
       trace(booleanStatus);
       trace(brochureXML.status);
    }
    You don't need to call the parseXML function- it get's called once the XML document has finished loading.

    You might also need to look into the 'ignoreWhite' property...
    Richard Lyman
    rich at lithinos.com
    www.lithinos.com

  3. #3
    Member
    Join Date
    Apr 2003
    Location
    detroit, mi usa
    Posts
    53

    To VAYKENT

    Hey VAYKENT,

    I have adapted your scripts and they work well, they give me feedback about loading the xml, boolean status, and xml status.

    brochureXML = new XML();
    brochureXML.load("brochure.xml");
    brochureXML.onLoad = handleLoad;
    function handleLoad(booleanStatus) {
    checksforload = "made it";
    checksforload1 = (booleanStatus);
    checksforload2 = (brochureXML.status);
    }

    Whether I export the project in Flash 5 or MX these scripts work perfectly, however the project continues to fail to load the xml when exported to MX. The only thing I am doing differently is exporting to MX and that there in lies the problem.

    Have any other suggestions?
    - Jimmy

  4. #4
    Senior Member
    Join Date
    Feb 2001
    Location
    Provo, Utah
    Posts
    1,112
    Could you describe what you mean by - '...fail to load the xml...'? What are the trace statments inside the handleload function returning?
    Richard Lyman
    rich at lithinos.com
    www.lithinos.com

  5. #5
    Member
    Join Date
    Apr 2003
    Location
    detroit, mi usa
    Posts
    53

    To VAYKENT

    VAYKENT,

    checksforload = "made it";
    checksforload1 = (booleanStatus);
    checksforload2 = (brochureXML.status);

    returns
    made it
    true
    0

    While exporting in Flash 5 the following line fails to load the xml content. When I comment out this line the movie works as expected.
    brochureXML.ignoreWhite = true;

    Could poor xml formatting be causing it to fail? But wait a minute the xml status returns 0 which means that it is formatted correctly. What does not make sense here?

    - Jimmy

  6. #6
    Senior Member
    Join Date
    Feb 2001
    Location
    Provo, Utah
    Posts
    1,112

    What you meant to say then was - my custom code fails to retrieve the correct data - not Flash fails to load the XML.


    Loading and parsing the XML took place correctly, but without ignoreWhite in F5, you reference data a certain way based on it being in a certain location... and that way will not be the same when you use the FMX ignoreWhite property, since the location will not be the same...

    Your data is all there, you just need to change your code to find it correctly... or set the ignoreWhite property to false... I'd go with setting ignoreWhite to false.

    P.s. - I forgot to menton - whitespace is considered a node in Flash... and that's why ignoreWhite is 'causing' problems.
    Richard Lyman
    rich at lithinos.com
    www.lithinos.com

  7. #7
    Member
    Join Date
    Apr 2003
    Location
    detroit, mi usa
    Posts
    53

    Flash MX XML parser does not work like Flash 5

    Hey Richard,

    Thanks for your help you are quite right. The xml content was being loaded just fine. By the way your custom scripts were working correctly too. But the xml loading and formatting status was not where to look for a solution.

    Wondering why setting brochureXML.ignoreWhite = true; in F5 had the effect of breaking the movie's navigation...still I am not quite sure...but I have removed this line. By Default ignoreWhite = false; so there is no need to keep write the script.

    Back to my original question, Does the Flash MX XML parser work like the Flash 5 XML parser and the answer is "Perhaps No".

    In the project when a Next button is used it calls the following snippet of code


    function updateContent() {

    mainTag = new XML();
    mainTag = brochureXML.childNodes;

    //brochureNodes = mainTag[2].childNodes;
    brochureNodes = mainTag[1].childNodes;

    for (i=0; i<=brochureNodes.length; i++) {

    // Much more came after this but you get the gist
    }


    Essentially this function creates a new xml object and sets the brochureNodes variable to the 2nd array item of the xml object. This is used to determine which content to load in the rest of the movie. When viewing this xml object in its entirety in F5 you would see 2 commas prior to the first childNode. When doing the same in FMX you would see only 1 comma prior to the first childNode. (The only difference was what export mode F5 or FMX was used) So the navigation of the project failed and no content would display. The remedy was to make the brochureNodes variable look at the 1st array item of the xml object. Now everything works as expected.

    Thanks again,
    - Jimmy

  8. #8
    Senior Member
    Join Date
    Feb 2001
    Location
    Provo, Utah
    Posts
    1,112
    Glad it ended up working out... sorry I couldn't help more.
    Richard Lyman
    rich at lithinos.com
    www.lithinos.com

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