Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Random Xml Node?



My aim is to have a plane coming into the scene from left to right, displaying a message from an xml file, does anyone know how to display a random message, so that when the plane comes back onto the screen after a set time, another message is displayed,

any advice tutorials to help me would be great .

Thanks



KirupaForum > Flash > Flash 8 (and earlier) > Flash MX 2004
Posted on: 12-09-2005, 09:42 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

[AS2]extract 10 Random Node From XML
Hello to everybody, I'm new kirupa user... and as often happens in these cases I have a problem ...

for a quiz I'm writing a script that extract 10 random questions from a fil xml as follows

Code:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<mld_db>
<quest id="1" domanda="blablablablabla1?">
<answer numero="1" risposta="blabla1" valore="1"></answer>
<answer numero="2" risposta="blabla2" valore="0"></answer>
<answer numero="3" risposta="blabla3" valore="0"></answer>
<answer numero="4" risposta="blabla4" valore="0"></answer>
</quest>
<quest id="2" domanda="blablablablabla2?">
<answer numero="1" risposta="blabla21" valore="0"></answer>
<answer numero="2" risposta="blabla22" valore="1"></answer>
<answer numero="3" risposta="blabla23" valore="0"></answer>
<answer numero="4" risposta="blabla24" valore="0"></answer>
</quest>
etc etc...
to create the script I follow that logic:
- create an array that includes all the id of question (total question) on the file xml
- create another array with 10 unique random numbers (1 to total question)
- with an intruction if (array_random [0] == array_id [0]) nested in a loop for control if the first value of dell'array random number corresponds to that of the id of the node, if it corresponds delete both values (arrays.shift) and popultae arrays with the questions, if not shift only the first value of array id questions,

this is the script that I use + or - commented


Code:
System.useCodepage = true;
var idArrTot:Array = new Array();
var idArr:Array = new Array();
var questionArr:Array = new Array();
var randomNum:Array = new Array();

function uni_random_number(maxNumber) {
var i:Number = 1;
var myArray:Array = new Array();
while (myArray.push(i++)<total) {
}
myArray.sort(function (myArray) {
return Math.random()*2-1;
});
return myArray.slice(0, maxNumber);
}
sito = new XML();//load l'xml
sito.ignoreWhite = true;
sito.load("mld_db2.xml");
sito.onLoad = function() {
total = this.firstChild.childNodes.length;//find total question in xml
for (i=0; i<total; i++) {//set the loop for total number question array
idArrTot.push(this.childNodes[0].childNodes[i].attributes.id);
}
randomNum = uni_random_number(10);
randomNum.sort(Array.NUMERIC);
trace(randomNum);
trace("total n° of question = "+total);
trace("++++++++++++++++++");

for (i=0; i<total; i++) {
if (randomNum[0] == idArrTot[0]) {
var id = this.childNodes[0].childNodes[i].attributes.id;
var question = this.childNodes[0].childNodes[i].attributes.domanda;
if (id === undefined){
trace("undefined");
} else {
idArr[i] = id;
questionArr[i] = question;
};
trace("QUESTION n°"+idArr[i]);//content trace
trace(questionArr[i]);
trace("------------------");
trace("");
randomNum.shift();
idArrTot.shift();
trace(randomNum);
} else {
idArrTot.shift();
}
idArr.toString();

}trace(questionArr);
trace(idArr);
};
the problem is that in doing so the loop for insert an undefined value each time that the values did not match ...

attached the xml file and a txt of the output..

Someone can tell me why?

or alternatively on suggest to me an alternative way to proceed ...

I've posted this request also in 3 italian formu but noone can tell me how it happens..

Thanks for attention

m[...]o

Multiple Random Node Selection
I am trying to figure out how to populate a load of dyn text fields with data taken from an external XML file. I can bring in the XML and populate etc... but it random thing that's throwing me.

I know a fair bit about XML and flash, but I'm not clever by any means! Does anyone know of any good sites that might help - or indeed does anybody know the answer!

Gryllsie

Using XFTree: Getting The Parent Node Of Selected Node?
I'm using the XFTree component (great component) and I'm hoping there is a way to return the parent node of whatever node is selected in the tree. Does anyone know.

I can use getSelectedNode() to return the selected node for example, but I can't use: getSelectedNode().ParentNode for instance since the selected node that is returned is no longer attached to its original XML object.

Also, (and this is the larger issue) I really have no idea where the documentation is for this. Is there any? Aside from the list o' methods in the actionscript panel I mean.

Thanks in advance!

Finding A Node In XML File Via Node Attrib?
Hi guys,

I thought this was going to be easy! I would like to search an XML file for a particular data set i.e. set of nodes depending on a passed variable. However, storing a subset of my XML file via
ActionScript Code:
var gallery = this.firstChild;
and then searching 'gallery' as you would an array-using a for()-doesn't work since this.firstChild isn't returning an array . Any ideas?
A sample of my XML and function are below.

Cheers!




Code:
<gallery>
<collection title="Christmas 2004">
<picture title="Tiny Disk" thumb="portfolio_images/thumbs/tinydisk.jpg" description="portfolio_text/tinydisk.txt" image="portfolio_images/tinydisk.jpg"/>
<picture title="Plug" thumb="portfolio_images/thumbs/plug.jpg" description="portfolio_text/plug.txt" image="portfolio_images/plug.jpg"/>
</collection>
<collection title="Christmas 2004">
<picture title="Tiny Disk" thumb="portfolio_images/thumbs/tinydisk.jpg" description="portfolio_text/tinydisk.txt" image="portfolio_images/tinydisk.jpg"/>
<picture title="Plug" thumb="portfolio_images/thumbs/plug.jpg" description="portfolio_text/plug.txt" image="portfolio_images/plug.jpg"/>
</collection>
</gallery>
And the AS function....


