Load vars with php variables (flash mx)

I am trying to load the value of a php variable into a dynamic text field in flash mx.

I am using the loadvars method, with "nameofPHPfile,“0”,“GET” etc.

It doesn’t seem to work, but then I am not sure if the php code is correct. A process of elimination is needed. Am I using the right method in flash???

Any help would be great.

Best Regards

from the actionscript dictionary:

[size=3]loadVariables[/size]

Availability

Flash Player 4.

Usage

loadVariables ("url" ,level/"target" [, variables])

Parameters

url An absolute or relative URL where the variables are located. If you access the movie using a Web browser, the host for the URL must be in the same subdomain as the movie itself.

level An integer specifying the level in the Flash Player to receive the variables. When you load variables into a level, the action in the Actions panel in normal mode becomes loadVariablesNum; in expert mode, you must specify loadVariablesNum or choose it from the Actions toolbox.

target The target path to a movie clip that receives the loaded variables. You must specify either a target movie clip or a level (level) in the Flash Player; you can’t specify both.

variables An optional parameter specifying an HTTP method for sending variables. The parameter must be the string GET or POST. If there are no variables to be sent, omit this parameter. The GET method appends the variables to the end of the URL and is used for small numbers of variables. The POST method sends the variables in a separate HTTP header and is used for long strings of variables.

Returns

Nothing.

Description

Action; reads data from an external file, such as a text file or text generated by a CGI script, Active Server Pages (ASP), or PHP, or Perl script, and sets the values for variables in a Flash Player level or a target movie clip. This action can also be used to update variables in the active movie with new values.

The text at the specified URL must be in the standard MIME format application/x-www-form-urlencoded (a standard format used by CGI scripts). The movie and the variables to be loaded must reside at the same subdomain. Any number of variables can be specified. For example, the phrase below defines several variables:

company=Macromedia&address=600+Townsend&city=San+Francisco&zip=94103

The first movie to open in an instance of the Flash Player loads into the bottom level (identified in code as _level0). When you use the loadMovie or loadMovieNum action to load subsequent movies into the Flash Player, you must assign a level number in the Flash Player or a target movie clip into which each movie will load. When you use the loadVariables action, you must specify either a Flash Player level or a movie clip target into which the variables will load.

Example

This example loads information from a text file into text fields into the varTarget movie clip on the main Timeline. The variable names of the text fields must match the variable names in the data.txt file.

on(release) {
	loadVariables("data.txt", "_root.varTarget");
}

[size=3]loadVariablesNum[/size]

Availability

Flash Player 4. Flash 4 files opened in Flash 5 will be converted to use the correct syntax.

Usage

loadVariables ("url" ,level [, variables])

Parameters

url An absolute or relative URL where the variables are located. If you access the movie using a Web browser, the host for the URL must be in the same subdomain as the movie itself.

level An integer specifying the level in the Flash Player to receive the variables.

variables An optional parameter specifying an HTTP method for sending variables. The parameter must be the string GET or POST. If there are no variables to be sent, omit this parameter. The GET method appends the variables to the end of the URL, and is used for small numbers of variables. The POST method sends the variables in a separate HTTP header and is used for long strings of variables.

Returns

Nothing.

Description

Action; reads data from an external file, such as a text file or text generated by a CGI script, Active Server Pages (ASP), or PHP, or Perl script, and sets the values for variables in a Flash Player level. This action can also be used to update variables in the active movie with new values. When you load variables into a level, the action in the Actions panel in normal mode becomes loadVariablesNum; in expert mode, you must specify loadVariablesNum or choose it from the Actions toolbox.

The text at the specified URL must be in the standard MIME format application/x-www-form-urlencoded(a standard format used by CGI scripts). The movie and the variables to be loaded must reside at the same subdomain. Any number of variables can be specified. For example, the phrase below defines several variables:

company=Macromedia&address=600+Townsend&city=San+Francisco&zip=94103

The first movie to open in an instance of the Flash Player loads into the bottom level (identified in code as _level0). When you use the loadMovie or loadMovieNum action to load subsequent movies into the Flash Player, you must assign a level number in the Flash Player or a target movie clip into which each movie will load. When you use the loadVariablesNum action, you must specify a Flash Player level into which the variables will load.

