actionscript 3 - Try Catch With Sound Element into Flash CS5-as3 -
hi all—anyone has idea why code doesn’t work?
with other load [example image] work perfect sound...no :(
mysoundurl = new urlrequest(var+".mp3"); mysoundurldefault = new urlrequest("default.mp3"); try{ sound.load(mysoundurl); }catch(e:ioerrorevent){ trace("can't load sound: "+e); sound.load(mysoundurldefault); }
this error i’m getting:
error #2044: unhandled ioerrorevent:. text=error #2032: stream error
thanks , day!
you not use try/catch loaders. here's instead:
sound.addeventlistener(ioerrorevent.io_error, onioerrorevent); sound.load(mysoundurl); private function onioerrorevent(e:ioerrorevent):void{ trace(e); trace(e.message); // ^ show file tried load , failed @ e.currenttarget.removeeventlistener(ioerrorevent.ioerror, onioerrorevent); e.currenttarget.removeeventlistener(event.complete, oncomplete; // ^ don't forget clean listeners! }
the reason is, you've seen, uncaught error not tell helpful, such sound failed load, or url tried contact was.
i think @alexander sobolev on right track first guess, based on fact still error. handling errors loaders different handling errors synchronous code, , try/catch not here.
if want try playing alt sound on fail first one, you'd in onioerrorevent function.
other times you'd listen ioerrorevent when using loader load swf or image file
loader.contentloaderinfo.addeventlistener(ioerrorevent....
or urlloader
urlloader.addeventlistener(ioerrorevent...
Comments
Post a Comment