2 Replies - 21756 Views - Last Post: 15 February 2006 - 10:31 PM

#1 gayatri  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 13-February 06

Passing variables/data from Flash to PHP

Posted 15 February 2006 - 05:45 AM

Please forgive me for the long-winded post; I wanted u to take thoroughly through my problem n not intended to waste ur time!

I have been googling for 5 days. I have some good knowledge of php and i am fairly new to flash. I have done some really cool things with PHP/MySQL relatively easy.
my code goes as:
<?php
$Flash=flash.swf;
echo "<table cellpadding='0' cellspacing='0' width='500' style='border: 0px outset; margin-left: 1px;' align='center'><tr><td>".
'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="400" 
height="400" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="'.$Flash.'" />
<param name="quality" value="high" />
<param name="bgcolor" value="#000000" />
<embed src="'.$Flash.'" quality="high" bgcolor="#000000" width="400" height="400" name="thegame" align="middle" allowScriptAccess="sameDo
main" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
</td></tr></table>';


if i use
<?php
echo "
&FromPHP=Hello World&
";
?>


where to add
loadVariablesNum("phpfile.php", 0, "POST");

in my current code??
i know that gettimer is a function in flash which provides timer value for flash file execution, i want the same value in php but with the code above
i have gone through lot many websites but all show same info as open flash file add loadvar or loadvarnum etc
is it needed if i don't want to open the src of the flash file
i have some readymade flash games and just want the time
these file takes to completely execute, in php

the utterly simple php:

<?php
//The value of $x would be printed to the screen but the SWF would not read the data
$x = "abc";
print $x;
//The value of $x would be printed to the screen and because of the prefix 'myVar=', the SWF will //interpret this as being the intended value for the variable myVar in the SWF
print "myVar=$x";
?>


The second comment in the code never worked out for me Flash does not see it 'myVar='.

I have tried other tutorials out there and end up in the same place...

Relative points...

i have flash code and php code in the same file, so what to add in the flash execution??? and in php

I have seen the code I am trying to use in several scripts
<? print "myVar=$x"; ?>
except EVERY time I have seen it, it looks like this
<? print "&myVar=$x&"; ?>
or atleast 1 of the added ampersands.

Would this extremely basic simple script vary for different versions of Flash/ActionScript?

Should I be using the loadVariables or should it be loadVariablesNum? I've tried both...

If I copy and paste this simple code you would think it WOULD work! It does not!!!

I understand the "&" is what Flash uses to seperate elements from the external text.

If I can figure out how to pass vars between Flash and PHP I am on to great things :)

No kidding, I have tried every combination between everything mentioned above. I have looked everywhere I know of on the web. I have not been able to find anything to get me started that is as simple as this code ( SHOULD BE )!

Please help, thanks in advance,

Thanks again,

P.S. Some good (Flash/PHP) resources would be greatly appreciated. Lot's of great PHP resources out there but not too much using the combination,

This post has been edited by pioSko: 15 February 2006 - 06:25 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Passing variables/data from Flash to PHP

#2 pioSko  Icon User is offline

  • still.dreaming
  • member icon

Reputation: 23
  • View blog
  • Posts: 1,888
  • Joined: 06-June 03

Re: Passing variables/data from Flash to PHP

Posted 15 February 2006 - 06:58 AM

In order to get a value FROM flash you have to have Flash pass it on to PHP using the loadVars() or similar function. You will have to go into the Flash file and add that.

For example, at the end of the game or press of a button or whatever you can have a script that collects all theinformation from the game and sends it off to a PHP file:
var Timer:Number = 34;

var myVars:LoadVars = new LoadVars();

myVars.playerName = "Some Body";
myVars.playerTime = Timer;

myVars.send("echo.php", "_parent", "POST");


..for this example I've made an echo.php file where the vars are being sent. In it I have this code:
<?PHP
    echo($_POST['playerName'] . "'s time: " . $_POST['playerTime'] . " seconds.");
?>


You can test this here.
Was This Post Helpful? 1

#3 gayatri  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 2
  • View blog
  • Posts: 62
  • Joined: 13-February 06

Re: Passing variables/data from Flash to PHP

Posted 15 February 2006 - 10:31 PM

thanx a lot
what i can see from all this, is i have to get into flash file
i mean there is no any other alternative to transact with flash by not getting into it.
i thought i would get at least a option to gettimer value of game played by just passing varibale in url.
but i guess, it won't be possible
thanx will carry out the method u suggested.
in case u find anything constructive in this matter, do revert back

thanx again!
:D
hope for some :magic:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1