Skip to main content
January 1, 2008
Question

Loading variables

  • January 1, 2008
  • 2 replies
  • 260 views
Hi it is possible that this will be very easy, but still:
I need function that loads variables from php via POST method and while variables are loading all other functions are stopped, as i will use this function often in script I think it is better that this function returns array of loaded variables, like

some code;
aArray = getVars("myPHP.php", aParamsArray);
some code vhere aArray is used;

the main problem I have is how to return variables if i am using setInterval because it calls another function, maybe there is some other way to stop script from runing until variables is loaded
This topic has been closed for replies.

2 replies

January 1, 2008
tnx i think it will work
Participating Frequently
January 1, 2008
This is the basic structure that I use to bring variables into Flash from a database via PHP. In Flash the variables are treated as an associative array (ie colors["white"] = 0xFFFFFF). I am so used to using the American spelling that I automatically write color when I am typing and colour when I am writing :).

----------PHP CODE-----------

$dbConn = mysql_connect("server", "username", "password");
mysql_select_db("database", $connection);
$result = mysql_query("SELECT Title, Story, Image FROM articles");
$i = 0;
while($article=mysql_fetch_array($result)) {
echo "Title{$i}={$row[Title]}&Story{$i}={$article[Story]}&Image{$i}={$article[Image]}&";
$i++;
}
echo "articleCount=$i";
mysql_close($dbConn);

---------------------------------------
This should output:

Title0=First Title&Story0=First Story&Image0=image1.jpg&Title1=Second Title&Story1=Second Story&Image1=image2.jpg&articleCount=2

---------ACTIONSCRIPT---------

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load(new URLRequest("phpFile.php"));

loader.addEventListener(Event.COMPLETE, variablesLoaded);

function variablesLoaded (ev:Event) {
for (var i:uint = 0; i < ev.target.data.articleCount; i++) {
this["title" + i + "_txt"].text = ev.target.data["Title"+i];
//Further code not shown
}
}

---------------------------------------

I sometimes create a variable to store ev.target.data outside of the function. ev.target.data is of the data type URLVariables.