Loading External Images = Anger + Pain!

Hi, I’m trying to load external swfs dynamically into empty movie clips from a list in a xml file.
Problem is that I want only one to appear at a time, while the others are paused. I also want to randomise which gets shown. I’ve got most of it to work but for some reason I cant turn off (using ._visible) the individual movies, so I’m thinking I have got multiple instances to begin with.

Can anyone please help?

Thanks greatly!

var x:XML = new XML();
x.ignoreWhite = true;

//array containing the location of swfs
var urls:Array = new Array();

//variable stating which is the current swf displayed
var current:Number = 0;
var randomNum:Number = 0;
var max:Number = 0;

//loads url from XML to array and loads first swf into holder clip on stage.
x.onLoad = function()
{
var swfs:Array = this.firstChild.childNodes;
for(i=0; i<swfs.length; i++)
{
urls.push(swfs*.attributes.url);
_root.createEmptyMovieClip(“swf”+ i,i);
loadImage();
}
max = urls.length;
randomise();
turnOn();
current = randomNum;
}

//loads XML
x.load(“swfList.xml”);
turnOn = function()
{
//this._visible = true;
}

loadImage = function()
{
loadMovie(urls*,[“swf”+i]);
this._visible = 0;
}

//triggers the next swf
nextSwf = function()
{
//this is where i will work out how to get the next one going… This function is called from within the individual swfs
}

//returns a random number between 0 and the total number of swfs in XML
randomise = function()
{
while (current == (i = random(max)))
{
i = random(max)
}
randomNum = i
}

Hi pete,

In the future, wrap your code in


=P

Anyway, it looks like you’re not actually setting the visibility of the movie clip you’re loading. “this” within your loadImage function doesn’t reference the movie clip, if I’m not mistaken. To hide/stop the movie clip you loaded the swf into, you could use any of the following:

this["swf"+i]._visible = false;
this["swf"+i].unloadMovie();
delete this["swf"+i].;

Also, I think your randomize function is overly complex. You can simply use this:
randomNum = random(swfs.length);

In fact, that function might be returning the same number every time… I can’t really think straight about it right now, but make the first change and see if you have any problems, and then if you do, change your randomize function.

Best,

-thesean