View Full Version : AS2 and random images

09-03-2009, 03:38 PM
Hey all,
I'm new to Flash and AS (i'm using 2.0), and I have a question or two. I would like to have a section of my flash file to generate a picture I provided at random to load on my first page. I am having trouble doing this. I can make a .fla file using a .xml file that will play just fine. however it does not seem to work when I copy the frames into my other .fla file. The coding does not seem to work togther. I put a stop(); code so it will not just play all my keyframes, however this seems to put an end to my random pictures. does anyone know how to have a section of my page play the random pictures but will not run the timeline looping through all my pages. please of anyone can help that would be wonderful.
here is my code:

import mx.transitions.Tween;
import mx.transitions.easing.*;

pauseTime = 2000;

xmlImages = new XML();
xmlImages.ignoreWhite = true;
xmlImages.onLoad = loadImages;

function loadImages(loaded) {
if (loaded) {
xmlFirstChild = this.firstChild;
imageFileName = [];
totalImages = xmlFirstChild.childNodes[0].childNodes.length;
for (i=0; i<totalImages; i++) {
imageFileName[i] = xmlFirstChild.childNodes[0].childNodes[i].attributes.title;
function randomImage() {
if (loaded == filesize) {
var ran = Math.round(Math.random() * (totalImages - 1));
picture_mc._alpha = 0; // Start image clip as invisible
picture_mc.loadMovie(imageFileName[ran], 1); //Load random image from xml
var pictureTweenIn:Tween = new Tween (picture_mc,"_alpha",Normal.easeIn,0,100,1,true); // Use the Tween class to ease in the alpha from 0 to 100 over 1 seconds
pictureTweenIn.onMotionFinished = function () { // When done fading
_root.pause(); // Start pause() function
function pause() {
myInterval = setInterval(pause_slideshow, pauseTime);
function pause_slideshow() {
var pictureTweenOut:Tween = new Tween (picture_mc,"_alpha",Normal.easeOut,100,0,1,true); // After pause, start fade out
pictureTweenOut.onMotionFinished = function () { // Once faded out
_root.randomImage(); // Call next randomImage()