I have created a form using Flash & actionscript 3. The problem I am having is that I can send the variables to php when stored at the same location as that of the swf file, but if i want to make an android AIR application for the form, I cant address the php file which send me the email. Is it possible to address a remote php file? Please help me, I am stuck at this stage.
Probably you stuck with crossdomain.xml.
The idea that first flash load the policy file and check's permissions: can flash access to this server or not. It's a simple security: to prevent flash doing request's where it shouldn't.
For more information just google by keyword crossdomain.xml.
I found the solution. I just had to use the following code.
var url:String = "php url";
var my_url:URLRequest = new URLRequest(url);
my_url.method = URLRequestMethod.POST;
my_url.data = my_vars;
var my_loader:URLLoader = new URLLoader();
my_loader.dataFormat = URLLoaderDataFormat.VARIABLES;
my_loader.load(my_url);
Related
php bloack as3 after trying load variables in setinterval loop. i guess the title explain it all. actually i have flash widget that use URLLoader to grab some php variables and it works perfect but this urlloader is in setinterval loop that happens every 2 mins the problem is it work for several times well then after that php blocks the ip that loading the variables (using flash widget) and gives no response. i tried to search about this subject but found nothing especially that flash is outdated but i am using this flash in place which dont support except flash no js... idk what is the problem exactly but i got huge feeling its a server side issue and idk how to fix it. thought to share my issue here maybe someone can help. btw it blocks the ip of the user that been using the flash for long not for all but after 2-3 mins it unblocks the ip again and works again
btw when my ip is blocked by php i get this error as return by flash:
2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs.
and by searching up found that this means the flash got nothing back from php request.
the as3 code is as simple as that:
submit_btn.addEventListener(MouseEvent.CLICK, btnDown);
function btnDown(event:MouseEvent):void {
var variables:URLVariables = new URLVariables();
var varto:URLRequest = new URLRequest("http://url/dir/script.php");
varto.method = URLRequestMethod.POST;
varto.data = variables;
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
variables.somecode = "code";
varLoader.load(varto);
function completeHandler(event:Event):void{
var Var1fromphp = event.target.data.var1ofphp;
var Var2fromphp = event.target.data.var2ofphp;
from1_txt.text = Var1fromphp;
from2_txt.text = Var2fromphp;
trace("traced:" + event.target.data);
}
}
thanks and appreciate all the replies/support
found the problem wasnt php/server side its all about encoding then decoding the url for the variables cuz some vars had "&" character which interfer with the reponse.
I'm creating Flash "memory" game, Idea to discover 2 equal cards. Here is timer which count time in how many seconds all cards are discovered. After complete game timer stops. How can I get this time from swf file and write to database? As I understand I need take this data with php file, but don't have idea how to do It.
As I know I need to do something like that:
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, scoreSaveResponse,false,0,true);
var request:URLRequest = new URLRequest("http://mysite.com/score.php");
var urlVars:URLVariables = new URLVariables();
urlVars.time = timer.currentCount;
urlVars.userName = "yourUserName";
request.method = URLRequestMethod.POST;
urlLoader.data = urlVars;
urlLoader.load(request);
function scoreSaveResponse(e:Event):void {
//whatever you return from the php page is found in urlLoader.data
}
//LondonDrugs_MediaServices's code
But could someone explain me how to do It, because If I use this part of code nothing happens, I don't get any errors, but I don't know how to use this in php or how to write it to database.
My app will be used for Facebook, that's mean username will be used the same as in Facebook. So I think first i need to get time to PHP than get username from Facebook and write both to database.
Thank you for answers.
Try to use AMFPHP.
AMFPHP makes it possible to write a service for your application where you can store your SWF values into a PHP database.
http://www.silexlabs.org/amfphp/
I'm using facebook php sdk to get friend list of an user. But I'm strugling to get that list to flash.
The idea is that the list is always new, depending from the user loading the application. So what I need is one .html file which is loaded with php script to proccess friend list and embedded flash .swf to which php would pass information.
How can I achieve this? thanks
There are two ways to do it:
Set the flashvars to the data you want to pass to the Flash file. Since the friend list rarely changes, that should work.
Or use a URLLoader:
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest("http://example.com/yourscript.php");
loader.addEventListener("complete", loader_complete);
loader.loader(request);
private function loader_complete(event:Event):void {
var scriptData:String = event.currentTarget.data;
// process data
}
So here's the deal,
I'm trying to save variables from flash to PHP, however when i try to do so the php script seems to not acknowledge that i'm logged in.
This would mean that the session doesn't arrive in flash. How do i fix this?
AS3 added:
var bitmap:BitmapData = new BitmapData(loaded_swf.width, loaded_swf.height - 273, false, 0x000000);
var saveSelfyRequest:URLRequest = new URLRequest('urlhere.php');
saveSelfyRequest.contentType = "application/octet-stream";
saveSelfyRequest.method = URLRequestMethod.POST;
var bytes:ByteArray = PNGEncoder.encode(bitmap);
requestLoader = new URLLoader();
saveSelfyRequest.data = bytes;
requestLoader.load(saveSelfyRequest);
requestLoader.addEventListener(Event.COMPLETE, loaderCompleteHandler);
I don't know Flash or ActionScript, but once I had a similar problem while developing a Java Applet which interacts with a php application which requires login. The problem was the fact that the applet make independent requests to the web app and not through the browser, so it was not passing a proper session id to the php app.
I solved this problem by passing a session_id parameter to the applet (using a param tag) and then making post requests to the app by setting a cookie with the value PHPSESSID=xxxxx in the HttpClient used for the request.
Maybe you can try the same inside ActionScript.
To get confirms on my theory you can print all received headers in the php application to see if the cookie header is sent in the request.
I have a Flex app which is taking XML data and posting it to be saved to a file on the server, where it can be read later. Using tip found here on SO, I have the Flex part down (I think), but I am not a PHP programmer so I am unclear as to what should be in the PHP that handles the URLRequest:
protected function saveBtn_clickHandler(event:MouseEvent):void {
var saveData:XML = new XML();
saveData = myManager.exportFullXML();
trace(saveData);
var uploader:URLLoader = new URLLoader();
var data:URLVariables = new URLVariables();
data.xml = saveData.toXMLString();
trace(data.xml);
var req:URLRequest = new URLRequest("http://locahost/saveXML.php");
req.data = data;
uploader.load(req);
}
First of all ensure that your request is a post one (it isn't mandatory, but it is a good practice as XMLs tend to be lengthy):
req.method = URLRequestMethod.POST;
The PHP part is simple as PI. You get the received data from the $_POST superglobal and you write it to your file with file_put_contents.
<?php
file_put_contents('path/to/file', $_POST['data']);
?>
Note: remember that anyone can post to that PHP file, so you need to implement some security mechanism to ensure you only save what your application sends.