This tutorial shows how to get a var from a php file and convert and use it in Flash.

PHP-Var

In order to execute this tutorial with your own php file you need a server, which can execute php files. We first have to create a php file, which contains our variable as shown below. As you can see the var is called "increment". Important here however is that the expression is a string. That is important, because later we have to convert the string in our flash file.

<?
echo "increment=6";
?>

Now open a new flash file, make a movieclip and name it. We have named our movieclip "item". Next we call the php file and load it in the flash movie using LoadVars().

var lv:LoadVars = new LoadVars ();
var lvAnswer:LoadVars;
lvAnswer = new LoadVars ();
lv.sendAndLoad ("phpvar.php", lvAnswer, "POST");
lvAnswer.onLoad = function ()
{
	myNum = parseInt (this.increment);
};
//IMPORTANT here is the conversion of the data type string to number using parseInt().

Then we create our function, which will use the var from the php file.

     
but.onPress = function ()
{
	_root.varField.text = "increment= " + myNum;
	for (i = 1; i <= myNum; i++)
	{
	   removeMovieClip (_root["item" + i]);
	}
	var i = 1;
	timer = new Object ();
	timer.interval = function ()
	{
	   duplicateMovieClip (item, ["item" + i], i);
	   _root["item" + i]._x = i * 30;
	   _root["item" + i]._y = i * 10;
	   _root["item" + i].nField.text = "No. " + i;
	   if (i >= myNum)
	   {
	       clearInterval (myTiming);
	       _root.varField.text = "break at " + increment;
	   }
	   i++;
	};
	myTiming = setInterval (timer, "interval", 2000);
};