views:

260

answers:

3

Hi there

I am loading an xml file using AS2.0. On Mac, all the elements load completely, but as soon as I run it on Windows, only the first element of type item loads. When I run it on Mac, the elements are loaded in and all item's are separate buttons. When I run it on Windows, only one button appears and its name is ch1. Virgin Group Holdings. None of the other item elements load. I don't have a Windows versions of Flash to work on, so I cannot debug.

Is there another way to determine if this has to do with the XML file loading incompletely or with the depths of the Movieclips? Here is the URL

Here is my XML:

<?xml version="1.0" encoding="UTF-8"?>
<menu>
    <item link="vgh" name="ch1. Virgin Group Holdings" movie="VirleoGH">
     <menuitem link="vgh_overview">Group Overview</menuitem>
     <menuitem link="vgh_capacity">Group Capacity</menuitem>
     <menuitem link="vgh_archive">Certification Archive</menuitem>
     <menuitem link="vgh_timeline">Timeline</menuitem>
    </item>
    <item link="mdb" name="ch2. Manny Design Bureau" movie="MechanologyDB">
     <menuitem link="mdb_overview">Overview</menuitem>
     <menuitem link="mdb_archive">Works Archive</menuitem>
     <menuitem link="mdb_showroom">Showroom</menuitem>
     <menuitem link="mdb_skills">Core Skills</menuitem>
     <menuitem link="mdb_products">Products</menuitem>
    </item>
    <item link="sai" name="ch3. Special Autonomic Industries" movie="SpecialAI">
     <menuitem link="sai_overview">Overview</menuitem>
     <menuitem link="sai_archive">Works Archive</menuitem>
     <menuitem link="sai_showroom">Showroom</menuitem>
     <menuitem link="sai_skills">Core Skills & Serices</menuitem>
     <menuitem link="sai_products">Products</menuitem>
     <menuitem link="sai_infrastructure">Infrastructure</menuitem>
    </item>
    <item link="iacs" name="ch4. Interesting And Cool Stuff"></item>
</menu>

And here is the code where I load the XML file:

var xmlFile:String = "menu.xml";
var menu:XML = new XML();
// ignores spaces and declaration in XML file, improves parsing of XML file
menu.ignoreWhite = true;

// create 'mainMenu' (type Menu), holds all functions related to menu and constructs array from XML
var mainMenu:Menu = new Menu();

// event handler triggerred when XML is completely loaded
menu.onLoad = function(success:Boolean) {

    if (success) {
     // passes XML file to buildMenu function in Menu class to build menu Array
     mainMenu.buildMenu(this);
     // passes 'mainMenu' (type Menu) to buildScene function, builds whole scene with individual MC's
     buildScene(mainMenu);

     // set depth of navigation to top of pile, in order for buttons to move behind the navigation, instead of on top of it
     _root.navigation.swapDepths(theScene);
    }
}

// load XML file
menu.load(xmlFile);

Does somebody mind giving me pointers on pitfalls that I missed?

Regards & TIA

// EDIT src for buildMenu() function

// build multi-dimensional array from XML file received
    function buildMenu(menu:XML):Void {

     // determine how many chambers there are now
     menuArray = menu.firstChild.childNodes;
     var length:Number = menuArray.length;

     // dynamic according to number of chambers
     for (var i:Number = 0; i < length; i++) {
      var sublength:Number = menuArray[i].childNodes.length;
      var submenu:Array = new Array();

      // chamber name and link
      var xmlNode:XMLNode = menuArray[i];
      submenu["name"] = xmlNode.attributes.name;
      submenu["link"] = xmlNode.attributes.link;
      submenu["movie"] = xmlNode.attributes.movie;

      trace(submenu["name"]);

      // create sub-item for each chamber
      for (var j:Number = 0; j < sublength; j++) {
       var subXmlNode:XMLNode = xmlNode.childNodes[j];

       var item:Array = new Array(subXmlNode.firstChild, subXmlNode.attributes.link);
       submenu.push(item);
      }

      // create an entry for each chamber
      mainmenu.push(submenu);
     }
    }

// EDIT 2

I am now running this file from a remote server (Linux box), but still only the first element loads on Windows, with no siblings. On Mac, everything loads fine, I am at a dead end, my deadline (draft #2) for this is in about 12hours and I still need to get a night's rest in. Does anyone have the slightest inkling what this could be? Any pointers or advice will be cordially accepted. The url

Regards and TIA.

// EDIT 3

I am now debugging in Windows and have found that the XML file does get loaded completely eventually. What is odd is that I trace the _x and _y values of all the movieclips, and all change constantly to an acceptable value, but still only the first-added movieclip is visible on the stage. I have traced their depths which do in fact differ, they are enabled (traced), they are _visible (traced that also), everything works perfect on Mac, except when I run it on Windows, so clearly, Flash Player in Windows in doing something unexpected, has anybody encountered this before?

I would really appreciate some help.

Regards and TIA.

A: 

What editor do you use for XML file ? Windows and Mac have a diffrent line ending chars.

greg
I use Dreamweaver CS4 and as far as I know the line end chars are set to Windows format.
Anriëtte Combrink
Do you know of a short method to correct any wrong line end chars?
Anriëtte Combrink
Well, I edited the file on a Windows computer in Dreamweaver CS3 now, I deleted all newlines and manually put them back in. Still, Flash only loads one element, but not the rest of the siblings.
Anriëtte Combrink
A: 

did you try

menu.ignoreWhite = false;

Windows uses CR+LF to mark a newline, Mac uses LF

Rodrigo
I can't, that will completely throw off my parsing.
Anriëtte Combrink
Are you parsing xml yourself? why don't you use API methods?
Amarghosh
Sorry, it's the only way I'm used to. What API's do you recommend?
Anriëtte Combrink
``ignoreWhite`` only ignored _insignificant_ whitespace (ie. the whitespace between the end of one tag and the start of another). It is unlikely to cause you problems if you turn it on.
Richard Szalay
Well, I did try and then it just loaded nothing, both Mac and Windows.
Anriëtte Combrink
The standard xml class in actionscript
Amarghosh
A: 

I'm not sure this is the cause of your problem but two things to look out for in the XML is that the & in "Core Skills & Services" makes the XML invalid. Flash is pretty forgiving about such things but a stricter parser would report it as an error. For example Firefox won't display that XML, and report a "XML Parsing Error: not well-formed" with reference to the position of the &. Trying to open the XML file in Firefox (or IE) is often a quick way to discover errors in XML that Flash/AS2 won't report.

So to use a & in a text, the text needs to be marked as CDATA for it to be valid XML:

<menuitem link="sai_skills"><![CDATA[Core Skills & Services]]></menuitem>

Another thing to look out for (again, it may not be the cause of your problem) is to make sure the file is actually saved in UTF-8 format. Having encoding="UTF-8" in the XML itself is not enough, the file also needs to be saved as UTF-8. This is a quite usual mistake, but as you say you use Dreamweaver, I would assume Dreamweaver normally takes care of that aspect.

Lars
Oh, yes, well I changed that to Core Skills and Services. Also, I did check Dreamweaver and the Prefs state that is supposed to save all new files as Unicode 5.0 UTF-8. I am now running this on a Linux server remotely, but still Windows computers only show the first element "ch1. Virleo Group Holdings". I don't understand it.
Anriëtte Combrink