lan14n
47 posts
|
Hey! [AS3 Flash]
So I’m trying to test what would happen if my internet connection went out. I can’t seem to catch “Error opening URL” error. I tried:
try {
loader.load(new URLRequest(s));
} catch (e:Error) {
trace("CATCH",e);
}
It doesn’t work. I also tried IOErrorEvent and I can’t get that to work also.
Flash traces the error:
Error opening URL <error>
SecurityError: Error #2000: No active security context.
But I want to be able to display it in flash.
I was wondering how to do it.
thanks
|
Senekis93
4090 posts
|
Add a textfield and set its text to e.message.
Also, instead of a try/catch block, add an IOErrorEvent.IO_ERROR listener to the loader.
|
lan14n
47 posts
|
I cant seem to make it work… I tried doing this.
public function runYoutube(s:String) {
loader = new Loader();
var context:LoaderContext = new LoaderContext();
context.checkPolicyFile = true;
context.securityDomain = SecurityDomain.currentDomain;
context.applicationDomain = ApplicationDomain.currentDomain;
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
loader.addEventListener(IOErrorEvent.IO_ERROR, onURLError);
Security.allowDomain("www.youtube.com");
loader.load(new URLRequest(s));
}
private function onURLError(event:IOErrorEvent):void {
var txtError:Window_Text = new Window_Text( "", 0, 128, Game_System.GAME_PIXEL_WIDTH, 32 );
txtError.setFormat(Window_Text.DOUBLECENTER);
txtError.text = "Error connecting to youtube:\n" + event + "\nPress next to continue...";
addChild( txtError );
}
|
NineFiveThree
1370 posts
|
Nice LoaderContext object you got there, do you intend to actually use it ? ;)
|
lan14n
47 posts
|
I copy pasted it from a tutorial about running a youtube video using actionscript. I saw the tutorial before stumbling upon the actual api with some examples. I have no idea what its for.
I’ve change the code to what the api example was, but I still can’t catch the error :(
public function runYoutube(s:String) {
Security.allowDomain(“www.youtube.com”);
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
loader.addEventListener(IOErrorEvent.IO_ERROR, onURLError);
loader.load(new URLRequest(s));
}
private function onURLError(event:IOErrorEvent):void {
trace(“CATCH”,event);
var txtError:Window_Text = new Window_Text( "", 0, 128, Game_System.GAME_PIXEL_WIDTH, 32 );
txtError.setFormat(Window_Text.DOUBLECENTER);
txtError.text = “Error connecting to youtube:\n” + event + “\nPress next to continue…”;
addChild( txtError );
}
|
DPbrad
1197 posts
|
Originally posted by lan14n:I copy pasted it from a tutorial
Uh-oh…
Your problem is here
loader.contentLoaderInfo.addEventListener(Event.INIT, onLoaderInit);
loader.addEventListener(IOErrorEvent.IO_ERROR, onURLError);
Your first event listener you add to the contentLoaderInfo (as you should with a Loader object), but you then add the other event listener directly to the loader object, which I don’t think will ever get dispatched.
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onURLError);
That’s what it should be.
|
lan14n
47 posts
|
woot! it worked thanks! :D
|