Standalone flash player navigateToURL using POST fails - actionscript-3

Since Flash plugin has reached EOL, the only way to still use my RIA is to use the standalone version of Flash player.
I've noticed an issue with the following piece of code while testing the migration:
var request:URLRequest = new URLRequest("/utils/function");
request.contentType = "application/x-www-form-urlencoded";
request.method = URLRequestMethod.POST;
var data:URLVariables = new URLVariables();
data.x = encodeURIComponent(1);
data.y = encodeURIComponent(2);
data.z = encodeURIComponent('some value');
request.data = data;
navigateToURL(request, "_blank");
The standalone version of flash (v30.0.0.134) makes a GET request instead of the instructed POST method. The browser plugin (v32.0.0.238) opens the page correctly in a new tab as a POST request.
Why does the standalone flash convert my request in to a GET? Anybody out there who can shed some light on this issue?

I don't know if it qualifies as a answer, but we use this to make a POST request:
handleService.url='.../something.ashx';
handleService.method = URLRequestMethod.POST;
var prm:Object=new Object();
prm.par1 = "asd";
prm.content=encodedData;
prm.fileName=FileName;
handleService.send(prm);
Instead of going for a standalone version of flash, you can package the app as a Adobe AIR runtime. We still use some apps written in Flex and have no issues with them.
If running on windows, you can package it as a native runtime and works nice.

Related

SSL (TLS) in as3crypto

I am facing some issues around SSL (HTTPS calls) in an Adobe Air application. There is a bug on Adobe's list and its the exact same issue that I've bumped into:- https://forums.adobe.com/thread/1116924
The recommended solution (unless Adobe fixes this - they haven't done so in over 2 years) is to use as3crypto's SSL.
Can anyone here help me with the same? Right now, my HTTPService, which uses the default built in Adobe's SSL capabilities, looks like:-
var params:Object = getPOSTParameters();
var _httpservice:HttpService = new HTTPService();
_httpservice.url = "https://myserver_url";
_httpservice.resultFormat = "text";
_httpservice.contentType="application/x-www-form-urlencoded";
_httpservice.method = "POST";
_httpservice.concurrency = "multiple";
_httpservice.requestTimeout=600000;
_httpservice.showBusyCursor = false;
_httpservice.addEventListener(IOErrorEvent.IO_ERROR, httpIOError);
_httpservice.addEventListener(HTTPStatusEvent.HTTP_RESPONSE_STATUS, httpResponseStatus);
var responder:Responder = new Responder(onResult, onError);
var token:AsyncToken = _httpservice.send(params);
token.addResponder(responder);
How should I go about implementing the same with as3crypto? Any example/ code pointers will be really helpful
There is no 100% working solution, at least I don't know it. When I needed https in Adobe Flash I used as3httpclient library where AS3Crypto used for implementig TLSSocket. It's much easier than write you own. But beware it's buggy and it isn't works in some cases.
EDIT:
There is documentation available here for me it was enough, there is no difference between http and https request (except URL).

how to load and edit a sql database from adobe flex builder 4.6 air program

Alright I have my sqldb hosted online and can access it using phpmyadmin what i would like to do is create tables and add items to the tables via adobe flex builder 4.6 desktop AIR application.
Anyone know if i am able to do this, the idea for the program is so person at position A can enter a name and person at position B can then use his program to read those names
According to Accessing mysql from Adobe flex/AIR, AIR is unable to access MySQL servers directly, so you'll have to use web services or some custom API do to this. But yeah, sure it's possible to do what you want.
I agree with Isaac. However, I want to add that it is good coding practices to not allow client side applications modify a database directly. In the applications that I have built, I like to use PHP to set-up an API that then interacts with the database. The AIR application then the interaction with the API using HTTP Requests.
Following code shows how to perform a URL request from the Adobe Website.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html
var url:String = url location of the API;
var request:URLRequest = new URLRequest(url);
var variables:URLVariables = new URLVariables(); //create variables to pass to the API
variables.exampleSessionId = new Date().getTime(); //create variables to pass to the API
variables.exampleUserLabel = "guest"; //create variables to pass to the API
request.data = variables; //Add the variables to the request
request.method = URLRequestMethod.POST; //Set the method of the Request GET, POST, PUT
navigateToURL(request); //Executes the request
You'd probably like something like https://backendless.com/ for this.

Flex mobile HTTPMultiService set user-agent

I'm developing a Flex mobile application and I'm using the Http Services within FlashBuilder (4.7) to send/receive data. I'm having some issues with how the server is setup to accept calls (from the mobile platform) and apparently setting the User-Agent in Android works just fine. But I can't seem to be able to find a way to set the User-Agent in FlashBuilder.
Any ideas?
Thanks
var request:URLRequest=new URLRequest('URL_OF_YOUR_SERVICE');
var userCredential:Object = new Object();
userCredential['user_email'] = 'YOUR_MAIL';
userCredential['user_password'] = 'YOUR_PASSWORD';
request.data=JSON.stringify(userCredential);// use this if your service accept json only else give Object directly
request.method = 'post';// specify here method GET or POST
var loader:URLLoader=new URLLoader();
loader.addEventListener(Event.COMPLETE, userLoginCompleteHandler);
loader.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorHanlder);
try
{
loader.load(request);
}
catch(error:Error)
{
trace("Login Error:: "+ error.toString());
}
may this will help you, here i have defined userLoginCompleteHandler and onIOErrorHanlder event listner for result and fault.
No, you can't set the User-Agent header in Flex.
From this Adobe forums post:
Note again that since the underlying Flash API is flash.net.URLLoader there are certain headers that
you cannot send. For details, please see the docs for flash.net.URLRequestHeader.
The URLRequestHeader docs say:
In Flash Player and in Adobe AIR content outside of the application
security sandbox, the following request headers cannot be used:
... User-Agent, ...

Flash player stuck at Frame 1 after calling a function

I'm working in a flash CS6 and I'm having a trouble: After calling a function, player freezes at frame 1. This not happend during Ctrl+ENTER preview, but when I play the .swf file published (using flash player or opening it on a web browser, doesn't matter) is when the problem begin.
This is the code:
import flash.display.MovieClip;
var code:int = 0
var temp:int = 0;
var _xmlURL:String = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid=368335%20and%20u=%27c%27";
var _xmlData:XML;
function loadXML(xmlURL:String):void {
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest(_xmlURL);
loader.load(request);
loader.addEventListener(Event.COMPLETE, loadData);
}
function loadData(event:Event):void{
_xmlData = new XML(event.currentTarget.data);
var dataG:XMLList = _xmlData.results.channel.item.elements();
code = dataG[5].#code;
temp = dataG[5].#temp;
trace(code);
trace(temp);
}
loadXML(_xmlURL);
I'm not used to use as3, I don't know if I'm using it right.
As you can see, the code reads an external xml file using "URLLoader" and its method ".load".
Thanks for your help.
BTW, I've already tried to play the published ".swf" file in other PCs (xp, seven, 8), one of them with Windows recently installed (seven).
Most likely (because you're loading in resources from the internet, and it works when you test), this has to do with the security settings of your application.
Go to your publish settings file -> publish settings.
You'll see a drop down labelled Local playback security. Ensure this is set to access network only and not the default acess local only.
This hangs up a lot of people when they first start using flash.
It's always good practice too, to listen not just for the COMPLETE event on your loaders, but also for error events such as:
loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandlerFunction);
loader.addEventListener(IOErrorEvent.NETWORK_ERROR, ioErrorHandlerFunction);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandlerFunction);
In your case, it's probably throwing a security error.

Need alternative to POST data using navigateToURL that works with Pepper Flash plugin

As most people know, Google messed several flash applications after starting using Pepper Flash plugin in Chrome.
I'm getting the same problem, but it can't be solved with external interface call, as I need to post data using POST, to a php file.
My application basicaly takes a screenshot, and post to a php file. Worked fine before, but now with Pepper Flash, nothing happens.
This is the piece of code that POSTs the data.
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;
navigateToURL(URL_TO_THE_PHP_FILE, "_self");
Is there a workaround for this? My website that uses this application have thousands visitors daily, and most users woudn't know how to disable pepper flash.
thanks.
To upload image, you will need URLLoader, image encoding algorithm, and some contract(names of variables in POST's body, encoding algorithm, etc) with you server-side
var urlRequest : URLRequest = new URLRequest();
var urlLoader : URLLoader = new URLLoader();
var urlVars : URLVariables = new URLVariables();
//Take from the image bytes, for example with JPEGEncoder
//Endoce ByteArray for example with Base64
//If image is big, you can split on several parts
urlVars.image = Base64.encode(imageData);
urlRequest.url = $snapshotUploadURL;
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = urlVars;
// create the image loader & send the image to the server;
urlLoader.addEventListener(Event.COMPLETE, onComplete);
urlLoader.load(urlRequest);
BloodyCrypto is very helpful library for this task.