Yeni wrote on 12-01-2002 10:40 PM:
Hey David,
i need help with the loadvariables( ).
i click on button X then call .php. After that , i would want to send this data into a display box called Y.
Can you explain loadvariable (‘target.php’, targetclip)
CHeERrsS,
Yeni
Sure can… or at least I’ll do my best. PHP is not my strong suit, but I’m pretty good with the loadVariables statements
Now… I’ve writen it in here, and all of this should work in either Flash 5.0 or MX. There is a new, more convienient way to do this in MX that I’ll try to explain at the end. I’m sure h88 can add to anything I write with more detail.
loadVariables();
loadVariablesNum();
getUrl();
and a few others, seek to communicate with the server. They have particular syntax
you’ve probebly seen all that already Yani, but for the sake of others I supplied it.
loadVariables will take any variables that are located on the same timeline with it, and send those varibales to a server side script of some sort. You sound like you have a php file set up to feed the loadVariables(); method. That’s good. (that’s really the hard part)
This is the text from the dictionary.
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.
This last part is important. You can’t call to a script that’s on some other server. This is a safty feature. At least for testing purposes, you can place the php in the same folder with the swf, in which case the path would simply be the php doc, by name. Worry about paths to folders later when you’ve got it working.
level The level parameter is available with the loadVariables action only when the Actions panel is in normal mode; to specify level in expert mode, you must use the loadVariablesNum action. An integer specifying the level in the Flash Player to receive the variables. If you select this parameter when the Actions panel is in normal mode, Macromedia Flash MX automatically changes the loadVariables action to the loadVariablesNum action in the Actions panel Script pane.
This is the difference between loadVariablesNum() and loadVariables. I don’t use the Num version of that method because I almost never have levels stacked that have needed to send variables back and forth. But it’s there if you need it.
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.
this is just as it says. Sometimes it’s easiest to just have a holder clip sitting off to one side. create a clip off stage, call it holder. When you loadVariables, put them in there. From then on, you’ll always know that the path to your variables is small and easy to remember “_root.holder”
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.
If you’re going to send a small amount of data, and it is not important that it remain secure use get. If the data is extensive and or needs to be kept a secret send it using post. (erata: there is a program that can read variables being used by the Flash player. So just because I say secure, do not think that it’s absolute. Security is a whole other issue entirely.)
so to recap
this command
_root.loadVariables(“myphp.php”,_root.myHolderClip);
will send all variables that are on the main timeline, to the php script called myphp.php. That script will be executed by the server, sending back to Flash, any variables that are writen in the php doc to be sent as a “return”.
That is a little tricky probebly… but I’m assuming that you know something about the php doc that you’re using. If you need help with that, I’ll definitely have to call for back up
I’m really not sure what more can be said about the loadVariables method. But I can now mention the MX addition to the object team.
Thanks to h88 for giving me the heads up on these. In MX the loadVariables method is duplicated in object form.
basicaly, we can now use actionscript to create a loadVars object like so
myLoadVars = new LoadVars();
myLoadVars could be anything you wish. Once you’ve created the object you can use all of the following methods on that object.
[/quote]LoadVars.load Downloads variables from a specified URL.
LoadVars.getBytesLoaded Returns the number of bytes loaded from a load or sendAndLoad method.
LoadVars.getBytesTotal Returns the total number of bytes that will be downloaded by a load or sendAndLoad method.
LoadVars.send Posts variables from a LoadVars object to a URL.
LoadVars.sendAndLoad Posts variables from a LoadVars object to a URL and downloads the server’s response to a target object.
LoadVars.toString Returns a URL encoded string that contains all the enumerable variables in the LoadVars object.
It has the following Property
LoadVars.contentType Indicates the MIME type of the data.
LoadVars.loaded A Boolean value that indicates whether a load or sendAndLoad operation has completed.
and has the following Event
LoadVars.onLoad Invoked when a load or sendAndLoad operation has completed.[/quote]
I’m still playing around with each of these, so I’m not going to try to explain them. If h88 sees this thread I’d ask you if you might post some simple examples of usage for any of the methods or properties or the event.
Yani… do feel free to ask a specific quetion if I haven’t explained one area enough. I’m not too sure what you’re having trouble with. I’ll help out anyway I can.