View Full Version : php to flash?
Macsy
05-08-2007, 01:11 PM
Hi. How do i send a singel Php variable to flash ? Is this hard?
jakattak
05-08-2007, 01:42 PM
Depends on when you want to send it. If it's a variable that will remain constant in an embeded swf, you can include it in a URL string... whatever.swf?variable=12
If you want to get the variable sometime after you've started the Flash piece (via some action or event) you can use something like loadVariables or xml.load:
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = function() {
_root.variablename = xmlData.firstChild.attributes.value1;
}
xmlData.load("xmltest.php");
Then make sure your php file spits out something formatted similar to:
<variablename value1="0" />
There are other ways to do it. This is just one set of options.
Macsy
05-08-2007, 02:09 PM
i dont understand that code, at all... I so there no way for flash to read POST or GET data ?
McGuffin
05-08-2007, 02:34 PM
i dont understand that code, at all... I so there no way for flash to read POST or GET data ?
Yes, there is, he just posted an extremely odd way of getting the PHP var.
AS3:
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://www.mysite.com/file.php");
loader.load(request);
loader.addEventListener(Event.COMPLETE, onComplete);
function onComplete(e:Event) {
var loader:URLLoader = e.target as URLLoader;
if(loader != null) {
trace(loader.data);
}
}
Macsy
05-08-2007, 03:07 PM
Thanks, still. dont know how to use it :)
Please explain if you want to :)
gvozden
05-08-2007, 03:08 PM
you can also look for amfphp 1.9 release, great stuff
very easy to implement and great speeds
http://amfphp.org/
:( whoa what happened to their home site
http://osflash.org/projects/amfphp info but no download
McGuffin
05-08-2007, 04:56 PM
Sorry mate, I'll explain...
// import necessary packages...
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
// new instance of the URLLoader class used to load the data in...
var loader:URLLoader = new URLLoader();
// the URLRequest instance is given the the loader, the URL used links to your PHP file
var request:URLRequest = new URLRequest("http://www.mysite.com/file.php");
// tell loader to load the request instance
loader.load(request);
// we want to know when the variables are loaded, so we add a COMPLETE event
loader.addEventListener(Event.COMPLETE, onComplete);
// this function is called on complete...
function onComplete(e:Event) {
// check to see that the loader has valid data...
var loader:URLLoader = e.target as URLLoader;
if(loader != null) {
// loader.data will store your variables you loaded from the PHP file
trace(loader.data);
}
}
[/QUOTE]
Use Flash Help (press F1 with Flash open) to check any specifics. Your PHP needs to output something like...
&variableName=value1&var2=value2&
dgsk387
01-16-2008, 10:46 PM
I understand how to import the data but how can I use this data OUTSIDE of the function onComplete?
I need to create a global variable or something that stores the imported data so I can use that variable outside of the function like in conditional statements and such.
How can I do this?
Thanks!
vBulletin® v3.8.4, Copyright ©2000-2010, Jelsoft Enterprises Ltd.