PDA

View Full Version : Convert AS2 to AS3 (XML / Slideshow)



public2
December 2nd, 2008, 05:59 AM
Hi everyone,
I've created a slideshow in AS2 (with some help from a tutorial) but it is in AS2 unfortunately. I need it to be in AS3 and I've tried to read some online tutorials and other online materials on AS3 and the difference, but I just seem to run my head against the wall every time.
I don't know if it's a comprehensive task to ask but I take my chances and try anyway. Please let me know if this is way too much to convert / translate


My AS2 code looks like this:


function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
description = [];
//url = [];
delay = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
description[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
//url[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
delay[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue;
}

firstImage();
} else {
content = "Billedet er ikke hentet!";
}
}
my_Date = new Date();
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("images.xml");

/////////////////////////////////////
listen = new Object();
listen.onKeyDown = function() {
if (Key.getCode() == Key.LEFT) {
prevImage();
} else if (Key.getCode() == Key.RIGHT) {
nextImage();
}
};
Key.addListener(listen);
previous_btn.onRelease = function() {
clearInterval(myInterval);
prevImage();
};
next_btn.onRelease = function() {
clearInterval(myInterval);
nextImage();

};

play_btn._visible = 0;
p = 0;
pause_btn.onRelease = function() {
clearInterval(myInterval);
pause_btn._visible = 0;
play_btn._visible = 100;
};
play_btn.onRelease = function() {
myInterval = setInterval(pause_slideshow, delay[p]);
pause_btn._visible = 100;
play_btn._visible = 0;
};

/////////////////////////////////////
p = 0;
this.onEnterFrame = function() {
filesize = picture.getBytesTotal();
loaded = picture.getBytesLoaded();
preloader._visible = true;
if (loaded != filesize) {
preloader.preload_bar._xscale = 100*loaded/filesize;
} else {
preloader._visible = false;
if (picture._alpha<100) {
picture._alpha += 5;
}
}
};

function nextImage() {
pause_btn._visible = 100;
play_btn._visible = 0;
previous_btn._visible = 100;
next_btn._visible = 100;
if (p<(total-1)) {
p++;
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[p], 1);
desc_txt.text = description[p];
url_btn = url[p];
go_btn = url[p];
picture_num();
slideshow();
}
}else{
p = 0;
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[p], 1);
desc_txt.text = description[p];
//url_btn = url[p];
//go_btn = url[p];
picture_num();
slideshow();
}
}
}

function prevImage() {
pause_btn._visible = 100;
play_btn._visible = 0;
if (p>0) {
p--;
picture._alpha = 0;
picture.loadMovie(image[p], 1);
desc_txt.text = description[p];
//url_btn = url[p];
//go_btn = url[p];
picture_num();
}else{
p = total - 1;
picture._alpha = 0;
picture.loadMovie(image[p], 1);
desc_txt.text = description[p];
picture_num();
}
}


function firstImage() {
// previous_btn._visible = 0;
// next_btn._visible = 100;
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[0], 1);
desc_txt.text = description[0];
//url_btn = url[0];
//go_btn = url[0];
picture_num();
slideshow();


}
}
function picture_num() {
current_pos = p+1;
pos_txt.text = current_pos+" / "+total;
}

function slideshow() {
myInterval = setInterval(pause_slideshow, delay[p]);
}

function pause_slideshow() {
clearInterval(myInterval);
if (p == (total-1)) {
p = 0;
firstImage();
} else {
nextImage();
}
}


I short it has to load images from a XML file where a tag with caption (image title) and a tag with the delay settings.
So far I’ve discovered that the XML loading in the very beginning is completely different in AS3 so I founded a tutorial on how to load XML data into flash. That is working alright but my next problem is to reset all the other variables (like caption, delay etc.) and I’ve read that XML in AS3 has a much faster and smarter way to load the tags. Now I just have to found out how that’s done :-)
Thanks in advance
Public2