Example

This example loads information from a text file into text fields in the main Timeline of the movie at level 0 in the Flash Player. The variable names of the text fields must match the variable names in the data.txt file.

on(release) {
	loadVariablesNum("data.txt", 0);
}

i’d say … yes

Are you posting any value to a php file and then getting a response or your trying to load a value from a php file without sending any var from flash?

Just tell me exactly what is your issue.

The contact form passes variables to a php file. Then the php if condition tests to see if the mail was sent to my inbox. If it did it generates a php variable called $status. This is the variable I am trying to capture in flash.

I’ve still to iron out the bugs in the php code, as it still generates errors, but I have also to make sure that flash displays the variable.

I have a .fla which is the send button

The code might be a little crap but I am a newbie.

Regards

And thanks for any help you might be able to give.

I didn’t check your fla, but here is a code that might help you:

also, generate the variable value (php script) in this form:

echo “&status1 = $status”

Here is the flash Code:

myLoadVars = new LoadVars();
myLoadVars.specificvariable = “Value”;
// specificvariable value will be submited to the php file
myLoadVars.sendAndLoad(“phpfile.php”, this, “POST”);
//now, let us set onLoad!
myLoadVars.onLoad = function() {
myTextBox.text = this.status1;
};

The code you submitted was interesting. But I don’t understand it completely, for example why use POST if I want to GET a variable.

I only need to get a variable from the php. I have been using:

