Difference between revisions of "Actionscript-XML Interaction"
From Wikicliki
| Line 137: | Line 137: | ||
</slide> | </slide> | ||
</slides> | </slides> | ||
| + | </pre> | ||
| + | |||
| + | |||
| + | == One More == | ||
| + | |||
| + | with thanks to Kun: | ||
| + | |||
| + | <pre> | ||
| + | |||
| + | function readysteadygoforKun2(fileNum,newballNumber){ | ||
| + | //trace("READY KUN!") | ||
| + | momo.enabled = false; | ||
| + | itHasMoved = 1; | ||
| + | subHeader._visible = 1; | ||
| + | currentLoaded_txt._visible = 1; | ||
| + | destinoXML = new XML(); | ||
| + | destinoXML.ignoreWhite = true; | ||
| + | destinoXML.onLoad = function(){ | ||
| + | //trace("XML LOADED"); | ||
| + | loadXMLKun(fileNum); | ||
| + | } | ||
| + | var xmlFileName = "cat"+newballNumber+".xml"; | ||
| + | loadedFile = "cat"+newballNumber; | ||
| + | //trace("xmlFileName: "+xmlFileName); | ||
| + | destinoXML.load(xmlFileName); | ||
| + | //trace("DONE"); | ||
| + | pChecker(); | ||
| + | } | ||
| + | |||
| + | function loadXMLKun(fileNum) { | ||
| + | xmlNode = destinoXML.firstChild; | ||
| + | //trace("xmlNode: "+destinoXML) | ||
| + | image = []; | ||
| + | header = []; | ||
| + | subheader = []; | ||
| + | total = xmlNode.childNodes.length; | ||
| + | for (k=0; k<total; k++) { | ||
| + | image[k] = xmlNode.childNodes[k].childNodes[0].firstChild.nodeValue; | ||
| + | header[k] = xmlNode.childNodes[k].childNodes[1].firstChild.nodeValue; | ||
| + | subheader[k] = xmlNode.childNodes[k].childNodes[2].firstChild.nodeValue; | ||
| + | } | ||
| + | ptotal_txt.text = total; | ||
| + | loadSectionKun(fileNum); | ||
| + | pChecker(); | ||
| + | } | ||
| + | |||
| + | function loadSectionKun(fileNum){ | ||
| + | p = fileNum; | ||
| + | pleft = p+1; | ||
| + | pvalue_txt.text = p; | ||
| + | pleftvalue_txt.text = pleft; | ||
| + | |||
| + | container._alpha = 0; | ||
| + | trace("fileNum: "+fileNum) | ||
| + | cat_txt.text = fileNum; | ||
| + | trace("image[fileNum]: "+image[fileNum]) | ||
| + | container.loadMovie(image[fileNum],1); | ||
| + | |||
| + | Header.text = header[fileNum]; | ||
| + | subHeader.text = subheader[fileNum]; | ||
| + | content_txt.text = image[fileNum]; | ||
| + | pChecker(); | ||
| + | } | ||
| + | |||
</pre> | </pre> | ||
Revision as of 00:58, 13 August 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>
One More
with thanks to Kun:
function readysteadygoforKun2(fileNum,newballNumber){
//trace("READY KUN!")
momo.enabled = false;
itHasMoved = 1;
subHeader._visible = 1;
currentLoaded_txt._visible = 1;
destinoXML = new XML();
destinoXML.ignoreWhite = true;
destinoXML.onLoad = function(){
//trace("XML LOADED");
loadXMLKun(fileNum);
}
var xmlFileName = "cat"+newballNumber+".xml";
loadedFile = "cat"+newballNumber;
//trace("xmlFileName: "+xmlFileName);
destinoXML.load(xmlFileName);
//trace("DONE");
pChecker();
}
function loadXMLKun(fileNum) {
xmlNode = destinoXML.firstChild;
//trace("xmlNode: "+destinoXML)
image = [];
header = [];
subheader = [];
total = xmlNode.childNodes.length;
for (k=0; k<total; k++) {
image[k] = xmlNode.childNodes[k].childNodes[0].firstChild.nodeValue;
header[k] = xmlNode.childNodes[k].childNodes[1].firstChild.nodeValue;
subheader[k] = xmlNode.childNodes[k].childNodes[2].firstChild.nodeValue;
}
ptotal_txt.text = total;
loadSectionKun(fileNum);
pChecker();
}
function loadSectionKun(fileNum){
p = fileNum;
pleft = p+1;
pvalue_txt.text = p;
pleftvalue_txt.text = pleft;
container._alpha = 0;
trace("fileNum: "+fileNum)
cat_txt.text = fileNum;
trace("image[fileNum]: "+image[fileNum])
container.loadMovie(image[fileNum],1);
Header.text = header[fileNum];
subHeader.text = subheader[fileNum];
content_txt.text = image[fileNum];
pChecker();
}