ActionScript Code:
function getCollection(collection) {    //set the popup invisble when choosing a new gallery    var gallery_xml = new XML();    gallery_xml.ignoreWhite = true;    gallery_xml.onLoad = function(success) {        if (success) {            trace("XML loaded");            var gallery = this.firstChild            trace("gallery:" +gallery instanceof Array);            for(var i=0; i< gallery.length; i++){                trace("searching for collection...");                //find collection data                if(gallery[i].attributes.title==collection) {                    trace(collection+ " collection found");                    //store collection parent node                    var collection = gallery[i].childNodes;                    collectionInfo.text = collection.attributes.title;                    var totalItems = collection.childNodes.length;                    buildGallery(collection, totalItems);                    break;                } else if(i==gallery.length) {                    trace("Collection not found!");                    galleryInfo.text = "Not found";                    break;                }            }                    } else {            trace("Error loading XML file");        }    };    gallery_xml.load("gallery.xml");}

Node To Node Path Finding
Can anybody help me with this one. I had been looking for a tutorial that will find the shortest path from node to node. I have attached a sample picture to illustrate the problem.

I have created a symbol(dot) and name it pt01,pt02,pt03,pt04,pt05,and pt06. All I want is to find the shortest path from pt01 to pt06 and if ever it find the shortest path, it will draw a line from pt01,pt03,pt05 then pt06.

XML: Add Child Node To Existing Node
Hello all, just trying to get straight how this works.

Say I create some XML like so:

ActionScript Code:
var sample:XML = <sample>
<items>
</items>
</sample>


How would I now add an <item/> to the items elements? I've been trying to use

ActionScript Code:
sample.items.appendChild(<item/>);


but it hasn't seemed to work.

Any ideas? Thanks for reading.

-Dane

XML Element Node Vs Text Node
I have created an application via Flash/AS2 that is basically a form that updates a graphic based on the information given. I have those options saving into an XML file on the local hard drive at the location of the users choice. The problem I'm having is reading that XML file back in from the XML file (this was suppose to the the easy part).

Where I'm getting stuck is the NodeType... all my nodes are being typed as "1 - Element" so I can grab the nodeValue... instead it give me NULL.

My question is... did I code something wrong? is there a way to declare a node type?


ActionScript Code:
//SAMPLE XML
<?xml version='1.0' encoding='UTF-8' ?>
<allflex>
    <tag>
        <act>12345</act>
        <contact_name>Test XML</contact_name>
    <tag>
</allflex>

//ACTTIONSCRIPT 2.0
loadfile.onRelease = function () {
    var feed_xml:XML = new XML();
    feed_xml.ignoreWhite = true;
    feed_xml.onLoad = function(success:Boolean):Void {
        trace("onload...");
        if (success) {
            trace ("success...");
            var thePath_str:String = "/allflex/tag";
            var titleNode_str:Array = XPathAPI.selectNodeList(this.firstChild, thePath_str);
            trace(titleNode_str[0].firstChild.nodeType);

        }else{
            trace("error loading XML");
        }
    };
    feed_xml.load("C://xml.xml");
}

//OUTPUT
onload...
success...
1

This tells me I need to get the NodeType to a 3 - Text Node.

Any Information will be greatly appreciated.

Indexing A Node Below A Parent Node?
My problem: Attached within my node-hierarchies are text that I want to stay behind "sibling" node-hierarchies. Only solution I've found now is to attach the text to the root node, but then they loose their positional/scalar relationship to the node-hierarchies they're part of.


Are anyone aware about a solution to this problem?

What Is The Name Of This Node?
Here is my XML code-


<cellPhoneText>

<downLoadRingToneText>TEXT</downLoadRingToneText>
<ringtoneText>RINGTONE</ringtoneText>
<youHaveSelectedText>YOU HAVE SELECTED:</youHaveSelectedText>
<previewText>PREVIEW</previewText>
<selectYourWirelessCarrierText>
<phone carriers="Carrier"></phone>
<phone carriers="Carrier"></phone>
<phone carriers="Carrier"></phone>
</selectYourWirelessCarrierText>


</cellPhoneText>

I need to know what the name of "selectYourWirelessCarrierText" is so I can call it from my flash file. I also need to know how to call it's childNodes as well.

Can anyone help? I posted this in the XML board as well but noone is on it.

XML Node Name
I attempted to find a previous forum for my problem, but I didn't find anything is explained by I sudden can't obtain the node name from my XML.

First this my XML file

Code:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<FLVCoreCuePoints Version="1">

<CuePoint>
<Time>1932</Time>
<Type>event</Type>
<Name>Marker 02</Name>
<Parameters>
<Parameter>
<Name>bullet</Name>
<Value></Value>
</Parameter>
</Parameters>
</CuePoint>

<CuePoint>
<Time>24544</Time>
<Type>event</Type>
<Name>Marker 01</Name>
<Parameters>
<Parameter>
<Name>bullet</Name>
<Value></Value>
</Parameter>
</Parameters>
</CuePoint>

</FLVCoreCuePoints>


And I want to pull it in and store in an Object/Array. It seemed like an easy assignment when I started, but I can't get the node names and that is an important part. I can't reformat the XML file as it is published by another program, so I need to import as is. Here is my XML Loader class.


Code:
package pageComponents.soundComp
{
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLLoader;
import flash.net.URLRequest;

public class CueXML
{
private var filename:String;
private var xml:XML;
private var xmlList:XMLList;
private var XMLData:Object;

private var tempArr:Array;

public function CueXML(pFilename:String)
{
filename = pFilename;

XMLData = new Object();
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest(filename));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
}

public function xmlLoaded(e:Event):void
{
xml = XML(e.target.data);
var a:int;
var b:int;
xmlList = xml.children();

tempArr = new Array();

for(a=0; a < xmlList.length(); a++)
{
tempArr.push(new Object());
var xmlcue = xmlList[a].children();

for(b=0; b < xmlcue.length(); b++)
{
var xmlChild = xmlcue[b];
trace(xmlChild.node.nodeName);
}

}
}

}


What am I missing, why can't I see the node name?

Samac

Getting An XML Node Into A Var
Hi, I have a datagrid called dg that has data populated to it thru an external XML. What I am trying to achieve is whenever someone clicks on an item in the grid it stores that items coordinates to a variable called locCoordinates. At this moment it is tracing out the coordinates for all of the items in the grid. I just dont know how to go about only getting the selected items coordinates. Any help is appreciated. I attached a sample of my XML and my AS3 code.

Thanks

XML Snippet

Code:
<?xml version="1.0" encoding="UTF-8"?>
<Document>
<Placemark>
<description>Location Name</description>
<LookAt>
<longitude>-80.08228780449664</longitude>
<latitude>26.76333909302779</latitude>
<altitude>0</altitude>
<range>800531.7783723106</range>
<tilt>0.2434603296494301</tilt>
<heading>2.751823574569335</heading>
<altitudeMode>relativeToGround</altitudeMode>
</LookAt>
<styleUrl>#msn_mechanic1</styleUrl>
<Point>
<coordinates>-80.08228780449664,26.76333909302779</coordinates>
</Point>
</Placemark>



AS3 Code

Code:
//Packages
import com.afcomponents.umap.core.UMap;
import com.afcomponents.umap.providers.google.GoogleProvider;
import com.afcomponents.umap.types.LatLng;
import com.afcomponents.umap.overlays.KMLLayer;
import com.afcomponents.umap.styles.MarkerStyle;
import com.afcomponents.umap.styles.GeometryStyle;
import com.afcomponents.umap.display.markermanager.MarkerManager;
import com.afcomponents.umap.display.markermanager.ExpandedGroupPattern;
import com.afcomponents.umap.overlays.Marker;
import com.afcomponents.umap.overlays.Layer;
import com.afcomponents.umap.interfaces.IOverlay;
import com.afcomponents.umap.events.OverlayEvent;
map.addControl(ZoomControl);
map.addControl(MapType);
map.addControl(PositionControl);

//Set Map Provider

var settings:URLRequest = new URLRequest("http://umap.s3.amazonaws.com/assets/xml/GoogleSettings.xml?rand=" + Math.random());
var language:URLRequest = new URLRequest("http://maps.google.com/maps?file=api&v=2");
var copyright:URLRequest = new URLRequest("http://www.afcomponents.com/proxy/g_map_as3/copyright.php");
map.setProvider(new GoogleProvider(false, settings, language, copyright));

//Create Layers - Load KML Points - Center/Set Map Zoom

var theKml:KMLLayer = new KMLLayer();
theKml.load("MarooneServiceCenters.kml");
theKml.addEventListener(Event.COMPLETE, theKmlComplete);
map.addOverlay(theKml);
function theKmlComplete(e:Event):void {
theKml.addEventListener(OverlayEvent.READY, ready);

function ready(event) {

// change icons for loaded markers

var style:Object = {icon:"wrenchmarker.gif"};
applyStyleToMarkers(theKml, style);
}

function applyStyleToMarkers(layer:Layer, style:Object) {

for each (var overlay:IOverlay in layer.getOverlays()) {
if (overlay is Marker) {
overlay.setStyle(style);
} else if (overlay is Layer) {
applyStyleToMarkers(Layer(overlay), style);
}
}
}
map.setCenter(new LatLng(26.210,-80.220),9);
}

var myXML:XML = new XML();
myXML.ignoreWhite = true;
var XML_URL:String = "MarooneServiceCenters.xml";
var myXMLURL:URLRequest = new URLRequest(XML_URL);
var myLoader:URLLoader = new URLLoader(myXMLURL);
myLoader.addEventListener("complete", parseXML);

//Loads Datagrid with Locations

function parseXML(e:Event):void {

myXML = new XML(e.target.data);
for (var i:int = 0; i <myXML.*.length(); i++) {
dg.addItem({Locations:myXML.Placemark.description.text()[i]});
dg.addEventListener(MouseEvent.CLICK, locSelect);
}
//Loads Location Coordinates into Var

function locSelect(e:Event):void {

var locCoordinates = int;
locCoordinates = (myXML.Placemark.Point.coordinates);
trace(locCoordinates);
}
}

Which Node?
<Result><Item>
<Index>a</Index>
</Item> <Item>
<Index>b</Index>
</Item><Item>
<Index>c</Index>
</Item></Result>

myxml = new xml;

How to find the item b's item number. Meaning i want to get the node number 1.

Thanks

XML Node
hey there... long time "reader", first time "poster"

if I have this

Code:
<visiting-team><team-name name="TEAM NAME" alias="TN"/>
<team-city city="CITY"/>
<team-code id="5"/>
<record wins="9" losses="6" ties="0" pct=".600"/></visiting-team>
and this works for me in AS (I didn't post the whole xml file, childNode[9] is <visiting-team>)


Code:
visitingTeam[i] = xmlNode.childNodes[i].childNodes[9].firstChild.attributes["alias"];
is there no way to reference the node by name? i.e.

Code:
visitingTeam[i] = xmlNode.childNodes[i].childNodes["visiting-team"].firstChild.attributes["alias"];
I've tried the above and it does not work... but you see what I mean. Do you HAVE to reference the nodes by number and not name?

Basically.. the problem I'm having is sometimes my <visiting-team> is childNode[9] and sometimes it's childNode[12] (depending on if the game is currently being played or not). So instead of having 'basically' the same code in a few "if" loops.. I was hoping there was a way to get the value by name instead of number.

thanks

Trying To XML Node Value Only If Node Has A Value?
Hi,

I am bringing in values from XML nodes, and in-turn attaching a MovieClip in a loop;

however the ones that are undefined purposely, are still attaching clips

Is there a way to stop this, currently i'm testing with:


Code:
test = DJThumbs[i].childNodes[0].nodeValue
if (test != ""){
trace(test)
}
thanks

How Do You Get The Name Of An XML Node?
I'm looping through an XMLList and I want get the name of the current node that I'm looking at? I can't seem to find a method that does this?

The XML looks something like this:


PHP Code:



<p x="18" y="171"/><p x="18" y="172"/><p x="18" y="173"/><move/><p x="19" y="165"/><p x="20" y="165"/> 




I want to check whether the tag in is a p or a move tag. In AS2 there was the nodeName property. I can't seem to find an equivalent in AS3.

Xml & Add Node
Hello,

I have a xml file MyXML:
<Myxml>
<mytext>ABCD</mytext>
<mytext>EFGH</mytext>
<mytext>IJKL</mytext>
</Myxml>

I want to random and extent the content, but fail, please help. The problem is don't know how to
make a new xml doc from the origin doc.

doc = new XML();
doc.ignoreWhite = true;
doc.onLoad = isLoaded;
doc.load("MyXML.xml");

function isLoaded(success)
{
_l2 = this;
var my_xml = new XML();
var ary = new Array();
for (j = 0; j < 10; ++j) {
for (i = 0; i < _l2.firstChild.childNodes.length; ++i) ary = i;
ary.sort( function() { return random(2)? 1 : -1; });

for (i = 0; i < ary.length; ++i) {
var node = _l2.childNodes.cloneNode(true);
my_xml.appendChild(node);
}
}
}
this = nothing;
this = my_xml;
}

XML Node Value
I'm going after the Yahoo weather and trying to get the value of a XML node

So after I grab the node

item_buildNode.toString() = <lastBuildDate>Tue, 26 Dec 2006 12:51 pm CST</lastBuildDate>

So I know I have the proper node

But I want just the value without the tags

If I try item_buildNode..nodeValue, That returns null

Can I just get the value? If so, how?


Thanks
Mathias

XML Node
Hi all. I changed the sctructure of my XML but i can't load it. I post the 2 methods.

1º - WORK VERSION

HTML Code:
XML
<?xml version="1.0" encoding="UTF-8"?>
<fotos>
<foto fp="img1.jpg" fg="img1.jpg" categoria="img1.jpg"/>
<foto fp="imgs/foto2p.jpg" fg="imgs/foto2g.jpg"categoria="teste2"/>
<foto fp="imgs/foto3p.jpg" fg="imgs/foto3g.jpg"categoria="teste3"/>
<foto fp="imgs/foto1p.jpg" fg="imgs/foto1g.jpg"categoria="teste3"/>
<foto fp="imgs/foto2p.jpg" fg="imgs/foto2g.jpg"categoria="teste3"/>
<foto fp="imgs/foto3p.jpg" fg="imgs/foto3g.jpg"categoria="teste3"/>
<foto fp="imgs/foto1p.jpg" fg="imgs/foto1g.jpg"categoria="teste3"/>
<foto fp="imgs/foto2p.jpg" fg="imgs/foto2g.jpg"categoria="teste3"/>
<foto fp="imgs/foto3p.jpg" fg="imgs/foto3g.jpg"categoria="teste3"/>
<foto fp="imgs/foto1p.jpg" fg="imgs/foto1g.jpg"categoria="teste3"/>
<foto fp="imgs/foto2p.jpg" fg="imgs/foto2g.jpg"categoria="teste3"/>
<foto fp="imgs/foto3p.jpg" fg="imgs/foto3g.jpg"categoria="teste3"/>
</fotos>

FLASH
dados = this.firstChild.childNodes
1º - NOT WORK VERSION

HTML Code:
XML
<?xml version="1.0"?>
<item>
<modelo>
<titulo> CAFETEIRAS</titulo>
<url>imagens/56870.jpg</url>
<url2>cafeteiras.xml</url2>
</modelo>
<modelo>
<titulo> CHALEIRAS</titulo>
<url>imagens/53783.jpg</url>
<url2>chaleiras.xml</url2>
</modelo>
<modelo>
<titulo> TORRADEIRAS</titulo>
<url>imagens/78012.jpg</url>
<url2>torradeiras.xml</url2>
</modelo>
<modelo>
<titulo> LIQUIDIFICADOR</titulo>
<url>imagens/6550.jpg</url>
<url2>liquidificador.xml</url2>
</modelo>
<modelo>
<titulo> PANELAS PARA FOUNDUE</titulo>
<url>imagens/88533.jpg</url>
<url2>fondue.xml</url2>
</modelo>
<modelo>
<titulo> PANELA SLOW COOKER</titulo>
<url>imagens/85146.jpg</url>
<url2>slow.xml</url2>

</modelo>
<modelo>
<titulo> JARRAS TÉRMICAS</titulo>
<url>imagens/5817.jpg</url>
<url2>grelhar.xml</url2>
</modelo>
</item>


FLASH
????? HOW I CAN LOAD IT?!?!?

Anyone Know How To Add New Node To XML With AS
I want to add new node to the current XML file.
It already contain some data and I want to add new node with Flash.
I know how to retrieve the data but don't know how to insert

Xml.contains(<node/>)
Hi,

Can someone explain me how the contains(xml) function works?
Because it always returns false.

I use it like this:

ActionScript Code:
xml.*.contains(<art5/>)


And my xml looks like this:

PHP Code:



<root>
<art5 aa15="05" aa25="372" acd5="" amc5="" abr5="000" aln5="000" apr5="000056,00">
<agr6 a16="05" a26="PBD" an6="1">
<art6 aa16="05" aa26="370" acd6="" amc6="" abr6="000" aln6="000" apr6="000030,00"/>
</agr6>
<agr6 a16="05" a26="PBE" an6="1">
<art6 aa16="05" aa26="369" acd6="" amc6="" abr6="000" aln6="000" apr6="000030,00"/>
<art6 aa16="05" aa26="371" acd6="" amc6="" abr6="000" aln6="000" apr6="000030,00"/>
</agr6>
</art5>
<art5 aa15="05" aa25="373" acd5="" amc5="" abr5="000" aln5="000" apr5="000056,00">
<agr6 a16="05" a26="PBD" an6="1">
<art6 aa16="05" aa26="370" acd6="" amc6="" abr6="000" aln6="000" apr6="000030,00"/>
</agr6>
<agr6 a16="05" a26="PBE" an6="1">
<art6 aa16="05" aa26="369" acd6="" amc6="" abr6="000" aln6="000" apr6="000030,00"/>
<art6 aa16="05" aa26="371" acd6="" amc6="" abr6="000" aln6="000" apr6="000030,00"/>
</agr6>
</art5>
<art5 aa15="05" aa25="374" acd5="" amc5="" abr5="000" aln5="000" apr5="000056,00">
<agr6 a16="05" a26="PBD" an6="1">
<art6 aa16="05" aa26="370" acd6="" amc6="" abr6="000" aln6="000" apr6="000030,00"/>
</agr6>
<agr6 a16="05" a26="PBE" an6="1">
<art6 aa16="05" aa26="369" acd6="" amc6="" abr6="000" aln6="000" apr6="000030,00"/>
<art6 aa16="05" aa26="371" acd6="" amc6="" abr6="000" aln6="000" apr6="000030,00"/>
</agr6>
</art5>
</root> 




Thx!

XML Node Is Set
Is there a simple way to check that a child node with a specific name exists?

I could do that with a for each loop, but I was wondering if there is a simpler way.

Search Through Each (sub)node In XML
I got one more XtreMeLy big problem (to me, that is),

I have XML that should have X number of nodes and childNodes. Each has "id" attribute.
I want to search whole XML file for id, "10" for instance.
Since there is no fixed number of childNodes (for example one parent node, one child node with another childNode), I'm not sure how to search through all of them.

if mainXML is my XML object, I can loop:

for (var nodes=0; nodes < mainXML.childNodes.length; nodes++)

which would return one node (parent node, "family" for instance)
then I can loop through it's childNodes, since there will always be at least one.
But each of these childNodes could have one or more childNodes, which again can have one or more and so on.

So how do I find the right one? The one with correct "id".
heelp!

~Darko aka Witchsmeller

Node Identifier....
Anyone know of an application in which you can load an xml document whereby it gives you a visual display of the node structure. For example, if I loaded in a document that has many, many nodes the display would inform me when I moused over or clicked on a give node that it is a firstChild.firstChild.nextSibling of.... and so on?

Thanks

Node Identifier....
To both learn and to identify the node I am attempting to extract infro from. I know there has to be a better/easier way to get to the info I want the this.firstChild.firstChild.firstChild.firstChild.n extSibling.firstChild and so on.

Thank you,

How Many Attributes Can An XML Node Have?
Hi Guys

I'm reading in attributes of an XML node into my flash movie....

Is there a limit to the number of nodes you can read in?
I ask this, cause I can't read in the third attribute on my node!!

e.g. <level1 id="12" title="hello" desc="why wont this bit show up?"/>

Any ideas?

Cheers

Add New Node To XML With Flash
Anyone pls. help me!
I need to add new record to the XML file.
I already can load the data but can't add into the file.

Can HTML Be In An XML Node?
is it possible to have HTML in XML? I have a piece of xml that looks like this:


Code:
<root>
<entry day="4"month="February"year="2006">This is my text. Here is a <a href=http://website.com ><b>link</b></a>to my website. </entry>
</root>
but when i am bringing it into Flash, it gets hungup and traces:


Code:
<root>
<entry day="4"month="February"year="2006">This is my text. here is a</entry></root>

[F8] Read Xml Node By Name
Hi, I have a dynamic image loader that I would really like to be able to call a node out by name.

Say this is my xml file:

Code:
<?xml version='1.0' encoding="utf-8" ?>
<node1>
<info>blah blah blah</info>
</node1>
<node2>
<info>blah blah blah</info>
</node2>
I want to say something like:
currentNode = myXML["node1"];

Anyone know how to do this?

Remove Xml Node
Hello,
i am using a scroll panel component with an instance name of photoScroll on the stage. This scroll panel is linked to an xml page which contains the names of the thumbnails and the jpgs.
When you click on the thumbnail it loads the corresponding jpg beside the scroll panel. Also on the stage, there is a button which moves the timeline along and also removes the scroll panel. The problem is that the jpg which was loaded remains on the stage. I can't figure out how to get rid of it. I really need help, i've been on this for days!
Here is my code (the jpgs are found in the <data> node of the xml page). "hor" is the button that must remove the scroll panel and the lingering jpg.
thanks!

stop();
import flash.events.MouseEvent;
import com.afcomponents.scrollpanel.ScrollPanelEvent;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.net.navigateToURL;

photoScroll.addEventListener(ScrollPanelEvent.XML_ LOAD_COMPLETE, loadComplete);

function loadComplete(event:ScrollPanelEvent){
photoScroll.addGenericItemEventListener(MouseEvent .CLICK, playOnClick);


}
function playOnClick(event:MouseEvent) {


var imageLoader:Loader = new Loader();
var myRequest:URLRequest = new URLRequest(event.target.data);
imageLoader.load(myRequest);


addChild(imageLoader);
imageLoader.y = 117;
imageLoader.x = 435;

}



hor.buttonMode = true;

hor.addEventListener (MouseEvent.CLICK,funchor);
hor.addEventListener (MouseEvent.CLICK,removeScroll);



function funchor (e:MouseEvent):void
{
gotoAndPlay(currentFrame+1);
addFrameScript (currentFrame+5, skipFrame);

function skipFrame ()
{
gotoAndPlay (29);
}
function removeScroll(event:MouseEvent) {
removeChild(photoScroll);
}

Xml Node Help (galery)
hey guys,

I have been hacking around with this gallery code for a wile and as you can imagine have run into some difficulties. Basically the code will load nodes from a XML file and tile them in sequence onto the stage(1 first, 2 second and so on)

I don't want this to happen I want them to load all at once. so the user will see 1234567 all at the same time. Probably not the clearest explanation but here is what Im working with,


Code:
stop();
//xml load variables
var xmlLoader:URLLoader;
var xmlData:XML;

//xml load function
function loadXml(xmlFile:String):void {
try {
xmlLoader= new URLLoader();
xmlData = new XML;
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, xmlLoadFail);
xmlLoader.load(new URLRequest(xmlFile));

} catch (error:Error) {
//catch errors
trace("error");
}
}
//load the XML file
loadXml("gettingAroundR.xml");

function xmlLoadFail(event:IOErrorEvent):void {
trace("Looks like there was an error loading the XML");
}

//we have our XML data, so lets load the thumbnails
function xmlLoaded(e:Event):void {
xmlData = XML(xmlLoader.data);
loadThumbs();//call the thumbs loading function
}



/*********************************************************************
SET VARS
**********************************************************************/

var p:int = 0;//increment value
var u:int = 0;
var iHit:Boolean = false;//used from thum hit state
var changex:int = 0;//var to track total width of thumb track
var padding:int = 10;//use if you want padding between thumbnails in the scroller
var pictureValue:int = 0;//dynamic var used to track position in XML data array
//var for empty movieClip that hold our thumbs
var child:MovieClip;


//generic empty loader objects
var loader:Loader;
var thumbLoader:Loader;
//Sprite holder for content to load into
var largeContent:Sprite = new Sprite;

var targetThumbs:int;



/*********************************************************************
LOAD THUMBNAILS
**********************************************************************/
function loadThumbs():void {
thumbLoader = new Loader();
thumbLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadThumbProgress);
thumbLoader.contentLoaderInfo.addEventListener(Event.INIT, thumbLoaded);
//thumbLoader.load(new URLRequest(String(xmlData.pic.thumb[p])));//access the thumbnails
thumbLoader.load(new URLRequest(String(xmlData.pic.thumb[p])));

p++;//increment through the thumbnails array
u++
}
//progresshandler for thumbs loading.
function loadThumbProgress(e:ProgressEvent):void {
//trace("LOADED "+Math.floor(e.bytesLoaded / 1024)+ " OF "+Math.floor(e.bytesTotal/1024));
}

