# \[FlashCS3\] launch mediabox from XML imported into SWF

**URL:** <https://forum.kirupa.com/t/flashcs3-launch-mediabox-from-xml-imported-into-swf/251641>\
**Category:** Uncategorized\
**Created:** [February 11, 2008, 11:57am UTC](https://forum.kirupa.com/t/flashcs3-launch-mediabox-from-xml-imported-into-swf/251641 "2008-02-11T11:57:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![pockitz](https://avatars.discourse-cdn.com/v4/letter/p/c5a1d2/32.png) [@pockitz](https://forum.kirupa.com/u/pockitz)\
**Post date:** [February 11, 2008, 11:57am UTC](https://forum.kirupa.com/t/flashcs3-launch-mediabox-from-xml-imported-into-swf/251641/1 "2008-02-11T11:57:15Z")

</div>

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.

## 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](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\_tes...box\_test6.html](http://www.pockitz.co.uk/gallery_tes...box_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](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
