I am using Flash CS3 and AS2.0 to try and open Mediabox (the lightbox clone for multimedia files) from XML text imported into an SWF movie. The SWF movie is a slideshow which imports images and captions from the XML file. When the user clicks on one of these captions I want to launch another SWF file in a Mediabox window. I think the problem is in the actionscript, rather than the XML.
My first test was to launch Mediabox from a button in an SWF movie and it worked fine. Here is the code that works, followed by my test movie URL:
Actionscript assigned to button:
on (release) {
getURL(“javascript:Mediabox.open(‘http://www.homestarrunner.com/tgs10.swf’,'test using mediabox’,‘mediabox[550 410]’);”);
}
You can view the result that I am trying to achieve here. Click on the image to launch:
http://www.pockitz.co.uk/gallery_tests/mediabox_test6.html
When I add the actionscript to import an XML file and assign the child information to a button, the result does not work.
1)-------------------------------
XML data which holds the link info and javascript instruction:
<?xml version=“1.0” encoding=“utf-8” standalone=“yes”?>
<images>
<pic>
<image>/image1.png</image>
<caption>caption goes here</caption>
<visit>Launch movie</visit>
<link>“javascript:Mediabox.open(‘http://www.homestarrunner.com/tgs10.swf’,'test using mediabox’,‘mediabox[550 410]’);”</link>
</pic>
</images>
2)-------------------------------
Actionscript to import XML and pass child info to button:
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
description = [];
visit = [];
link = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
description* = xmlNode.childNodes*.childNodes[1].firstChild.nodeValue;
visit* = xmlNode.childNodes*.childNodes[2].firstChild.nodeValue;
//this bit pulls the link info from the XML document
link* = xmlNode.childNodes*.childNodes[3].firstChild.nodeValue;
}
firstImage();
} else {
content = “file not loaded!”;
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load(“gallery_test6.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() {
prevImage();
};
next_btn.onRelease = function() {
nextImage();
};
/////////////////////////////////////
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 += 10;
}
}
};
function nextImage() {
if (p<(total-1)) {
p++;
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[p], 1);
desc_txt.text = description[p];
visit_txt.text = visit[p];
picture_num();
}
}
}
function prevImage() {
if (p>0) {
p–;
picture._alpha = 0;
picture.loadMovie(image[p], 1);
desc_txt.text = description[p];
visit_txt.text = visit[p];
picture_num();
}
}
function firstImage() {
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[0], 1);
desc_txt.text = description[0];
visit_txt.text = visit[0];
picture_num();
}
}
function picture_num() {
current_pos = p+1;
pos_txt.text = current_pos+" / "+total;
}
// this bit takes the link details and creates a function which is then passed to the button.
function myUrl(){
getURL(link[0]);
}
3)-------------------------------
Actionscript assigned to button:
on (release) {
myUrl();
}
any help greatly appreciated.
Pockitz