Loading from XML

This is just an example of what can be done with loading from an xml file.

buy cialis
buy zovirax online
buy doxycycline today
buy generic zocor
buy cipro generic
buy zoloft drugs
buy cheap keflex
buy ampicillin
buy acomplia online
buy valtrex today
buy zithromax
buy ultram
buy cialis
buy prilosec

The xml code needs to go in the same directory and needs to have the same name as the swf, ie. loadXML.xml loadXML.swf

<?xml version="1.0" encoding="iso-8859-1"?>
<xml>
<imagesDepth>1</imagesDepth>
<textsDepth>0</textsDepth>
<textField x="50" y="0" width="100" height="50">This is being loaded from an xml file</textField>
<image x="50" y="100" width="50" height="50">http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif</image>
<textField x="6" y="8" width="100" height="50">I can position and resize this text to any size.</textField>
</xml>

And this code needs to go on the first frame in the root of the movie
function findXML(string) {
var num1:Number = string.lastIndexOf("/");
var num2:Number = string.lastIndexOf(".swf")+4;
var string2:String = string.substr(num1+1, num2-5-num1);
var string3:String = string.slice(num1, num2);
var array:Array = string.split(string3);
array[1] = string2;
return (array);
}

function loadXML() {
var array:Array = findXML(_root._url);
var xml:XML = new XML();
xml.onLoad = function(success) {
if (success == true) {
trace(”Loading of “+array[0]+”/”+array[1]+”.xml”+” succeeded”);
parseXML(this);
} else {
trace(”Loading of “+array[0]+”/”+array[1]+”.xml”+” failed”);
}
};
xml.ignoreWhite = true;
xml.load(array[0]+”/”+array[1]+”.xml”);
}
function parseXML(xml) {
var xmlChild:XML = xml.firstChild;
var xmlChildChild:XMLNode = xml.firstChild.firstChild;
var xmlChildChildChild:XMLNode = xml.firstChild.firstChild.firstChild;
imageA = new Array();
imageX = new Array();
imageY = new Array();
imageW = new Array();
imageH = new Array();
textA = new Array();
textX = new Array();
textY = new Array();
textW = new Array();
textH = new Array();
for (j=0; j<1000; j++) {
//trace(”RSS”+newline+xmlChildChildChild.nodeName.toUpperCase() )
if (xmlChildChild.nodeName == undefined) {
break;
}
trace(xmlChildChild.nodeName.toUpperCase());
if (xmlChildChild.nodeName.toUpperCase() == “IMAGESDEPTH”) {
imagesDepth = Number(String(xmlChildChild.firstChild));
}
if (xmlChildChild.nodeName.toUpperCase() == “TEXTSDEPTH”) {
textsDepth = Number(String(xmlChildChild.firstChild));
}
if (xmlChildChild.nodeName.toUpperCase() == “IMAGE”) {
imageA.push(String(xmlChildChild.firstChild));
imageX.push(xmlChildChild.attributes.x);
imageY.push(xmlChildChild.attributes.y);
imageW.push(xmlChildChild.attributes.width);
imageH.push(xmlChildChild.attributes.height);
}
if (xmlChildChild.nodeName.toUpperCase() == “TEXTFIELD”) {
textA.push(xmlChildChild.firstChild);
textX.push(xmlChildChild.attributes.x);
textY.push(xmlChildChild.attributes.y);
textW.push(xmlChildChild.attributes.width);
textH.push(xmlChildChild.attributes.height);
}
xmlChildChild = xmlChildChild.nextSibling;
}
trace(imageA);
initXML();
}
function initXML() {
texts();
images();
}
function images() {
loaded = 0;
_root.createEmptyMovieClip(”Images”,imagesDepth);
var imageLoader:MovieClipLoader = new MovieClipLoader();
var loadListener:Object = new Object();
imageLoader.addListener(loadListener);
loadListener.onLoadInit = function(mc) {
loaded++;
trace (mc.getDepth()-1)
mc._x = imageX[mc.getDepth()-1];
mc._y = imagetY[mc.getDepth()-1];
mc._width = imageW[mc.getDepth()-1];
mc._height = imageH[mc.getDepth()-1];
if (loaded == imageA.length) {
trace(”done”);
}
};
for (i=0; i<1000; i++) {
imageLoader.loadClip(imageA[i],Images);
}
}
function texts() {
_root.createEmptyMovieClip(”Text”,textsDepth);
for (i=0; i<textA.length; i++) {
var txt:TextField = _root.Text.createTextField(String(”text”+i), i, textX[i], textY[i], textW[i], textH[i]);
txt.text = textA[i];
trace (”text”+i)
trace(txt.text)
}
}
loadXML();

Click here to download sample Files

2 Responses to “Loading from XML”

  1. bey Says:

    hi, thanks for this piece of code, very interesting.
    Do we need to modify the structure of the XML to load different items?

  2. Protoflash Says:

    If you want more text items and image items, just add them into the xml structure.
    Is that what you wanted to ask?
    Cheers,
    Stephen

Leave a Reply