PDA

View Full Version : load vars with php variables (flash mx)



jimw00d
January 27th, 2003, 03:55 AM
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

kode
January 27th, 2003, 04:21 AM
from the actionscript dictionary:

loadVariables


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");
}

loadVariablesNum


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

h88
January 27th, 2003, 02:27 PM
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.

jimw00d
January 27th, 2003, 02:46 PM
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.

h88
January 27th, 2003, 02:54 PM
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;
};

jimw00d
January 27th, 2003, 04:20 PM
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??

h88
January 27th, 2003, 04:36 PM
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.

eyezberg
January 27th, 2003, 05:35 PM
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
www.yoursite.com/phpscript.php?var1=this&var2=that&var3=andsoon

jimw00d
January 27th, 2003, 05:47 PM
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??

jimw00d
January 27th, 2003, 05:48 PM
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??

h88
January 27th, 2003, 05:52 PM
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!

jimw00d
January 28th, 2003, 04:26 AM
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.

jimw00d
January 28th, 2003, 05:52 AM
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

kev
February 4th, 2003, 07:57 AM
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 (http://www.liquidsource.co.uk) 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

eron19
February 4th, 2003, 11:14 AM
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

jimw00d
February 5th, 2003, 05:15 AM
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

kev
February 5th, 2003, 03:02 PM
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

jimw00d
February 6th, 2003, 02:50 AM
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

jimw00d
February 6th, 2003, 02:50 AM
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

kev
February 6th, 2003, 11:57 AM
Thanks - here is the link to the php click counter i will be using! - http://www.hotscripts.com/Detailed/20165.html

kev

jimw00d
February 6th, 2003, 05:54 PM
Listen,

The best I can do is scan the hard copy and email them to you, I am buggered if I can find the url, last week was a mess of code etc.

Let me know if you need it, it's no problem.

The code for the click looks good. Problem with the MOOCK example??

regards

kev
February 7th, 2003, 03:29 AM
Hi, thanks for finding it! yes email it to me if you don't mind - info@realitydesigns.co.uk

The script works well, but it seems i have to enter each link into the database manually for it to work! Beacuse my links to the site are loaded in from a .txt file, this means i have to edit two files - the .txt file and the database! -

Want i want is to just add a new link into one file and have it all update it self! maybe i will have to look at loading the link.txt file through php somehow or directly into the database! but I have no idea where to start!

if you got any ideas let me know!

Thanks