if (Name.length && Email.length && Details.length != true && Email.indexOf("@") != -1 && Email.indexOf(".") != -1) {

loadVariablesNum(“mailPHP.php”, “0”, “POST”);

to send variable to flash.

The end of the php code now reads:

if(mail($Name." <".$ToEmail.">",$ToSubject, $EmailBody, “From: “.$Name.” <”.$Email.">")){

$status= “Mail Sent”;
}
else{
$status= “Mail not Sent”;
}
echo “&status1=$status”;

?>
</html>

And I have been using:

loadVariables(“mailPHP.php”,_root.enq.form.Status,“GET”);

I can see the problem, principally that I haven’t defined the variable to GET

Could I ask for a bit more assistance??

*Originally posted by jimw00d *
**The code you submitted was interesting. But I don’t understand it completely, for example why use POST if I want to GET a variable.
I can see the problem, principally that I haven’t defined the variable to GET

Could I ask for a bit more assistance??**

It’s up to you, my code was just an example, you can use either GET or POST.

this
loadVariablesNum(“mailPHP.php”, “0”, “POST”);
can’t work, check where to place " and where not!

call your php directly in the browser and append the variables to the url to check the output, as in

I buggered up a little,

it should read:

getURL(“mailPHP.php”, “0”, “POST”);

In php there is a variable called $status

I am now messing around with:

myVars = new LoadVars();
myVars.load(“mailPHP.php”);
_root.enq.form.Err.text = this.myVars.status1=$status;

I still don’t understand the point of status1 in the php code

And flash won’t display the value of the $status

Err is the name of a dynamic text field

The issue is slowly becoming clearer and I hope I am near the end.

Where does the main problem lie??

I buggered up a little,

it should read:

getURL(“mailPHP.php”, “0”, “POST”);

In php there is a variable called $status

I am now messing around with:

myVars = new LoadVars();
myVars.load(“mailPHP.php”);
_root.enq.form.Err.text = this.myVars.status1=$status;

I still don’t understand the point of status1 in the php code

And flash won’t display the value of the $status

Err is the name of a dynamic text field

The issue is slowly becoming clearer and I hope I am near the end.

Where does the main problem lie??

It should be:

myVars = new LoadVars();
myVars.load(“mailPHP.php”);
_root.enq.form.Err.text = myVars.status1;

but it’s wrong! You told me that your posting a var from Flash, and then loading the result, the way above will let you just load the var from the php file, without posting anything!

Well the point of outputing your variable in the form i suggested to you above is flash can read them this way!

&status=bablatextorvariable!

Yes, you are right. I am using POST to post variables from a mail form i.e. name, email, location etc.

If the mailto() function is processed in php, I have opted to create a new variable called $status.

GET in flash is designed to get the value of $status, which is either “Mail sent” or “Mail not Sent”, so you see I am not interested in getting the results of the variables posted in flash to php.

So as long as I can get PHP to generate a variable called $stauts, with a value of Mail sent or not sent, then all I need to do is reflect the value of $status in a text field in flash.

For the record I am using

getURL("mailPHP.php,“0”,“POST”) to post user inputted variables from the form in flash.

Again, any help would be greatly appreciated. I’ve run out of hair to pull.

Also,

The php code is producing multiple emails rather than one.

The last time I tried, it produced eight emails. Four with the variables I inputted and four without.

Any ideas

Hi Guyz, don’t mean to butt in on this thread but i am also trying to accomplish the same thing! Maybe we can learn off of each other? (Flash 5 btw)

I think I have the exact scripts you are looking for! - if you go to my site - site and press the submit button (bottom right) fill in the form and you get a confirmation it has been sent. Sends the information entered to me and a thankyou confirmation to the user who inputed the data!

If you want the files i can send them to you!

I have lots of links in my flash document! and I am trying to save the clickcount for each link and then update the results in the flash file!

This is what i am doing so far - The links are load in from a .txt file into a duplicate mc! and the click count is in place and displays the results! Noe of course when you reload the page the click count results go back to ‘0’ as i have not saved them anywhere!

So I have been told by a very kind user (Jubba) that the next step is to save the counts to a database using php!

I have a mysql database system in place on my ip server! I just want to find the best php scripts to do the job, before i end up ammending many different ones!

Can anyone reccomend the one for my purpose?

Thanks

*Originally posted by h88 *
**I didn’t check your fla, but here is a code that might help you:

also, generate the variable value (php script) in this form:

echo “&status1 = $status”

Here is the flash Code:

myLoadVars = new LoadVars();
myLoadVars.specificvariable = “Value”;
// specificvariable value will be submited to the php file
myLoadVars.sendAndLoad(“phpfile.php”, this, “POST”);
//now, let us set onLoad!
myLoadVars.onLoad = function() {
myTextBox.text = this.status1;
}; **

here this should be a LoadVars() Object

Eron,

The form is all done and the code works fine, I actually came to the same code solution over the weekend and I finally understand how it all comes together.

As regards Kev’s query I have seen a tutorial for detecting mouse clicks that used php. I can’t seem to find the URL at the moment but I will keep looking. I also have posted on Kirupa on this subject with no success.

It seems feasible to use actionscript to use new LoadVars so that when a user clicks on a button or mc the LoadVars() is called which in turn sends a variable to a php code for processing. PHP can then pass this variable and maybe an associative value to the mysql database.

If you wanted to find out the number of users on your site, you

Thanks jimw00d, Glad you solved your problem, was it a similer form that i have on my site? And as for the link hope you can find it! it would be very usefull!

I have a php script for click counts, but I have not started to intergrate it yet! it looks pretty straight forward, although I have never set up a database before!

The only problem I can see is that the dupliacted buttons have the same duplicted textbox which the hits are displayed in, so all the different links display there individual hits into the textbox which has the same variable name!My problem is will the php script know that they are all individual seperate hits? I don’t want to have one database for each link! that would take for ever and be very unsuitable! Now i am no expert at either actionscripting and php, so this may not be a problem!

I’ll work at it first and at least get it working! then I can post my results back here!

Thanks

Kev

Although I am no guru in either field, I see no reason why a button click cannot generate an independent variable that can then be sent with all the others in a combined loadVars script on say a keyframe.

For example if a button is clicked a variable say “Links” could be given the value of 1 or yes and if not clicked, assigned a different value say 0 or no. These variable and values could then be posted to php for processing and database storage.

Let me know how it comes along.
I have found the tutorial in a hard copy that I printed. I will look for the url.

regards

Although I am no guru in either field, I see no reason why a button click cannot generate an independent variable that can then be sent with all the others in a combined loadVars script on say a keyframe.

For example if a button is clicked a variable say “Links” could be given the value of 1 or yes and if not clicked, assigned a different value say 0 or no. These variable and values could then be posted to php for processing and database storage.

Let me know how it comes along.
I have found the tutorial in a hard copy that I printed. I will look for the url.

regards

Thanks - here is the link to the php click counter i will be using! - http://www.hotscripts.com/Detailed/20165.html

kev