Difference between revisions of "Actionscript-XML Interaction"
From Wikicliki
(→AS 2.0) |
|||
| Line 99: | Line 99: | ||
} | } | ||
| + | </pre> | ||
| + | |||
| + | |||
| + | == Another Implementation == | ||
| + | |||
| + | <pre> | ||
| + | xmlette = this.firstChild; | ||
| + | total = xmlette.childNodes.length; | ||
| + | image = []; | ||
| + | header = []; | ||
| + | subheader = []; | ||
| + | for (k=0; k<total; k++) { | ||
| + | image[k] = xmlette.childNodes[k].childNodes[0].firstChild.nodeValue; | ||
| + | header[k] = xmlette.childNodes[k].childNodes[1].firstChild.nodeValue; | ||
| + | subheader[k] = xmlette.childNodes[k].childNodes[2].firstChild.nodeValue; | ||
| + | } | ||
| + | |||
| + | a = 0; | ||
| + | aleft = a-1; | ||
| + | aright = a+1; | ||
| + | |||
| + | avalue_txt.text = a; // this for cheking | ||
| + | arightvalue_txt.text = aright; | ||
| + | aleftvalue_txt.text = aleft; | ||
| + | |||
| + | container.loadMovie(image[a], 1); | ||
| + | containerleft.loadMovie(image[aleft], 1); // container for the slide before | ||
| + | containerright.loadMovie(image[aright], 1); // container for the slide after | ||
| + | |||
| + | |||
| + | |||
| + | <slides> | ||
| + | <slide> | ||
| + | <image>swf/filename.swf</image> | ||
| + | <header></header> | ||
| + | <subheader></subheader> | ||
| + | </slide> | ||
| + | </slides> | ||
</pre> | </pre> | ||
Revision as of 10:46, 14 July 2009
<box> <thing> <name>apple</name> <colour>red</colour> </thing> <thing> <name>elephant</name> <colour>gray<colour> </thing> </box>
- APPLE is this.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue;
- RED is this.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue;
- ELEPHANT is this.firstChild.childNodes[1].childNodes[0].firstChild.nodeValue;
- GRAY is 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);
// loop: draw box and print number inside it then repeat and draw the next box on the right of the first box and repeat
_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);
}
Another Implementation
xmlette = this.firstChild;
total = xmlette.childNodes.length;
image = [];
header = [];
subheader = [];
for (k=0; k<total; k++) {
image[k] = xmlette.childNodes[k].childNodes[0].firstChild.nodeValue;
header[k] = xmlette.childNodes[k].childNodes[1].firstChild.nodeValue;
subheader[k] = xmlette.childNodes[k].childNodes[2].firstChild.nodeValue;
}
a = 0;
aleft = a-1;
aright = a+1;
avalue_txt.text = a; // this for cheking
arightvalue_txt.text = aright;
aleftvalue_txt.text = aleft;
container.loadMovie(image[a], 1);
containerleft.loadMovie(image[aleft], 1); // container for the slide before
containerright.loadMovie(image[aright], 1); // container for the slide after
<slides>
<slide>
<image>swf/filename.swf</image>
<header></header>
<subheader></subheader>
</slide>
</slides>