-
Notifications
You must be signed in to change notification settings - Fork 285
/
pubnub.as
47 lines (40 loc) · 1.46 KB
/
pubnub.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package {
import flash.external.ExternalInterface;
import flash.display.Sprite;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.system.Security;
import flash.utils.setTimeout;
public class pubnub extends Sprite {
Security.allowDomain("*");
Security.allowInsecureDomain("*");
ExternalInterface.addCallback( "get", function(
id:Number,
url:String
):void {
function handler(e:Event):void {
var loader:URLLoader = URLLoader(e.target)
, data:String = loader.data
, timeout:int = 1;
if (e.type == 'securityError') {
data = '[1,"S"]';
timeout = 1000;
}
setTimeout( function delayed():void {
ExternalInterface.call( "PUBNUB.rdx", id, escape(data) );
loader.close();
}, timeout );
}
var loader:URLLoader = new URLLoader();
loader.addEventListener( Event.COMPLETE, handler );
loader.addEventListener( IOErrorEvent.IO_ERROR, handler );
loader.addEventListener(
SecurityErrorEvent.SECURITY_ERROR, handler
);
loader.load(new URLRequest(url));
});
}
}