[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!
 
I dont really understand that, though i do understand AS.

one thing though, your not very consistent with your layout, it might help you in the long run to be. for example you have
Code:
}
else {
on one line, and then
Code:
}else {
on the next, which gets rather confusing!

what is timePics ?
 
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've never used FlashVars in a project so i don't know what quirks it has but if it is resetting the fadeSpeed, try this:

make a tempVar which will be used just to hold the start value,
HTML:
Code:
filename.swf?myTempVar=3

Flash:
Code:
var fadeSpeed:Number = myTempVar; // or _root.myTempVar depending on the code's location
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;

PS you may find it handy to reg over at www.gotoandlearn.com
 
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!
 
you don't have to use FlashVars when you have access to php.

just incase you didn't know, FlashVars does not seem to work on IE :( it requires another parameter being set along with FlashVars:
http://forums.overclockers.co.uk/showpost.php?p=10903884&postcount=2

a guestbook tutorial example geared for MX:
http://www.flash-db.com/Tutorials/guestbook/
it's worth the read to see how flash can retrive data anywhere during it's runtime making the swf far more dyanmic.

if your MX supports it, loadVars(); is a good method.
http://www.sephiroth.it/tutorials/flashPHP/loadVars/
 
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