error handling

0 views
Skip to first unread message

sitron

unread,
Aug 26, 2008, 9:05:09 AM8/26/08
to masapi
hello!
first thanks for masapi, it's great!

i m trying to figure out how you created your error handling system.
It seems that none of the examples provided use an error listening
mechanism.

if i m not wrong, the event "massloader.file_close" is fired anyway
(whether the file was successfully loaded or not) and that you can
check the "closeEvent" property of the event to check if there was an
error.

is it the way to go?

In my experience, when the closeEvent is of type ioError, the
massloader tries to reload the file 2 times before giving up... is
that correct? But if i try to call the stop() method after an ioError
(to prevent the 2 reloading), it throws an error that there is no file
to load...

what i want to do is: if there is an error, get the file and stop the
loading.
thanks for your help.

Cédric Tabin

unread,
Aug 26, 2008, 9:55:27 AM8/26/08
to mas...@googlegroups.com
Hello,

The behavior that you describes (masapi reload file after an error) is due to the loading policy :) You can very simply avoid this behavior :
var cml:CompositeMassLoader = new CompositeMassLoader();
var policy:DefaultLoadPolicy = cml.massLoader.loadPolicy as DefaultLoadPolicy;

policy
.reloadTimes = 1;
//...
The default behavior is set to 3, so the file will be reloaded 2 times until masapi jumps to the next one ! And for the error handling, you can use the FILE_CLOSE event as you do, or directly put some listener on the ILoadableFile (it will dispatch IOErrorEvent and SecurityErrorEvent as usual).

Regards,
Cedric

sitron

unread,
Aug 26, 2008, 10:39:45 AM8/26/08
to masapi
cool! that was quick Cédric!
loadPolicy is what i was looking for. thanks!

is there a way to say for each file that i add to the massLoader if it
is mandatory or not (on failure, if mandatory -> stop queue, if not
continue)?

i could implement that in the Event.complete handling using the (very
handy) loadInfo.filesError array but it would be easier if it could be
done automatically.

thanks!

Cédric Tabin

unread,
Aug 26, 2008, 11:26:35 AM8/26/08
to mas...@googlegroups.com
Hello,

That is not directly possible, since this functionnality hasn't been implemented... In fact, it is very easy to do it : you just need to extend the DefaultLoadPolicy (or implements ILoadPolicy) and do what you want. You can put any property you want into the ILoadableFile.properties property (that's a IMap object) :

myFile.properties.put("isMandatory", true);


And then (if you extends DefaultLoadPolicy) :

public function processFile(file:ILoadManager, closeEvent:Event):ILoadManager
{
if (!file.properites.getValue("isMandatory")) return super.processFile(file, closeEvent);

//the file is mandatory
if (closeEvent == Event.COMPLETE) return null; //ok !
else return file; //reload it !!!
}
Finally you just need to put your new class as LoadPolicy for your MassLoader :)

Regards,
Cedric

sitron

unread,
Aug 27, 2008, 8:00:40 AM8/27/08
to masapi
waw!
thanks a lot for the extensive explanation.
Reply all
Reply to author
Forward
0 new messages