Difference between revisions of "Actionscript-XML Interaction"
From Wikicliki
(→AS 2.0) |
|||
Line 1: | Line 1: | ||
+ | <pre><box> | ||
+ | <thing> | ||
+ | <name>apple</name> | ||
+ | <colour>red</colour> | ||
+ | </thing> | ||
+ | <thing> | ||
+ | <name>elephant</name> | ||
+ | <colour>gray<colour> | ||
+ | </thing> | ||
+ | </box></pre> | ||
+ | |||
+ | |||
+ | APPLE == this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue; | ||
+ | RED == this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue; | ||
+ | ELEPHANT == this.firstChild.childNodes[1].childNodes[0].firstChild.nodeValue; | ||
+ | GRAY == this.firstChild.childNodes[1].childNodes[1].firstChild.nodeValue; | ||
+ | |||
+ | |||
+ | == Working Example == | ||
+ | |||
loading in the xml | loading in the xml | ||
Revision as of 06:58, 5 June 2009
<box> <thing> <name>apple</name> <colour>red</colour> </thing> <thing> <name>elephant</name> <colour>gray<colour> </thing> </box>
APPLE == this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
RED == this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
ELEPHANT == this.firstChild.childNodes[1].childNodes[0].firstChild.nodeValue;
GRAY == this.firstChild.childNodes[1].childNodes[1].firstChild.nodeValue;
Working Example
loading in the xml
var bannersXML:XML = new XML(); bannersXML.ignoreWhite = true; bannersXML.load("banners3.xml");
xml structure
<rotator isRandom="false"> <bannerTime>5</bannerTime> <numberOfBanners>3</numberOfBanners> <banners showHeader="true"> <banner> <name>Banner 1</name> <body>Lorem Ipsum</body> <imagePath>rotator/newpro1.jpg</imagePath> <bannerTime>3</bannerTime> <link>url</link> </banner> <banner> <name>Banner 2</name> <body>Lorem Ipsum</body> <imagePath>rotator/newpro2.jpg</imagePath> <bannerTime>10</bannerTime> <link>url</link> </banner> </banners> </rotator>
AS 2.0
- firstChild is the next level, childNode of the firstChild is the level below that
- first childnode is childNodes[0]
- second childnode is childNode[1]
- third childnode is childNode[2] you get the idea
for (var i = 0; i<numberOfBanners; i++) { banners.push(this.firstChild.childNodes[2].childNodes[bannerSequence[i]].firstChild.firstChild.toString()); bodyTexts.push(this.firstChild.childNodes[2].childNodes[bannerSequence[i]].childNodes[1].firstChild.nodeValue); imagePaths.push(this.firstChild.childNodes[2].childNodes[bannerSequence[i]].childNodes[2].firstChild.nodeValue); links.push(this.firstChild.childNodes[2].childNodes[bannerSequence[i]].childNodes[3].firstChild.nodeValue); _root.wn.banner_mc3.createEmptyMovieClip("ButtonImage"+i, i+20); eval("ButtonImage"+i).lineStyle(2,0xCCCCCC,20); eval("ButtonImage"+i).beginFill(0xCCCCCC,20); eval("ButtonImage"+i).lineTo(-5,0); eval("ButtonImage"+i).lineTo(-5,20); eval("ButtonImage"+i).lineTo(15,20); eval("ButtonImage"+i).lineTo(15,0); eval("ButtonImage"+i).lineTo(-5,0); eval("ButtonImage"+i).endFill(); eval("ButtonImage"+i)._x = 20+i*24; eval("ButtonImage"+i)._y = 10; _root.wn.banner_mc3.createTextField("ButtonNum"+i, i+10, 0, 3, 20, 20); eval("ButtonNum"+i).text = i+1; var prufont:TextFormat = new TextFormat(); prufont.size = 13; prufont.font = "Arial"; eval("ButtonNum"+i).setTextFormat(prufont); eval("ButtonNum"+i)._x = 20+i*24; eval("ButtonNum"+i)._y = 10; eval("ButtonImage"+i).onRollOver = function() { trace("rolloverbuttonmoon"); myColor = new Color(this); myColor.setRGB(0xff0000, 40); } eval("ButtonImage"+i).onRollOut = function() { trace("rolloverbuttonmoon"); myColor = new Color(this); myColor.setRGB(0xCCCCCC, 20); }