//we have access to our clips properties, so lets add it to the thumbs scroller
function thumbLoaded(event:Event):void {

if (pictureValue==0) {

constructScroller();//call the scroller constructor function

}
trace("sdfsdfsdf");
var mythumbHolder = new (getDefinitionByName("thumbRoom1_mc") as Class);
mythumbHolder.x =0;
mythumbHolder.y =50;

mythumbHolder.container.pictureValue = pictureValue++;

mythumbHolder.urlBTN.urlNum = xmlData.pic.url[u-1];
child = new MovieClip();

mythumbHolder.container.addChild(thumbLoader.content);
child.addChild(mythumbHolder);

//TEXT LOADS HERE
mythumbHolder.roomLable.htmlText = String(xmlData.pic.content[mythumbHolder.container.pictureValue]);
var h:Number = mythumbHolder.roomLable.height;
trace(mythumbHolder.roomLable.height);

holder_mc.addChild(child);

///DEFINE HEIGHT

mythumbHolder.roomLable.autoSize = TextFieldAutoSize.LEFT;

mythumbHolder.tipBG.height = mythumbHolder.roomLable.height +20;
trace("mythumbHolder.tipBG.height = "+mythumbHolder.tipBG.height)

mythumbHolder.urlBTN.y = mythumbHolder.tipBG.height/2;
mythumbHolder.clipBTN.y = mythumbHolder.tipBG.height/2;
///
child.y =changex;//set the x pos of the thumb to the changex var
changex = changex+mythumbHolder.height+padding ;

thumbLoad_txt.text = "LOADED "+p +" OF "+(xmlData.pic.length ())+" THUMBNAILS";
if (p<xmlData.pic.length()) {
loadThumbs();//create loop
}
if (p==xmlData.pic.length()) {

//clear the loading thumbs text
thumbLoad_txt.text = "";
}
}

