View Full Version : Flash Input
zypher2004
03-25-2005, 06:11 AM
How can I input data into a flash animation through the URL like using a PHP get function.
thanks,
zypher2004
Hi,
There are a few ways to import data into a flash movie. The most effiecient is the use of a load vars object...
new LoadVars()
Parameters
None.
Returns
Nothing.
Description
Constructor; creates an instance of the LoadVars object. You can then use the methods of that LoadVars object to send and load data.
Example
The following example creates an instance of the LoadVars object called myLoadVars:
myLoadVars = new LoadVars();
With the Load vars object, you have methods of load, onLoad, or onData. You can use those methods to ensure the data has loaded correctly.....
myLoadVars = new LoadVars();
myLoadVars.load("someFile.php");
myLoadVars.onLoad=function(success){
if(!success){
trace("Failed to load")
}else{
//do something with the loaded info
}
}
zypher2004
04-06-2005, 05:11 AM
could you please make a example .fla for me?
I use macromedia flash MX and I just want to print out the data from the URL into a .swf for now.
thanks,
zypher2004
Hi,
Sending variables with the url itself to a PHP page would look like.....
http://someSite.com/myForm.php?name=NTD&email=webmaster@ntdesigns.net
The question mark symol tells the server and the script that everything that follows comprise variables. One thing to keep in mind is that the GET method has a 1024 character limit and is attached to the URL itself(viewable by all). The POST method attaches variable/name pairs to the header of the HTTP request (can't be seen) and doesn't have a character limit. I dont have a demo handy but it is not a difficult task. Create a PHP script to hold your variables and echo a trace back to flash saying successful or unsuccessful.
zypher2004
04-06-2005, 05:41 AM
Hi,
Sending variables with the url itself to a PHP page would look like.....
http://someSite.com/myForm.php?name=NTD&email=webmaster@ntdesigns.net
The question mark symol tells the server and the script that everything that follows comprise variables. One thing to keep in mind is that the GET method has a 1024 character limit and is attached to the URL itself(viewable by all). The POST method attaches variable/name pairs to the header of the HTTP request (can't be seen) and doesn't have a character limit. I dont have a demo handy but it is not a difficult task. Create a PHP script to hold your variables and echo a trace back to flash saying successful or unsuccessful.
I know PHP pretty well, and I know how to use $HTTP_GET_VARS['whatever'] to get the data from the URL but I want to print that data into my flash animation into a text fiend or something like that.
thanks,
zypher2004
Hi,
You can use the sendAndLoad method of the loadVars object to send variables to a php script and return them to flash.
container = new LoadVars();
container.onLoad = function(success) {
if (!success) {
trace("Failed to load");
} else {
trace("Data is loaded");
trace(container.msg);
//populate the textfields with the returned data from the php script
_root.name.text = _root.container.name;
_root.myTextSave.text=_root.container.myTextSave;
_root.msg.text = _root.container.msg;
}
}
myButton.onRelease = function() {
//You could use the POST method to send the data(more secure), as long
//as the php script uses the GET method, it will return the url appended
//data correctly
_root.container.sendAndLoad("http://someSite.com/myReturn.php?name=NTD&myTextSave=This is some test text.", _root.container, GET);
}
The PHP script would look like.......
<?
$name=$_GET["name"];
$myTextSave=$_GET["myTextSave"];
echo ("&msg=Connected to file!&name=$name&myTextSave=$myTextSave");
?>
NTD
zypher2004
04-08-2005, 02:26 AM
i went out and bought macromedia flash just so I could do this and I dont understand how...:(
All i wat to do is go
http://www.mysite.com/animation.swf?name=bryan&lname=rolfe
and have it put that data into the animation.
thanks,
bryan rolfe
Hi,
Purchasing Macromedia Flash is rather an expensive lesson just to send a variable from Flash to a PHP script and back. I hope the endeavor turns out to be worth your while. I am a fan of Flash and will help as much as I can. Flash is a very dynamic application and if your into graphic design, it is the tool of choice. Graphic design wise, there is nothing around that compares. File size and customization possibilities make Flash hard to compete with. When it comes to application development, Flash is not nearly as advanced or complete as visual basic, Java, C++, or other OOP programming languages, but it is making up ground quickly! O.K..... with my Macromedia Flash praises out of the way,.... back to sending and receiving variables to and from flash using PHP as the backend scripting language.......
Flash can use the "GET" method like this.....
container = new LoadVars();
container.onLoad = function(success) {
if (!success) {
trace("Failed to load");
} else {
trace("Data is loaded");
trace(_root.container.myTextSave);
_root.name.text = _root.container.name;
_root.myTextSave.text=_root.container.myTextSave;
_root.msg.text = _root.container.msg;
}
}
myButton.onRelease = function() {
container.sendAndLoad("http://yourSite.com/myVarsTest.php?name=NTD&myTextSave=This is some test text.", _root.container, GET);
}
Flash can use the "POST" method like this...
container = new LoadVars();
container.onLoad = function(success) {
if (!success) {
trace("Failed to load");
} else {
trace("Data is loaded");
trace(_root.container.name);
_root.name.text = _root.container.name;
_root.myTextSave.text = _root.container.myTextSave;
_root.msg.text = _root.container.msg;
}
};
myButton.onRelease = function() {
container.name = escape("NTD");
container.myTextSave = escape("This is some test text.");
container.sendAndLoad("http://yourSite.com/myVarsTest.php", _root.container, POST);
}
The PHP script would look something like(I am no PHP guru, if this is formatted incorrectly, ...... so be it)......
<?php
$name=$_POST["name"];
$myTextSave=$_POST["myTextSave"];
echo ("&error=NONE&msg=Connected to file!&nameReturn=$name&textTest=&myTextSave");
?>
Here is a zip file demo containing the fla and the PHP script. Upload the script to your site, and change the button file path from "yoursite.com" to your actual site path. The demo currently uses the POST method, but contains the "Get" method also. The "GET" method is commented out. Remove the comment marks and change the PHP script from POST to GET to test that method.
http://ntdesigns.net/quickDemo/sendAndLoad.zip
hope it helps
NTD
Powered by vBulletin™ Version 4.1.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.