I loaded my xml document and that works perfectly but, I’m trying to find out the names of the attributes in my xml document. Can’t flash do this??
I know there is the .attributes property and it returns an associative array (meaning I need to know the names of the properties). I guess this isn’t a big deal since I am authoring the xml document but, it would be useful to be able to loop through the elements like a normal array. Can this be done?
-z
my code:
XML “slides.xml”:
[AS]
<Slides>
<slideNode jpegURL=“images/image1.jpg”>A sea horse</slideNode>
<slideNode jpegURL=“images/image2.jpg”>Sea anemone</slideNode>
<slideNode jpegURL=“images/image3.jpg”>Sardines!</slideNode>
<slideNode jpegURL=“images/image4.jpg”>Another sea horse</slideNode>
<slideNode jpegURL=“images/image5.jpg”>Some kind of jellyfish</slideNode>
</Slides>
[/AS]
Instead of [AS]trace(slidesXML.firstChild.firstChild.attributes);[/AS] try [AS]trace(slidesXML.firstChild.firstChild.attributes.jpegURL);[/AS] should work. And since you are inside the dynamic event handler for that object, you can change slidesXML to “this” (no quotes)
I could be overlooking something, not sure, but right now the only thing I can think of to be able to do that is to just trace the node itself… [AS]slidesXML.firstChild.firstChild[/AS] … which isn’t exactly useful :whistle:
yeah i was looking for something that would take all the things before the = and retrun them to me in an array. I guess I could build a script that would do that…
like you said though printing out the actual node doesn’t do much good…
here is the script that will return the attributes in an array (as posted it simply prints them out to the debug window) save this code below as slides.xml and you’ll see it working:
function attributeGetter(xmlNode)
{
var searchString:String = xmlNode.toString();
var attrArr:Array = new Array();
var count:Number = 0;
for(i=0; i<searchString.length; i++)
{
var attrStart:Number = new Number();
var attrEnd:Number = new Number();
if (searchString.charAt(i)== “=”)
{
//I found an attribute now we need to get its name
//loop backwards through string and find a space
for (j=i; j>0; j–)
{
if (searchString.charAt(j)== " ")
{
attrStart = j+1;
break;
}
}
attrEnd = i;
//then create an attribute string from = -1 to space +1
//put them in the attr array
attrArr[count] = searchString.substring(attrStart,attrEnd);
count++;
}
}
for(i=0; i<attrArr.length; i++)
{
trace(“attrArr[” +i.toString()+ "] = "+attrArr*);
}
//if you want it to return the attr Array uncomment this…
//return attrArr;
}
[/AS]
oh yeah this is for mx 2004… remove all the strong data typing for it to work in mx…