//define the scrollable area
var scrollPaneX:int;//populated in thumbs init load handler
var scrollPaneY:int;//populated in thumbs init load handler
//var scrollPaneWidth:int;//populated in thumbs init load handler
//var scrollPaneHeight:int;//populated in thumbs init load handler
//var scrollTrackWidth:int;//populated in thumbs init load handler
//scroller variables

var holder_mc:Sprite = new Sprite();//thumbs load into
addChild(holder_mc);

var thumbTrackBg_mc:Sprite = new Sprite();

function constructScroller():void {
//position thumbs scroller inline with pre set vars
x = scrollPaneX;
y = scrollPaneY;

}

function addScrollListeners():void {


}
Any help would be great guys thanks again.

XML Node Tool
I (and I think not only I) have problem to find the right node if I work with Flash.
Exist any tool, which can identify the node position?
Something similar like debugger in Flash.
Simple XML parser which display the node position in XML tree.
Thanks

XML> Select A Node?
Hi,

I got a simple XML document:

Code:
<slideshow>

<slide>
<url>images/DSCF0007.jpg</url>
<duration>5</duration>

</slide>

<slide>
<url>images/DSCF0010.jpg</url>
<duration>8</duration>
</slide>

</slideshow>
And this code, which outputs the value in the <url> tags:


Code:
for (var n = 0; n<xmlDoc_xml.firstChild.childNodes.length; n++) {
trace(xmlDoc_xml.firstChild.childNodes[n].firstChild.firstChild.nodeValue);
}
Does anyone knows how i can ouput the value of the 2nd node: <duration>?

Best regards,

Vic.

XML Node Values
I'm trying to load node values of an xml doc into variables.

It seems to be kind of working, but it's loading the variables as XML data.

If I use toString() I get strings, even when I want them to be integers.

What am I doing wrong?


Code:
ssp_xml = new XML();
ssp_xml.ignoreWhite = true;
ssp_xml.onLoad = function(sucess) {
if (sucess) {
processSSP(ssp_xml);
}
};
ssp_xml.load('config.xml');
function processSSP(xmlDoc_xml) {
for (i in xmlDoc_xml.firstChild.childNodes) {
set("_root._"+xmlDoc_xml.firstChild.childNodes[i].nodeName, int(xmlDoc_xml.firstChild.childNodes[i].firstChild.nodeValue));
}
}
And here is the xml file.


Code:
<ssp_config>
<_height>500</_height>
<_width>300</_width>
<activeColor>FF6600</activeColor>
</ssp_config>
As you can see, activeColor should be a string, and _height and width I want to be integers.

