Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Data Integration / July 2008



Tip: Looking for answers? Try searching our database.

XML node variable

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
crisbosch - 11 Jul 2008 02:38 GMT
HI
I'm trying to access RootNode in the code from anywhere in the timeline.  I
assigned a value in the loadFile function but when I try to access it from
outside this function I get "undefined".  How can I have this easily accessible
from anywhere in the code?  I know _global.RootNode will not work for XMLnode
types.  
Thanks!

// Initialize variables
var selectedUnitSize:String = "studio";
var selectedFloor:Number;
var matchingFloors:Array;// for Select a floor component
var matchingUnits:Array;// for keyplan component
var RootNode:XMLNode;

// Creates XML Object
var floorplansXML:XML = new XML();
floorplansXML.ignoreWhite = true;
floorplansXML.onLoad = loadFile;
floorplansXML.load("xml/floorplans.xml");

function init(){
    loadAllFloorplans();  
}

// Accesses XML data from the XML object
function loadFile(success:Boolean):Void {
    if (success) {
        RootNode = this.firstChild;
        trace(RootNode);

    } else {
        trace("Error in loading XML file");
    }
};

// Loads selected floorplan data from XML file
function loadAllFloorplans(selectedUnitSize) {
    //trace(RootNode);
    for (var i:Number = 0; i<RootNode.childNodes.length; i++) {
        nodeUnitSize = RootNode.childNodes[i].attributes.unitsize;
        if (nodeUnitSize == selectedUnitSize) {
            matchingUnits.push(RootNode.childNodes[i]);
            break;
        }
    }
};

init();
Noelbaland - 11 Jul 2008 04:10 GMT
Hello there,

Don't use the init function as you lose the scope to your RootNode variable.
You should instead call the loadAllFloorplans function from inside the loadFile
function.  

if(success){
   RootNode = this.firstChild;
   // Pass in the selectedUnitSize variable as a parameter here
   loadAllFloorplans(selectedUnitSize);
}

and then in the loadAllFloorPlans function set a different name for the
parameter and strict type it to Number.  

function loadAllFloorPlans(unitSize:Number) {
// Use unitSize throughout the rest of your script
for (var i:Number = 0; i<RootNode.childNodes.length; i++) {
        nodeUnitSize = RootNode.childNodes[i].attributes.unitsize;
        if (nodeUnitSize == unitSize) {
            matchingUnits.push(RootNode.childNodes[i]);
            break;
        }
    }
};
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.