actionscript 3 - How to force debug player not to launch a debug window, but silently output a message -
i want test cpu intensive swf file in firefox browser. problem whenever unhandled error encountered, shows debug window. trying handle each , every error,but becomes difficult because @ each error, browser hangs completely. , have restart. so, there way, eg. through compiler etc, can tell debug player, not show in window, , halt process, other way show output ?
i use general try..catch block. still many times, window pops up. seems like, try..catch block not work in every case.
here simple example : code, lists files in directory, list component. when clicked, selected file, must load. so, there no problem swf or picture files ( jpg, png etc). say, click upon "fla" should not load. error window pops unpredictably : error #2044: unhandled ioerrorevent:. text=error #2124: loaded file unknown type.
var loader:loader =new loader(); loader.contentloaderinfo.addeventlistener(event.complete,doneload); loader.contentloaderinfo.addeventlistener(ioerrorevent.io_error,loadingerror); loader.contentloaderinfo.addeventlistener(progressevent.progress,updateinfo); function filelist_lst_click(e:mouseevent):void { doload(); } function doload(e:mouseevent=null):void { try { loader.load(new urlrequest(filelist_lst.selecteditem.label)); } catch(e:error) { trace(e.tostring()); } //infobox.text="loading starts..."; } function updateinfo(e:progressevent):void { trace("loading: "+string(math.floor(e.bytesloaded/1024))+" kb of "+string(math.floor(e.bytestotal/1024))+" kb."); } function loadingerror(e:ioerrorevent):void { trace("there has been error loading image."); } function doneload(e:event):void { try { loader.contentloaderinfo.removeeventlistener(event.complete,doneload); loader.contentloaderinfo.removeeventlistener(progressevent.progress,updateinfo); loader.contentloaderinfo.removeeventlistener(ioerrorevent.io_error,loadingerror); displayview_mc.addchild(loader); } catch(e:*) { trace("error loading!"); } }
use uncaughterrorevent in root of app. catch uncaught errors inside app ps: need use flash player +10.x.x
sample app
<?xml version="1.0" encoding="utf-8"?> <s:windowedapplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/halo" applicationcomplete="applicationcompletehandler();"> <fx:script> <![cdata[ import flash.events.errorevent; import flash.events.mouseevent; import flash.events.uncaughterrorevent; private function applicationcompletehandler():void { loaderinfo.uncaughterrorevents.addeventlistener( uncaughterrorevent.uncaught_error, uncaughterrorhandler); } private function uncaughterrorhandler(event:uncaughterrorevent):void { // use prevent default , stoppropagation prevent flash debug window appear event.preventdefault(); event.stopimmediatepropagation(); if (event.error error) { var error:error = event.error error; // error } else if (event.error errorevent) { var errorevent:errorevent = event.error errorevent; // error } else { // non-error, non-errorevent type thrown , uncaught } } private function clickhandler(event:mouseevent):void { throw new error("gak!"); } ]]> </fx:script> <s:button label="cause error" click="clickhandler(event);"/> </s:windowedapplication>
Comments
Post a Comment