Adobe Air AS3 URLRequest Delay
Hi,
I want to make a request to read a url from my apk exported from .fla. The problem is in the first installation, then the request it takes 6 seconds. I do not know what's causing. I open the application 2nd time and request is executed in a second successful.
I attached files and screens here: https://app.box.com/s/unue6ebsgpmkk7jb7yuc
To reproduce the problem you need to uninstall the application and install->run again. Only on the first run is observed the problem.
I will be grateful if someone help me ![]()
MyConf:
Air sdk: 16
Flash CC: 14.1.0.96 ( windows 7 64 )
Thanks!
--------------------------------------------------------------
import flash.utils.Timer;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.events.IOErrorEvent;
import flash.net.URLLoader;
import flash.net.URLRequest;
var global_status:String = "none";
var global_magic_event:int = 0;
var text2screen: TextField = new TextField();
text2screen.x = 10;
text2screen.y = 450;
text2screen.width = 300;
text2screen.height = 100;
text2screen.wordWrap = true;
text2screen.border = true;
text2screen.textColor = 0xffffff;
text2screen.backgroundColor = 0x000000;
text2screen.background = true;
text2screen.text = global_status;
addChild(text2screen);
var xloader: URLLoader = new URLLoader();
var url: String = "http://pastebin.com/raw.php?i=TBwVdkFY&rnd="+randomRange(111,99999);
trace(url);
var request: URLRequest = new URLRequest(url);
try {
xloader.load(request);
xloader.addEventListener(Event.COMPLETE, processData);
xloader.addEventListener(IOErrorEvent.IO_ERROR, errorData);
} catch (e: Error) {
trace("error!!");
global_status = "err #1";
}
function processData(e:Event):void{
trace("Loading Completed");
global_status = "success "+xloader.data.substr(0,250);
}
function errorData(e: Event = null) {
trace("Loading fail!");
global_status = "err #2";
}
// debug screen
var timer_start: Timer = new Timer(1000, 1000);
timer_start.addEventListener(TimerEvent.TIMER, showlog);
timer_start.start();
function showlog(e: TimerEvent): void {
// catch the second where is success
if( global_magic_event==0 && global_status!="none" ) { global_magic_event = e.currentTarget.currentCount; }
text2screen.text = "#" + (e.currentTarget.currentCount*e.currentTarget.delay)/1000 + " second | status ["+global_magic_event+"]: "+global_status;
}
function randomRange(minNum:Number, maxNum:Number):Number {
return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum);
}
