Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Supporting Technologies > Server-Side Scripting

Thread Tools Rating: Thread Rating: 27 votes, 5.00 average. Display Modes
Old 09-10-2004, 06:09 PM   #1
Registered User
Join Date: Sep 2004
Posts: 5
Exclamation Passing variables from PHP to ActionScript

Ok I'm new to PHP but I have relative experience with ActionScript.

I've been making a game which at the end sends variables to a PHP file and the PHP file sends the variables to a MySQL database, I have this working perfectly fine and dandy.

However I require the game to display the top 10 scores at the start of the game, I can get the top 10 fine using PHP on its own but when it comes to sending the top10 (or any variable for that matter) to ActionScript I can't seem to get it to work.

I have searched in vein to find tutorials to help me out and I have searched this forum and still I'm no more knowledged than 3 days ago.

Please could someone post a simple PHP script that will pass a single variable to ActionScript and also the ActionScript needed to recieve that variable so I can see how it should be done.

arctictiger is offline   Reply With Quote
Old 09-10-2004, 06:48 PM   #2
Registered User
Join Date: Feb 2002
Location: Minneapolis
Posts: 77
Send a message via AIM to Twister Send a message via Yahoo to Twister

Ok you need to make a page for flash to pull in the variable. on this page you'd output your variable like this &name=thomas The source code for that page would be something like echo ("&name=thomas");

Then you use loadVariableNum to load that page. loadVariableNum("variablepage.php",0)

Two things to keep in mind
1) it will load variables into the root level of your file, most likely
2) I wrote that off the top of my head so make sure to check the code.
Twister is offline   Reply With Quote
Old 09-10-2004, 06:54 PM   #3
Super Moderator
CyanBlue's Avatar
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666

Quick tutorial can be found here...


I'd probably use LoadVars object unless you are exporting your movie for F5...
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 09-11-2004, 12:10 AM   #4
Registered User
Join Date: Sep 2004
Posts: 5

Ok, this is what I have going on as a test... (test php file is topten.php)

PHP Code:
then in the ActionScript I have this...

loadVariablesNum("topten.php", 0);
and my Dynamic Text box is assigned the variable _root.Topname

so this should display "Success" in my text box, is this right?
arctictiger is offline   Reply With Quote
Old 09-11-2004, 12:46 AM   #5
Registered User
Join Date: Sep 2004
Posts: 5

Ok, now I have tried a different ActionScript method using the same PHP as follows... (The dynamic textbox intance name is "top_text")

var top_list = new LoadVars();
top_list.onLoad = function(success){
	if (success){
		top_text.text = top_list.Topname;
And this doens't work either! Help Please
arctictiger is offline   Reply With Quote
Old 09-11-2004, 06:30 PM   #6
Registered User
Join Date: Aug 2004
Posts: 24

This should help

PHP Code

$second = "that";

echo "myfirst=$first&mysecond=$second";

Flash Actionscript:

var lvSend = new LoadVars();
var lvReceive = new LoadVars();

lvReceive.onLoad = function(bSuccess) {
if(bSuccess == true) {

Hope this helps

ibizconsultants is offline   Reply With Quote
Old 09-12-2004, 03:07 AM   #7
Dark_Element's Avatar
Join Date: Aug 2004
Location: Australia->Gold Coast
Posts: 413
Default If

Hi ya. I've made something like this for some1 recently. This piece of php code will deffinitely help you:

PHP Code:
//just replace the 'host', 'user', 'pass', and 'db' with stuff you have
$connect = @mysql_connect('host','user','pass');
$dbselect = @mysql_select_db('db',$connect);
$query = @mysql_query('SELECT player, score FROM scores ORDER BY score DESC LIMIT 10');
if (!
$connect or !$dbselect or !$query) {
$num 1;
$rows mysql_num_rows($query);
while (
$info mysql_fetch_assoc($query)) {
$key array_keys($info);
$key[0].''.$num.'='.$info['player'].''.($num <= $rows '&' '').''.$key[1].''.$num.'='.$info['score'].($num $rows '&' ''));
PS: that code assumes you have a table in your database called "scores" and in it there should be columns "player" and "scores".

note: it will return variables in this layout:
"player"a increasing number"="name of player"&score"a increasing value equivlent to the one before"="score value

so: if there is a table in MySQL like this:
|player | score |
| foo   | 100  |
| bar   | 250  |
| var   | 90   |
this will be returned by the PHP code:
player1=bar&score1=250&player2=foo&score2=100&play er3=var&score3=90

Hope that helps


<C-Stamp> if you need more help you are welcomed to PM me </C-Stamp>

Last edited by Dark_Element; 09-12-2004 at 03:11 AM. Reason: Makin it look better
Dark_Element is offline   Reply With Quote
Old 09-12-2004, 12:00 PM   #8
Registered User
Join Date: Sep 2004
Posts: 5

Sniper I aren't having any trouble with MySQL but thatnks anyway.

ibizconsultants I have tried your method and this works fine for the second variable only, it seems for some reason I can only recieve the second variable. bloody odd.
arctictiger is offline   Reply With Quote
Old 09-12-2004, 12:02 PM   #9
Registered User
Join Date: Sep 2004
Posts: 5

D'oh! it just needed an & in front. Thanks guys problem solved
arctictiger is offline   Reply With Quote
Old 09-12-2008, 03:50 PM   #10
Senior Member
Join Date: Dec 2005
Posts: 263

if you start passing larger and more coplex data you may thing about having you php out put it as a xml doc. then in flash you load the xml. It is much easier for complex data then the above method.
davej is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

All times are GMT. The time now is 04:21 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.