PDA

View Full Version : Flash and PHP Variable Issue



jlafond82
March 5th, 2010, 11:48 AM
Everyone, I am at my wits end, i just cannot figure this out. All I am trying to do is declare a variable in PHP and pass that variable to my flash file. Right now i am simply trying to do 1 easy variable, more will happen in the future but i need to figure this out first.

Can someone show me how to do this simply, I have used other forums and they say try this and that, but nothing i do seems to work. here is my code.



<?php
$fname = $_POST['John'] ;
echo '&firstName=' . $fname;
?>



var request:URLRequest = new URLRequest( "myPhp.php" );
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.firstName = "Test";
request.data = variables;
var loader:URLLoader = new URLLoader(request);
loader.addEventListener( Event.COMPLETE, loadCompleteHandler);
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.load( request );

function loadCompleteHandler( event:Event ):void
{

var data:URLVariables = new URLVariables( loader.data );
statusTxt1.text = loader.data.firstName;
trace( data.firstName );
}


I have no clue, please help

mpelland
March 5th, 2010, 11:59 AM
in your php... why are you grabbing $_POST["John"] and not $_POST["firstName"]?

jlafond82
March 5th, 2010, 12:11 PM
That is how previous forums desribed setting the variable of $fname, basically i want to post my name as a variable to flash and populate the text box with my name, really just to prove i can get variables into flash from php. Am i doing this wrong.

Here is the long and short of it, I am building a timeclock application, and within flash i get a bunch of values that i will eventually pass to php and populate an sql table, this part i think i can get, but what is really important is initially passing a variable from php (login name) to my initial flash file, i know this is off topic but thought it may be helpful if you knew what i was doing and why.

mpelland
March 5th, 2010, 12:13 PM
thats cool

basically what i am saying is that if you are calling the php script using variables.firstName = "Test"; as the variable, you need to use $_POST["firstName"] to access that info. the rest is fine

jlafond82
March 5th, 2010, 12:20 PM
Ok, so i just changed that and get the same result... My other question would now be if i am posting firstName, where in the php do i declare the value of fname?

mpelland
March 5th, 2010, 12:24 PM
you might have just lost me.. in your example, the flash is posting the value of the first name as test

then the PHP is taking that value and printing it out.. and flash is reading that. you have created a circle of data

jlafond82
March 5th, 2010, 12:28 PM
See now imagine how i feel...LOL Confusing myself... HAHA

Here is truly what i want to do, and i don't think my AS is correct at all.

Say I declare a variable in PHP the variable is $fname and it equals JOHN

How would I pass that variable to flash

The end result would be i want to take that variable that i recieved from PHP and populate a static text box on my flash stage.

I hope this clears it up.

snickelfritz
March 5th, 2010, 12:53 PM
See now imagine how i feel...LOL Confusing myself... HAHA

Here is truly what i want to do, and i don't think my AS is correct at all.

Say I declare a variable in PHP the variable is $fname and it equals JOHN

How would I pass that variable to flash

The end result would be i want to take that variable that i recieved from PHP and populate a static text box on my flash stage.

I hope this clears it up.
Lee brimelow has a good tutorial on SWFObject, that also deals with flashvars.
http://www.gotoandlearn.com/play?id=77
BTW, I would be very surprised if you could dynamically update the text in a static textfield.

jlafond82
March 5th, 2010, 01:10 PM
well now you can see why im so confused im calling dynamic text fields static text fields... LOL It's mind boggling... I will look at the tut, thanks