Ask a Question related to Macromedia Flash Data Integration, Design and Development.

  1. #1

    Default XML node variable

    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();

    crisbosch Guest

  2. Similar Questions and Discussions

    1. +Data (node)
      Can anyone tell me what It takes to get the +Data node and a few other components in the component window. On startup I see the nodes there but in a...
    2. XML node inserting
      Hi is it possible use the function insertChildAfter() (or another useful function) to insert a node under the root node? For example, suppose...
    3. tree node
      Hi, I have a tree with say parent1 and child1 . To access the label of either child or parent I am using...
    4. ANNOUNCE: XUL-Node 0.02
      NAME XUL-Node - server-side XUL for Perl SYNOPSIS package XUL::Node::Application::HelloWorld; # XUL-Node Hello World use XUL::Node; use...
    5. XML append node without DOM
      Note: I'm not using the xmldom functions because I need to maintain compatibility with current typical installs. Say I have an XML file like this...
  3. #2

    Default Re: XML node variable

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



    Noelbaland Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139