What type of variable is "<name>" in xml when using a URLRequest

Hello,

I have a little problem, I am creating a class that retrieves values out of an XML because I use this all over the place but only want to have to call one function to do it from now on.

So I created my AS file for it and set up all the functions that I usually use.

I don’t know the correct name but I will call it the “main” function (the one that has the same name as the class and so is ran when the class is called).

The “main” function for this is:

public function retrieveXML(xmlLocation:String,valueNode:String,valueAttribute:String)
        {
            _valueNode = valueNode;
            _valueAttribute = valueAttribute;
            var urlRequest:URLRequest = new URLRequest(xmlLocation);
            var urlLoader:URLLoader = new URLLoader(urlRequest);
            listenerDispatcher(urlLoader,null,xmlComplete);
            
        }

As you can see, when it is used in other AS files, I will have to specify the location of the xml document, the name of the element (Which I have called valueNode) and the attribute of that element (valueAttribute).

I created the global variables “_valueNode” and “_valueAttribute” because I will be using these values lower down in the AS file but wanted to only have to call one function from other AS files. Therefore I have declared “_valueNode” and “_valueAttribute” just above the “main” function.

Everything works fine until I try and load information out of the xml because I do not know what kind of object the “element name” is in the xml.

For example here is my xml document:


<images>
        <**logo** href="com/fusedDesign/images/logo.jpg" />
        <**img** href="1.gif" />
        <**img** href="2.gif" />
        <**btn** href="com/fusedDesign/images/portfoliobtn.psd" />
        <**btn** href="com/fusedDesign/images/contactbtn.psd" />
        <**btn** href="com/fusedDesign/images/services.psd" />
    </images>

What I would like to know is what kind of object the elements in bold are, as the problem is, when trying to get the URL out, it will not work.

Let me elaborate, I do URLRequest(xml.logo.attribute(“href”)[0]);

Where xml is the variable containing the xml Document. This works fine and when using addChild, the logo is added to the stage.

Although, as this is an AS file that will be used by others, the function that gets the images out of the xml with a Loader is:

private function loadValues(xml:XML,valueNode:String,valueAttribute:String)
        {
            var valueArray:Array = new Array(xml.length());
            valueNode = _valueNode;
            valueAttribute = _valueAttribute;
            
            for(var i = 0; i < xml.length(); i++)
            {
                var valueLoader:Loader = new Loader();
                var requestLocation = xml.valueNode.attribute(valueAttribute)*;
                trace("value of ValueNode: " + valueNode);
                trace("xml length: " + xml.length() + "
i: " + i + "
valueNode: " + valueNode + "
valueAttribute: " + valueAttribute + "
url: " + xml.valueNode.attribute("href")[0]);
                var valueRequest:URLRequest = new URLRequest(requestLocation);
                valueArray* = xml.logo.attribute("href")[0];
                valueLoader.load(valueRequest);
                trace("retrieveXML() >>> " + valueNode + " 1 : " + valueArray*);
            }
        }

As can be seen, I have traced all the values to see which is not working, and it seems that it is the valueNode. If I trace “xml.logo.attribute(valueAttribute)[0]”; it works fine because valueAttribute should be a String when used in the function attribute(), the problem is valueNode should not be, and that is why it does not return the URL for logo.jpg.

So my question is; What type of “object” (probably the wrong word) is (what I have called) the valueNode, because Flash is seeing it as a String at the moment using these functions, and this is the problem.

Thanks for your time,

Any reply is appreciated,

Blekk.

P.S.

Here is the whole AS File:

package com.fusedDesign.xmlscripts
{    

    import flash.net.URLRequest;
    import flash.net.URLLoader;
    import flash.events.*;
    import flash.display.Loader;
    import flash.display.LoaderInfo;
    
    public class retrieveXML
    {
        
        //globals
        var _valueNode:String = new String("");
        var _valueAttribute:String = new String("");
        
        public function retrieveXML(xmlLocation:String,valueNode:String,valueAttribute:String)
        {
            _valueNode = valueNode;
            _valueAttribute = valueAttribute;
            var urlRequest:URLRequest = new URLRequest(xmlLocation);
            var urlLoader:URLLoader = new URLLoader(urlRequest);
            listenerDispatcher(urlLoader,null,xmlComplete);
            
        }
        
        private function listenerDispatcher(dispatcher:IEventDispatcher,progressHandler:Function,completeHandler:Function):void
        {
            if(progressHandler == null)
            {
                dispatcher.addEventListener(Event.COMPLETE,completeHandler);
            }
            else
            {
                dispatcher.addEventListener(Event.COMPLETE,completeHandler);
                dispatcher.addEventListener(ProgressEvent.PROGRESS,progressHandler);
            }
        }
        
        private function xmlComplete(evnt:Event)
        {
            var xml:XML = new XML(evnt.target.data);
            loadValues(xml,_valueNode,_valueAttribute);
        }
        
        private function loadValues(xml:XML,valueNode:Object,valueAttribute:String)
        {
            var valueArray:Array = new Array(xml.length());
            valueNode = _valueNode;
            valueAttribute = _valueAttribute;
            
            for(var i = 0; i < xml.length(); i++)
            {
                var valueLoader:Loader = new Loader();
                var requestLocation = xml.valueNode.attribute(valueAttribute)*;
                trace("value of ValueNode: " + valueNode);
                trace("xml length: " + xml.length() + "
i: " + i + "
valueNode: " + valueNode + "
valueAttribute: " + valueAttribute + "
url: " + xml.valueNode.attribute("href")[0]);
                var valueRequest:URLRequest = new URLRequest(requestLocation);
                valueArray* = xml.logo.attribute("href")[0];
                valueLoader.load(valueRequest);
                trace("retrieveXML() >>> " + valueNode + " 1 : " + valueArray*);
            }
        }
    }
}