Attributes Of A Node
Hi

Is there a way to trace all the attributes of a childnode after loading it to flash?

Thanks

Xml Node Problem
Hello everyone

I have an xml file who is:
//////////////////////////////////
<?xml version="1.0"?>
<index_tools>
<news>news_01
<valeur01>valeur 01</valeur01>
</news>
<news_02>news_02
<valeur02>valeur 02</valeur02>
<valeur03>valeur 03</valeur03>
</news_02>
</index_tools>
/////////////////////////////////////

of course I'm trying to read the values it works fine with things like :
var xmlData_xml : XML = this.firstChild.childNodes wich reads my XML file.

then if I do :

var index_text : String = xmlData_xml [1].firstChild.nodeValue;
I get news_02 as a result (fine)

so what I dont get is how I can read:
valeur 02 and valeur 03

attached the zip file

Thank you

T.

XML Node Navigation
I am trying to pull some information from the Yahoo Weather RSS Feed.

I am stuck on how to get further down into the XML to pull the information from a particular node in the XML.

Here is the XML

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
- <rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
- <channel>
<title>Yahoo! Weather - Pensacola, FL</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Pensacola__FL/*http://weather.yahoo.com/forecast/USFL0399_f.html</link>
<description>Yahoo! Weather for Pensacola, FL</description>
<language>en-us</language>
<lastBuildDate>Sun, 25 Mar 2007 10:53 pm CDT</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Pensacola" region="FL" country="US" />
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph" />
<yweather:wind chill="67" direction="0" speed="0" />
<yweather:atmosphere humidity="76" visibility="1609" pressure="30.22" rising="0" />
<yweather:astronomy sunrise="6:47 am" sunset="7:03 pm" />
- <image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com/</link>
<url>http://l.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>
</image>
- <item>
<title>Conditions for Pensacola, FL at 10:53 pm CDT</title>
<geo:lat>30.47</geo:lat>
<geo:long>-87.18</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Pensacola__FL/*http://weather.yahoo.com/forecast/USFL0399_f.html</link>
<pubDate>Sun, 25 Mar 2007 10:53 pm CDT</pubDate>
<yweather:condition text="Fair" code="33" temp="67" date="Sun, 25 Mar 2007 10:53 pm CDT" />
- <description>
- <![CDATA[
<img src="http://l.yimg.com/us.yimg.com/i/us/we/52/33.gif" /><br />
<b>Current Conditions:</b><br />
Fair, 67 F<BR /><BR />
<b>Forecast:</b><BR />
Sun - Foggy. High: 84 Low: 59<br />
Mon - AM Fog/PM Sun. High: 79 Low: 61<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Pensacola__FL/*http://weather.yahoo.com/forecast/USFL0399_f.html">Full Forecast at Yahoo! Weather</a><BR/>
(provided by The Weather Channel)<br/>


]]>
</description>
<yweather:forecast day="Sun" date="25 Mar 2007" low="59" high="84" text="Foggy" code="20" />
<yweather:forecast day="Mon" date="26 Mar 2007" low="61" high="79" text="AM Fog/PM Sun" code="20" />
<guid isPermaLink="false">USFL0399_2007_03_25_22_53_CDT</guid>
</item>
</channel>
</rss>
- <!-- p2.weather.dcn.yahoo.com compressed/chunked Sun Mar 25 21:13:47 PDT 2007
-->

I am trying to pull the <yweather:condition text="Fair" code="33" temp="67" date="Sun, 25 Mar 2007 10:53 pm CDT" /> out so I can show this information....any help would be greatly appreciated.

XML Question: Get Node By Name
Hey there,

i have been looking through the net but figured out that it's probably not possible. i want to look for a XML childnode by calling its name with the result that the order of the XML file doesnt change the whole flash thing

so instead of myXML.firstChild.childNodes[0] for example
i want to say myXML.pictures.childNodes[0] if that makes sence

thanks in advance

How Do You Change The XML Node Name?
trace(obj.reference_xml.nodeName);
obj.reference_xml.nodeName = "newNodeName";
trace(obj.reference_xml.nodeName);

nodeName is probabely read only so if that is the case, it makes sense that this would not work. Does anyone know how to change the name of an arbitrary node with out effecting its attributes and children?

Inserting An XML Node Into XML
If I have an XML variable holding some info, how do I insert a new node with contents and values determined by variables?

Say I have something like:

ActionScript Code:
var myXML:XML = <folder>
<file id="3">Content of file 3</file>
</folder>

and I want to be able to go:

ActionScript Code:
count=4;
textContent='Content of newly added file';
myXML.addNode('<file id="'+count+'">'+textContent+'</file>');

and then this will be the new value of myXML.

ActionScript Code:
<folder>
<file id="3">Content of file 3</file>
<file id="4">Content of newly added file</file>
</folder>

XML Node And Casting To Int
Just came across a strange behaviour in my Flex app when casting a xml node value to int.


Code:

//The attibute is set to '2'

var selectedCodeId:int = int(selectedFilterTreeNode.@codeId); //gave 2

var selectedCodeId:int = selectedFilterTreeNode.@codeId as int; //gave 0
Anyone seen this before?

Trace Xml Node...
Hi everyone,

Im trying to trace an xml line but all I get is a blank trace :P


Code:
var testXML:XML =
<test>
<test1 col1="test1A" col2="test2A" col3="test3A"/>
<test1 col1="test1B" col2="test2B" col3="test3B"/>
<test1 col1="test1C" col2="test2C" col3="test3C"/>
<test1 col1="test1D" col2="test2D" col3="test3D"/>
</test>

trace(testXML.test1[0]); //empty line...
If I trace the "testXML.test01[0].attributtes()" i can see its attributes, but I want to get the whole xml line not just the attributes.
Can anyone help me out on this one?

cheers

Help Looping To The Next XML Node
I'm trying to display the data from the XML document. I was wondering if anyone could assist me on this topic.

I can loop through until I get to the count=1 node, but once I get there, I can't go to the count=2, count=3, etc.

If there's anyone who could tell me what's wrong with the code, I would greatly appreciate it.

This is the XML file I've made:

<segment id="15" type="1">
<course>
<courseid>1</courseid>
<courseabbr>math101</courseabbr>
<coursename>Math 101</coursename>
</course>
<segmentinfo>
<name>number 4</name>
<description>testing</description>
<movie>516197583.swf</movie>
</segmentinfo>
<position id="1">
<count="1">
<type>1</type>
<information>sfgsdfgfgfg</information>
<endtime>12</endtime>
</count>
<count="2">
<type>1</type>
<information>asdfadsfadsfasdf</information>
<endtime>30</endtime>
</count>
<count="3">
<type>2</type>
<information>219839299219839299.TTF</information>
<endtime>62</endtime>
</count>
<count="4">
<type>4</type>
<information>1724091206.xul</information>
<endtime>75</endtime>
</count>
<count="5">
<type>3</type>
<information>547868100.swf</information>
<endtime>100</endtime>
</count>
<count="6">
<type>1</type>
<information>afgsfsdfasdfasdfasdfasdf</information>
<endtime>155</endtime>
</count>
<count="7">
<type>1</type>
<information>asdfasdfasdfasdfasdfasf</information>
<endtime>195</endtime>
</count>
<count="8">
<type>1</type>
<information>adfasdfasdsfasdf</information>
<endtime>220</endtime>
</count>
</position>
</segment>

I've loaded the XML file in my main and called loadXML function:
<as>
function loadXML(xml){
promos = [];
level3C = xml.firstChild.firstChild.nextSibling.nextSibling;
for(var i = 0; i<level3C.firstChild.childNodes.length; i++)
{
trace(level3C.firstChild.childNodes[i]);
if(level3C.firstChild.childNodes[i].nodeName=="type")
{
myObj = {};
//trace("winner");
for(var j=0; j<level3C.firstChild.childNode[i].childNodes.length;j++)
{
myObj[level3C.firstChild.childNodes[i].childNodes[j].nodeName]=level3C.childNodes[i].childNodes[j].firstChild.nodeValue;
trace(level3C.firstChild.childNodes[i].childNodes[j].nodeValue);
}
promos.push(myObj);
}
}

}
</as>


chris


Appreciation rules the Nation

XML Node Name Referencing
Hello all

I'm just starting to play with XML in Flash. I've managed to load in an xml file into an xml object and assign values from the XML to variables (displayed in dynamic text boxes at the moment).

I'm fairly new to this, and at the moment I've been referencing the attributes using firstChild.

MyVar = LoadedXML.firstChild.firstChild.firstChild.firstCh ild.nodeValue;

However this could get very messy once the XML becomes more complex. Is there a way of referencing the tags in the XML? Something similar to:

MyVar = LoadedXML.tagName1.nextTag.joeBloggs.whatever.node Value;

TIA

Node Gardens
Hi i've been mucking around with the node gardens from bit-101.com and i wanted to recreate the screensaver that comes with windows called 'Mystify' even though it goes too insanely fast on my computer i remember what it used to be with good ol' windows 3.1! Anyway heres the code for my node garden, i'm not sure how to clean it up a bit, i have too many for loops but my problem is the nodes from the second ring don't sit ontop of the first


PHP Code:



//the second ring (green) seems to be superimposed
//on top of the red for about 1/4 a second
//i'm curious as to why, can neone
//help me
numberInPattern = 4;
setsOfNodes = 2;
numNodes = numberInPattern*setsOfNodes;
nodez = [];
for (i=1; i<((numNodes/2)+1); i++) {
    node = attachMovie("node", "n"+i, i);
    nodez[i] = node;
    node._x = Math.random()*550;
    node._y = Math.random()*400;
    //thought math round might solve my problem
    //but alas!
    node.vx = Math.round(Math.random()*10-5);
    node.vy = Math.round(Math.random()*10-5);
    node.onEnterFrame = nodeMove;
}
//second square
for (i=5; i<(numNodes+1); i++) {
    node = attachMovie("node", "n"+i, i);
    nodez[i] = node;
    //during testing just have _x but after will 
    //have _x + 10, _y+10 so that the points
    //aren't just superimposed on each other
    //which they should be!
    node._x = nodez[(i-numberInPattern)]._x;
    node._y = nodez[(i-numberInPattern)]._y;
    //this *should* make the node follow the one
    //four before it. ie. number 5 will follow
    //number one around, if it has same init velocity
    //and has same start position
    //and also follows function nodeMove why not?!?
    node.vx = nodez[(i-numberInPattern)].vx;
    node.vy = nodez[(i-numberInPattern)].vx;
    node.onEnterFrame = nodeMove;
}
_root.onEnterFrame = function() {
    var i, nodeA, nodeB;
    clear();
    for (i=1; i<(nodez.length/2); i++) {
        nodeA = nodez[i];
        if (i<(nodez.length/2)-1) {
            nodeB = nodez[(i+1)];
        } else {
            nodeB = nodez[1];
        }
        //red
        lineStyle(1, 0xff0000);
        moveTo(nodeA._x, nodeA._y);
        lineTo(nodeB._x, nodeB._y);
    }
    for (i=5; i<(numNodes+1); i++) {
        nodeA = nodez[i];
        if (i<nodez.length-1) {
            nodeB = nodez[(i+1)];
        } else {
            nodeB = nodez[5];
        }
        //green
        lineStyle(1, 0x006600);
        moveTo(nodeA._x, nodeA._y);
        lineTo(nodeB._x, nodeB._y);
    }
};
function nodeMove() {
    this._x += this.vx;
    this._y += this.vy;
    if (this._x>550) {
        this._x = 550;
        this.vx *= -1;
    }
    if (this._x<0) {
        this._x = 0;
        this.vx *= -1;
    }
    if (this._y>400) {
        this._y = 400;
        this.vy *= -1;
    }
    if (this._y<0) {
        this._y = 0;
        this.vy *= -1;
    }





and i'm not sure why. Obviously its something to do with node.vx = nodez[(i-numberInPattern)].vx; but i'm not sure how else to do it! In case you've never seen a node garden before and have no clue as to what i'm talking about i attached a fla. Thanks in advance Reuben

Undefined Node
I have an xml document set up like this example.

Code:
<imageNode jpegUrl="arc/culImages/pic_5.jpg">
<title>Place title here</title>
<description>This is just for test.</description>
</imageNode>
The problem is there are going to be some that don't require a description how do I do this.
Right now if I leave the description node blank it shows up as undefined in my textfield.


How can I do this.

Apply Css To Different Node
hello..

how do I apply the css to different nodes in the xml data? I have attached the file for you to take a look at. thank you.

XML Node Values
I am attempting to parse the values of several XML nodes. The code I am using is similar to that listed below:

1) var childItems:Array = current_xml.firstChild.childNodes;
2) my_txt.text += childItems[2].firstChild.firstChild.nodeValue + "
";
3) my_txt.text += childItems[2].firstChild.childNodes[1].nodeName;

Line 2 will give the correct node value, but line 3 will give me an undefined value. I tried this with several nodes, but all give the the same result. Only the first child will parse correctly. The XML file is formatted correctly, so what else can be the issue?

XML Node Has One Child?
Hey guys,

I have a recursive function that search through an XML document and finds each node, whether it has children, etc. When it comes across a block like the following:

<mainitem submenu="true" name="File">
<item submenu="false">Option 1</item>
<item submenu="false">Option 2</item>
<item submenu="false">Option 3</item>
<item submenu="false">Option 4or</item>
<item submenu="false">Option 5</item>
</mainitem>

It correctly states that the first node, "File," has 5 children. But when it recurses to the child nodes it states that each node has 1 child. I am using children().length() to check for number of children....below is my function:

private function parseMenuData(menuData:XML):void{

for each(var menuItem:XML in menuData.elements()){

trace("-----------------------------------------------------------");
trace("Menuitem " + menuItem.@name + "has " + menuItem.children().length() + " children.");

if(menuItem.children().length() > 0){
parseMenuData(menuItem);
}else{
trace("No children here");
}

//parseMenuChildren(menuItem);

}
}

Thanks in advance!

HTML In An XML Node
I know I'm missing something basic here. If I have a simple XML document and it contains html that will be displayed in a html textfield (see code snippet) how do you get around the fact that the a tag is seen as a node? So if I'm using something like firstChild.childNodes[0].nodeValue - how can I get this to include the html tag? Do I have to indicate that the node is something other than text, is there such a things as a html node? Or do I have to excape somehow? Thanks.








Attach Code

<something><a href="#">click here</a></something>

Copyright © 2005-08 www.BigResource.com, All rights reserved