Announcement

User registrations are currently disabled due to high spam traffic.

#1 16/02/08 9:27pm

Zuriki
Flash Dev (The Lazy One)
From: Manchester
Registered: 18/01/08
Posts: 755
Website

PHP URL Variables and Flash

Ok I know next to nothing on PHP, other than how to connect to a database and send/load variables into a PHP file, which is useless to me xD.

Now I know that you can have variables in a PHP file like this

Code:

<?php
$variable = "value";
?>

...but that isn't any use to me for this...

I want my variable like this

Code:

http://www.site.com/file.php?variable=value

...then I want flash to load that variable I looked up some codes on forums but they weren't working for me.

lets say ?variable is actually ?1
and flash is going to put ?1 into _root.2.text

that way it is easier for me to follow and change what I need to later.

Thanks in advance.


[img]http://img134.imageshack.us/img134/9129/headerxt2.png[/img]
[url=http://zuriki.co.nr/project/traveller/][img]http://i28.tinypic.com/2vspafo.png[/img][/url]
[url=http://zuriki.co.nr]Zuriki - PSP Flash Games[/url]

Offline

 

#2 16/02/08 10:03pm

Jake
Administrator
Registered: 29/04/06
Posts: 307

Re: PHP URL Variables and Flash

You need to write some code in the php file to receive the variables from the url. Using your example from above:

Code:

http://www.site.com/file.php?variable=value

The php file will receive the data from the url using the following code

Code:

<?php
if (isset($_GET['variable'])) // check to see if the variable is there
{
 $variable=$_GET['variable']; // assigns the variable from the url to a php variable
 echo $variable; // to show its worked
}
else // the url does not have the variable set
{
 echo "The variable was not set";
}
?>

I hope that solves your problem with php.

To assign that variable in to the flash movie you will need to add some code in to the html (get the php to write this) which would be something like

Code:

<?php
print <<<FLASH
'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="480" height="272">
  <param name="movie" value="game.swf" />
  <param name="quality" value="high" />
  <param name=FlashVars value=variable='.$variable.' />
  <embed src="game.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="480" height="272" FlashVars=variable"'.$variable.'"></embed>'
</object>
FLASH;
?>

moose

Offline

 

#3 16/02/08 10:08pm

Zuriki
Flash Dev (The Lazy One)
From: Manchester
Registered: 18/01/08
Posts: 755
Website

Re: PHP URL Variables and Flash

Ok Jake I'lll try that.

Btw check your PMs!


[img]http://img134.imageshack.us/img134/9129/headerxt2.png[/img]
[url=http://zuriki.co.nr/project/traveller/][img]http://i28.tinypic.com/2vspafo.png[/img][/url]
[url=http://zuriki.co.nr]Zuriki - PSP Flash Games[/url]

Offline

 

#4 16/02/08 11:02pm

rollinroll
Moderator
Registered: 23/10/06
Posts: 1890

Re: PHP URL Variables and Flash

WOW! jake was online!

Offline

 

#5 16/02/08 11:15pm

Zuriki
Flash Dev (The Lazy One)
From: Manchester
Registered: 18/01/08
Posts: 755
Website

Re: PHP URL Variables and Flash

Lol I have seen him online a few times. Since his

Jake wrote:

internet is back.

Last edited by Zuriki (16/02/08 11:15pm)


[img]http://img134.imageshack.us/img134/9129/headerxt2.png[/img]
[url=http://zuriki.co.nr/project/traveller/][img]http://i28.tinypic.com/2vspafo.png[/img][/url]
[url=http://zuriki.co.nr]Zuriki - PSP Flash Games[/url]

Offline

 

#6 16/02/08 11:35pm

rollinroll
Moderator
Registered: 23/10/06
Posts: 1890

Re: PHP URL Variables and Flash

Oh ok cool

Offline

 

#7 16/02/08 11:44pm

Zuriki
Flash Dev (The Lazy One)
From: Manchester
Registered: 18/01/08
Posts: 755
Website

Re: PHP URL Variables and Flash

Ok right even if these codes are valid I still need flash to load them into a textbox or is it the same for loading an external text file?


[img]http://img134.imageshack.us/img134/9129/headerxt2.png[/img]
[url=http://zuriki.co.nr/project/traveller/][img]http://i28.tinypic.com/2vspafo.png[/img][/url]
[url=http://zuriki.co.nr]Zuriki - PSP Flash Games[/url]

Offline

 

#8 17/02/08 9:23am

tallphil
Banned
From: UK
Registered: 29/04/06
Posts: 823
Website

Re: PHP URL Variables and Flash

Exactly the same as loading an external text file - assign variables and flash loads them in as that. You don't have to use GET data if you don't want either - flash is able to send POST data too (better if you have a lot of variables to send to the php script)

A useful tip for using PHP to get variables out of a db too - you can use the php function mysql_num_rows($result) to echo a variable called 'numrows' or whatever at the start so that you can tell the flash how many variables to expect, then call each new line of results a number and flash will know how many to count up to, if that makes sense.
blah.


PSP Flash Gaming creator

Offline

 

#9 17/02/08 10:10am

Zuriki
Flash Dev (The Lazy One)
From: Manchester
Registered: 18/01/08
Posts: 755
Website

Re: PHP URL Variables and Flash

There is only 1 variable so database talkback is a waste of bandwidth and slower.


[img]http://img134.imageshack.us/img134/9129/headerxt2.png[/img]
[url=http://zuriki.co.nr/project/traveller/][img]http://i28.tinypic.com/2vspafo.png[/img][/url]
[url=http://zuriki.co.nr]Zuriki - PSP Flash Games[/url]

Offline

 

#10 17/02/08 6:32pm

Zuriki
Flash Dev (The Lazy One)
From: Manchester
Registered: 18/01/08
Posts: 755
Website

Re: PHP URL Variables and Flash

Ok tried both on PSP and on PC and it doesn't work.

The problem lies in the flash file not loading the variable.

the variable is called currentversion on the php and in the dynamic text box in flash is called _root.currentversion.

Code:

loadText = new LoadVars();
loadText.load("update.php");
loadText.onLoad = function(success) {
    if (success) {
        _root.currentversion.html = true;
        _root.currentversion.htmlText = this.currentversion;
    }
};

I think that only loads .txt files though because it doesn't seem to work.


[img]http://img134.imageshack.us/img134/9129/headerxt2.png[/img]
[url=http://zuriki.co.nr/project/traveller/][img]http://i28.tinypic.com/2vspafo.png[/img][/url]
[url=http://zuriki.co.nr]Zuriki - PSP Flash Games[/url]

Offline

 

#11 18/02/08 4:58pm

tallphil
Banned
From: UK
Registered: 29/04/06
Posts: 823
Website

Re: PHP URL Variables and Flash

Definitely works on php files because i have done it quite a lot of times. Try using an absolute address to the php file instead of relative...


PSP Flash Gaming creator

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson