On Android the Loader/URLLoader etc cause insane app freezes and stuttery animation, we’ve seen it in effect with google analytics but also with very simple json and images. Using haxe.Http to fetch files also blocks.
Is there an asynchronous way to do this within haxe/openfl?
What’s that? I can’t find much on Google about it. We’re using Java where we can so we can put downloads etc on background threads but it’s not very cross-platform.
sorry, my fault… it is supported only in flash, no openfl. (sometimes I look on google for AS3 answers, and often they are supported in openfl as well… not this case )
I’ve got the same problem anyway, I am looking around for something really async.
(when I call the .load(…) sometimes it freeze for half a second on almost every platform (ios, mac, windows, linux), especially if there is a slow connection)
import cpp.vm.Thread;
function loadAssets()
{
//loader stuff
}
function main()
{
var worker:Thread = Thread.create(loadAssets);
worker.sendMessage(Thread.current ());
}
update
I’ve just tested this on windows and it doesn’t seem to work on sending urlrequestes The stuttering is still there. Works fine with drawing lots of bitmapdatas though…
It supports HTTP requests (HTTP/1.1), only GET method.
and right now it is written to get Strings (not the best to load raw data, like bitmaps) but good for text (html, json, csv… etc etc)
I’m planning to developing it more, it is just a prototype.
Basically it use the standard URLRequest/URLLoader on flash and html5
but on CPP, NEKO and JAVA it supports multi-threading.
In my case there were a freeze, sometimes, especially on slow connection.
Using this class there is no more freeze, and it is compatible with all targets in a way or another.
How to use it?
Basically you can copy the class in your project and use it as it follows:
package ;
class Main {
function new() {
//AsyncHttpRequest.logEnabled = true;
AsyncHttpRequest.send("http://fredfgtaefc.com:8080/mypage?field=test&field2=test",function(response:AsyncHttpResponse){
trace(response.request,response.status,response.time);
});
AsyncHttpRequest.send("http://en.wikipedia.org/wiki/Haxe",wikipediaPage);
AsyncHttpRequest.send("http://en.wikipedia.org/wiki/OpenFL",wikipediaPage);
}
function wikipediaPage(response:AsyncHttpResponse) {
trace(response.request,response.status,response.time);
if(response.content==null) {
trace('error');
} else {
trace('done');
}
}
}
in the AsyncHttpResponse you get 4 properties request: the original url requested status: 0 if error otherwise a normal HTTP Response Status time: seconds elapsed between the request and the response content: a string with the response content
@ben if you want to test it and see if it can be useful to you please do it.
if you like it and you want to improve it please fork it and make a pull request.
News:
it supports HTTP/1.1 almost completely (POST, GET, PUT, DELETE) with content payload on the request.
also I’ve made it a little bit more organised with an Request Object and a Response Object.
You can see a good example looking at the README on the repository
Haxelib
I’m going to submit on haxelib very soon (as soon as I recover my password )
sorry I didn’t catch well,
is it possible to send and get request?
I mean I have a an app that sends the player’s scores to a web service in order to update the leader board of the app???
My bad I am still stuck on openfl 2.2.8 because a project I am making is having hard time to run on anything later up to openfl 3.1.1(Still have to figure out why)
I was just looking at sending score to a webservice and retrieving a leaderboard and I bumped into this post.
URLLoader is built-in tool in OpenFL and it works good as far as I know (it did have some problems of freezing for few moments from time to time and that lead me to develop akifox-asynchttp), but my implementation offers an api common to all targets, provides a lot more options, it is usually faster in fetching a request and it does not need OpenFL (although it is obviously compatible with it).
To answer @ray_diama question, YES, it does send a request and get a response.
Look at the code or just the README to understand better what it does.