View Full Version : flash php basics with loadvars

02-10-2007, 07:11 PM
I'm using loadvars to get and retrieve data from flash to php.

I need some help in how can i call php functions from flash normally and with parameters.

02-10-2007, 08:10 PM
To be more specific, i would like to know how the comunication works.

I know how flash retrive vars from php, but how php retrive data from flash?

I have this example:

var result_lv:LoadVars = new LoadVars();
result_lv.onLoad = function(success:Boolean) {
if (success) {
aleatorio.text = result_lv.rand;
} else {
aleatorio.text = "Error connecting to server.";
var send_lv:LoadVars = new LoadVars();
send_lv.name = input_al.text;
send_lv.sendAndLoad("http://localhost/vinhos/test.php", result_lv, "GET");

I have a button, that when i click, it gets from php a random number. This works fine.

In fllsh i have an input box instance "input_al". If i put a number it sends it to php but it is not working.

In php i'm getting the flash var this way: $_GET['input_al']

This is just an example for me to know how this work.

Can anyone help me?

02-10-2007, 09:09 PM
Check Out what it won't work with (http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_15935)

And then follow this tutorial (http://www.azroc.co.uk/php/php_forms.php) for how it is done with php files :D

Hope it helps!

02-10-2007, 09:46 PM
Has i see there is no problem in my case. The output is a standalone player, and it wont play in a browser. The operating system is a MAC OSX 10.4, which is not refered in the "won't work" list.

I've tryed just doing it only with php and it worked. The problem is how php receive the vars from flash.

I've tryed this ways:
the object of Loadvars calls send_lv and the var i want to send calls input_aleatorio.
I have:
send_lv.input_aleatorio = 5;
send_lv.sendAndLoad("http://localhost/vinhos/test.php", result_lv, "POST");

In php i tryed:
$tab = $HTTP_POST_VARS['input_aleatorio'];
$tab = $_POST['input_aleatorio'];

None of this worked

02-10-2007, 09:48 PM
It's working with this:

$tab = $_POST['input_aleatorio'];


02-10-2007, 10:00 PM
i have another question. How can i call a php function from flash?

For example:

i have in php

function some_name(){
echo "success";

What should i have i flash? And if i want to send arguments from flash to php function?

I haven't found yet an example for this and it is very important.

02-11-2007, 03:20 PM
You can try with the $_GET var inside flash with all references pointing to the file in question.

You can also try variations of the load() vars or encapsulate the sting in it's own page using <?php include(); ?> and call that page...

Not sure exactly wqhat you are after though.