Hello,
I used a sample of macromedia to get a XML file with the names to the swf
files i want to import in the stage. That works (for now). But now i also want
to at a link (using getURL();) to the movieclip where the swf file is placed.
Can someone help me?
Greetings,
Spaantje
PS. i used gallery_tween.fla from the sample folder if someone wants to know...
/* Actionscript Code */
// Set the starting X and Y positions for the gallery images.
_global.thisX = 30;
_global.thisY = 70;
/* Set static values for the Stage's width and height.
Using Stage.width and Stage.height within the code results in
strangely positioned full images when testing in the Flash environment
(but the problem doesn't exist when published to a SWF file). */
_global.stageWidth = 970;
_global.stageHeight = 550;
// Create and configure the XML instance which is used to load the list of
gallery images on the fly.
var gallery_xml:XML = new XML();
gallery_xml.ignoreWhite = true;
gallery_xml.onLoad = function(success:Boolean) {
try {
/* if you are able to successfully load and parse the gallery from a remote
XML file,
parse out the image names and add them to an array. */
if (success) {
var images:Array = this.firstChild.childNodes;
var gallery_array:Array = new Array();
var myURL_array:Array = new Array();
// trace(images);
for (var i = 0; i<images.length; i++) {
gallery_array.push({src:images[i].firstChild.nodeValue},
href:images[i].attributes.href);
trace("gallery_array" + i + ": " + gallery_array[i].src);
trace"gallery_array" + i + ": " + gallery_array[i].href);
myURL_array.push({href:images[i].attributes.href});
trace("myURL_array" + i + ": " + myURL_array[i].href);
}
/* call the displayGallery function which handles loading in each
of the gallery images and placing them on the Stage. */
displayGallery(gallery_array);
displayURL(myURL_array);
} else {
throw new Error("Unable to parse XML");
}
} catch (e_err:Error) {
trace(e_err.message);
} finally {
delete this;
}
};
// load the gallery.xml file from the current directory.
gallery_xml.load("test_short_movies.xml");
/* create a function which loops through the images in an array,
and creates new movie clips on the Stage. */
function displayGallery(gallery_array:Array) {
var galleryLength:Number = gallery_array.length;
// loop through each of the images in the gallery_array.
for (var i = 0; i<galleryLength; i++) {
/* create a movie clip instance which holds the image. We'll also set a
variable,
thisMC, which is an alias to the movie clip instance. */
var thisMC:MovieClip = this.createEmptyMovieClip("image"+i+"_mc", i);
/* TRACE Names */
trace("MovieClip Name: " + thisMC);
/* load the current image source into the new movie clip instance,
using the MovieClipLoader class. */
mcLoader_mcl.loadClip(gallery_array[i].src, thisMC);
// attach the preloader symbol from the Library onto the Stage.
preloaderMC = this.attachMovie("preloader_mc", "preloader"+i+"_mc", 5000+i);
/* set the preloader's bar_mc's _xscale property to 0%
and set a default value in the progress bars text field. */
preloaderMC.bar_mc._xscale = 0;
preloaderMC.progress_txt.text = "0%";
// set the _x and _y coordinates of the new movie clip.
thisMC._x = _global.thisX;
thisMC._y = _global.thisY;
// set the position of the image preloader.
preloaderMC._x = _global.thisX;
preloaderMC._y = _global.thisY+20;
// if you've displayed 9 columns of images, start a new row.
if ((i+1)%9 == 0) {
// reset the X and Y positions
_global.thisX = 20;
_global.thisY += 70;
} else {
_global.thisX += 85+20;
}
}
}
/* NEW Function for URLS.... */
function displayURL(myURL_array:Array) {
var myURLLength:Number = myURL_array.length;
// loop through each of the images in the gallery_array.
for (var j = 0; j<myURLLength; j++) {
/* create a movie clip instance which holds the image. We'll also set a
variable,
thisMC, which is an alias to the movie clip instance. */
// var thisMC:MovieClip = this.createEmptyMovieClip("image"+i+"_mc", i);
// var myLink_array = new Array();
var myLink:String = myURL_array[j].href;
/* TRACE Names */
trace("Link: " + myLink);
}
}
// define the MovieClipLoader instance and MovieClipLoader listener Object.
var mcLoader_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadStart = function() {
};
// while the content is preloading, modify the width of the progress bar.
mclListener.onLoadProgress = function(target_mc, loadedBytes, totalBytes) {
var pctLoaded:Number = Math.round(loadedBytes/totalBytes*100);
// create a shortcut for the path to the preloader movie clip.
var preloaderMC = target_mc._parent["preloader"+target_mc.getDepth()+"_mc"];
preloaderMC.bar_mc._xscale = pctLoaded;
preloaderMC.progress_txt.text = pctLoaded+"%";
};
// when the onLoadInit event is thrown, you're free to position the instances
mclListener.onLoadInit = function(evt:MovieClip) {
evt._parent["preloader"+evt.getDepth()+"_mc"].removeMovieClip();
/* set local variables for the target movie clip's width and height,
and the desired settings for the image stroke and border. */
var thisWidth:Number = evt._width;
var thisHeight:Number = evt._height;
var borderWidth:Number = 2;
var marginWidth:Number = 6;
evt.scale = 100;
// draw a white rectangle with a black stroke around the images.
evt.lineStyle(borderWidth, 0x000000, 100);
evt.beginFill(0xFFFFFF, 100);
evt.moveTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
evt.lineTo(thisWidth+borderWidth+marginWidth, -borderWidth-marginWidth);
evt.lineTo(thisWidth+borderWidth+marginWidth,
thisHeight+borderWidth+marginWidth);
evt.lineTo(-borderWidth-marginWidth, thisHeight+borderWidth+marginWidth);
evt.lineTo(-borderWidth-marginWidth, -borderWidth-marginWidth);
evt.endFill();
/* scale the target movie clip so it appears as a thumbnail.
This allows users to quickly view a full image without downloading it
every time,
but unfortunaltey also causes a large initial download. */
evt._xscale = evt.scale;
evt._yscale = evt.scale;
// rotate the current image (and borders) anywyhere from -5 degrees to +5
degrees.
// evt._rotation = Math.round(Math.random()*-10)+5;
/* On MouseOver Start Play */
evt.onRollOver = function() {
this.play();
}
evt.onRollOut = function() {
// this.stop(1);
}
evt.onRelease = function() {
trace(evt._name);
// getURL('" + String(myLink) + "');
};
// if the mouse cursor was released outside of the movie clip, call the
onRelease handler.
evt.onReleaseOutside = evt.onRelease;
};
mcLoader_mcl.addListener(mclListener);
------------------------------------------------------------------------
/* XML file -test_short_movies.xml- */
<?xml version="1.0"?>
<gallery>
<img href="abn.htm"><![CDATA[ABN_Amro.swf]]></img>
<img href="andrea.htm"><![CDATA[Andrea_Bocelli.swf]]></img>
<img href="zoute_koning.htm"><![CDATA[De_zoute_koning.swf]]></img>
<img href="great_palaces.htm"><![CDATA[Great_Palaces_of_the_World.swf]]></img>
<img href="nijntje.htm"><![CDATA[Nijntje_is_er_weer.swf]]></img>
<img href="smit_clyde.htm"><![CDATA[Smit_Clyde.swf]]></img>
</gallery>
MotionMaker - 29 Mar 2007 01:17 GMT
"But now i also want to at a link (using getURL();) to the movieclip where the swf file is placed."
What does the question mean?