[Flash MX] ActionScript, PHP and Load times

Update:

Ok, I got the flash loading much quicker. I had to put my php file counting code at the end of the php section on the index page :)

But dont worry, another problem cropped up!

My flash has two variables i wish to control - holdLength and fadeSpeed. holdLength is the time in seconds that the image stays at 100% alpha, and this works fine being controlled by the HTML FlashVar.

However, fadeSpeed, the time it takes to fade in and out, simply wont be controlled via FlashVars. I'm not sure how its worked out, as a lower number produces a slower fade speed. Im positive it should be controllable via the HTML, yet when i try, the flash hangs on a blank canvas.

Below is a code snippet showing how this variable is used within the AS code.

Code:
onEnterFrame = function () {
    if (picFadeIn == true) {
        if (my_mc._alpha<100) {
            my_mc._alpha += fadeSpeed;
        } 
        else {
            picFadeIn = false;
            doHold = true;
        }
    }
    if (doHold==true){timePics();}else{
        if (nextFade == true) {
            if (my_mc._alpha>=0) {
                my_mc._alpha -= fadeSpeed;
            }else {
            getPics();
            }
        } 
    }

Hope someone can help, as being able to control this via PHP+HTML would be of great use!
 
Code:
createEmptyMovieClip("my_mc", 0);

//var fadeSpeed = 10;

var myName:String = "banner";
var myExt:String = ".jpg";
var myNum:Number = 1;
var lastNum:Number = 1;
var nextFade:Boolean = false;
var picFadeIn:Boolean = false;
var isDone:Boolean = false;
var doHold:Boolean = false;

i = 0;
function timePics() {
	doHold = false;
	var myInt = setInterval(holdPic, (holdLength*1000));
	function holdPic() {
		nextFade = true;
		clearInterval(myInt);
	}
}

function getPics() {

	lastNum = myNum;
	myNum = Math.floor(Math.random()*numberOfFiles+1);
	if (myNum == lastNum) {
		if (myNum<=1) {
			myNum += 1;
		} else {
			myNum -= 1;
		}
	}
	my_mc.loadMovie("images/banners/"+myName+myNum+myExt, myNum+".jpg");
	my_mc._alpha = 0;
	picFadeIn = true;
	nextFade = false;
	i++;
	my_mc._x += ((Stage.width-my_mc.width)/2);
}
getPics();

onEnterFrame = function () {
	if (picFadeIn == true) {
		if (my_mc._alpha<100) {
			my_mc._alpha += fadeSpeed;
		} else {
			picFadeIn = false;
			doHold = true;
		}
	}
	if (doHold == true) {
		timePics();
	} else {
		if (nextFade == true) {
			if (my_mc._alpha>=0) {
				my_mc._alpha -= fadeSpeed;
			} else {
				getPics();
			}
		}
	}
};

This is my full AS code. The commented variable, fadeSpeed, is the problem.

I have tried the standard way of using FlashVars, and also tried the filename.swf?fadeSpeed=*value* way, but that didnt work either.

NB I didnt write this code, I found it on a Flash help forum, kindly posted by some guy who obviously knows his stuff. I have simply been hacking away at it :)

Hope this helps!

Uber-Edit :: I think I have realised why the flash doesnt play. It seems that when setting the flash variable in HTML, it has to stay set at that number, and thats the problem. I believe the fadeSpeed number gets altered, and by doing so, makes the image fade in and out. Having the number static means it cannot fade in or out. Shame I don't know enough actionscript to rewrite that part of the code, doh!
 
Last edited:
I managed to figure it out own my own, the solution was dead easy.

I simply put in the AS:

Code:
var fade
var fadeSpeed = fade*1;

then in the PHP I made the variable fade controlable =)

I have since got a control panel working on a seperate "admin" page, which enters and retreive the values from a SQL database, rock on!
 
When i used normal FlashVars, they works fine in IE im sure, i know they defineatly work in FF

i have no clue about xml, and dont with to try and use it.

and about not needing flashvars with php - im not sure how it would work, but i know what i have so far does, without a hitch and thats PHP & HTML + FlashVars.
 
Last edited:
Back
Top Bottom