# Cycling through several Flash movies with each pageview?



## Morgan19 (Dec 22, 2005)

I have six Flash movies that act as a header on a webpage and would like to randomly change which one displays each time a user visits/refreshes the page using Javascript. I've done it with static images before using this code in the header:


```
<SCRIPT LANGUAGE="JavaScript">
    iArray=new Array(
    "images/photo1.jpg",
    "images/photo2.jpg",
    "images/photo3.jpg",
    "images/photo4.jpg");
    ri=Math.floor(iArray.length*Math.random());
    ri='<IMG SRC="'+ iArray[ri]+ '" BORDER=0>';
    </SCRIPT>
```

...and this where I want the image to be:


```
<SCRIPT language="JavaScript">
    <!--
    document.write(ri);
    // -->
    </SCRIPT>
```

But is there something similar to that which I can use for cycling through several Flash movies?

m19


----------



## Morgan19 (Dec 30, 2005)

Anyone.....?

m19


----------



## ElDiabloConCaca (Dec 30, 2005)

I would assume that it would be similar, if not almost identical, to cycling through static images -- simply build the correct HTML into the variable "ri" and use the document.write method to write the correct HTML into the page.

If there something different about the Flash movies that prevents this from working?


----------



## Morgan19 (Jan 4, 2006)

ElDiabloConCaca said:
			
		

> If there something different about the Flash movies that prevents this from working?



I don't know, that's why I asked.  I tried swapping out the filenames (inserting the Flash files instead of images) but it didn't work. I'm just not sure what I should replace...

ri='<IMG SRC="'+ iArray[ri]+ '" BORDER=0>';

with...

m19


----------



## ElDiabloConCaca (Jan 4, 2006)

This should work:

```
<object width="550" height="400">
<param name="movie" value="somefilename.swf">
<embed src="somefilename.swf" width="550" height="400">
</embed>
</object>
```

The "object" is recognized by Explorer, and "embed" is recognized by Netscape-based browsers -- at least that's how it was in the old days.  Things may have changed now -- I don't do much Flash anymore.  

This will simply not work for people that don't have Flash Player installed, though -- more fancy code can be written that will send them to the download page for Flash Player or display a message or something.


----------



## Morgan19 (Jan 11, 2006)

But doesn't that just play _one_ Flash movie? The whole point is to have it cycle through six or seven each time a user refreshes or revisits the page, but it doesn't look like your code would do that...

m19


----------



## ElDiabloConCaca (Jan 11, 2006)

No, it won't do that.

You could, however, create a "master" flash movie who's job is to solely load a random other flash movie and play it.  Then, upon completion of the first movie, it would randomly pick another and load and play it.

That way, you have static HTML that points to the master Flash movie, which in turn simply loads random flash movies and plays them.  It would require some actionscripting in Flash, but I don't think it'd be too difficult.


----------



## Morgan19 (Jan 11, 2006)

Hmm, I'll have to look into doing it that way, as it sounds like it's just about the only feasible method at this point.  Just wish I knew anything about actionscripting.

m19


----------



## Morgan19 (Jan 17, 2006)

ElDiabloConCaca said:
			
		

> however, create a "master" flash movie who's job is to solely load a random other flash movie and play it.  Then, upon completion of the first movie, it would randomly pick another and load and play it.
> 
> That way, you have static HTML that points to the master Flash movie, which in turn simply loads random flash movies and plays them.  It would require some actionscripting in Flash, but I don't think it'd be too difficult.



Okay, I'm no Flash master and I haven't been able to figure out how to set up a movie that'll call to other movies, either with action scripting or otherwise. Can anyone help with that (and hopefully very quickly)?

m19


----------



## Thank The Cheese (Jan 17, 2006)

Hey Morgan. I found this, looks like what you need. I haven't tested it though:

Random loading of external swf file using loadMovie

good luck


----------

