FORUMS: list search recent posts

xml nodes for AS2

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Crystal Shannon
xml nodes for AS2
on Nov 25, 2009 at 12:05:52 pm

I am adding dynamic links to exsisting movieclips in AS2 Flash.
Here is my code, and here is my XML. I am pulling the link from the trace in the output window, but I cannot get the getURL to pull the link. I'm getting an "undefined". Any help would GREATLY be appreciated!!!

iconlinks_xml = new XML();

// load data from an external XML file into "my_xml" object

iconlinks_xml.ignoreWhite = true;
iconlinks_xml.onLoad = function() {
var parent = this.firstChild
var nodes = parent.childNodes;
numOfItems = nodes.length;
trace (iconlinks_xml.firstChild.childNodes[0]


icon link="" /
icon link="" /
icon link="" /

I'm leaving off the brackets from the XML code because the forum will not accept them.


on (release) {
getURL(iconlinks_xml.firstChild.childNodes[0], "_self")


Return to posts index

Mike Smith
Re: xml nodes for AS2
on Nov 25, 2009 at 4:39:05 pm

xml does need a little care, and no less in Flash!
I redid your xml like this:
<?xml version="1.0" ?>
<!DOCTYPE vidload[
<!ELEMENT icons (icon)>

<icon myaddress=" 1" />
<icon myaddress=" 2" />
<icon myaddress=" 3" />

and then your actionscript as below, to create an array and populate the array with the data wanted from the xml. Then your undefined error should go away ..

// path to xml file
var myXmlPath = "links.xml";
// trace ("hi mike");
// set up our xml object
XML.prototype.ignoreWhite = true;
var iconlinks_xml:XML = new XML();
// array, to hold url values
var myUrls:Array = new Array();
iconlinks_xml.onLoad = function(success:Boolean) {
if (success) {
// trace("ok");
numberofclips = iconlinks_xml.firstChild.childNodes.length;
// trace(numberofclips);
for (i=0; i<iconlinks_xml.firstChild.childNodes.length; i++) {
delete this;
// this deletes the xml object, freeing some memory

} else {
trace("failed to load ...");
/* you now have an array named myUrls with your various urls at positions addressable with the [] syntax!

Return to posts index

Crystal Shannon
Re: xml nodes for AS2
on Nov 25, 2009 at 5:19:21 pm

thank you so much for your response and work. I'm quiet new to xml... I know how to put it together in AS3, but this project was made in AS2 and it's like a different world.

Anyhow, I plugged in all the information you provided. I guess I'm wondering how I call the different links. I'm so sorry for the newbie question, but am I keeping the on (release) function the same... just add it to all my movieclips and change the number for the link? I guess I was getting confused with the array part. I'm not sure why flash makes it so difficult just to call a link... and why I need an array. :s

Thank you so very much!!!

Return to posts index

Crystal Shannon
Re: xml nodes for AS2
on Nov 25, 2009 at 5:40:39 pm

holy cow :P I figured it out. I was calling the onRelease function by the actual movieclip name INSTEAD of the instance name. DUH. Anyhow, thanks for your work... I know wonder if it would've worked how I had it set up prior. Non-the-less, the code is much much cleaner now. :D :D

I ended up removing the on (release) function from the movieclip and added it inside the function.. so it looks like so...

numberofclips = iconlinks_xml.firstChild.childNodes.length;
e0_mc.btn.onRelease = function() {
getURL(iconlinks_xml.firstChild.childNodes[0].attributes.myaddress, "_self");

Thanks a mill

Return to posts index

Mike Smith
Re: xml nodes for AS2
on Nov 25, 2009 at 6:06:37 pm

Good that it's working!

Now you have the myUrls array, you could change your functions to e.g.

e0_mc0.onRelease = function() {
e0_mc1.onRelease = function() {
e0_mc2.onRelease = function() {

if you wanted to.

I think the problem initially was more that the data wasn't getting out from the xml and into your object in a useful way so when you tried to trace or call the data you got the undefined message.

So moving the load xml to later in the script, cleaning up the xml to use the attributes identifier, and loading the xml into an array for easier addressing were just steps to make sure that we could call the xml data successfully - from the getUrl function.

Whatever, glad it's working now!

Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2018 All Rights Reserved