13.08.2012 Views

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

ACTIONSCRIPT 3 Developer’s Guide en

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ACTIONSCRIPT</strong> 3.0 DEVELOPER’S GUIDE<br />

Handling errors<br />

The final method in the ApplicationError class is toString(). This method overrides the function defined in the<br />

Error class so that you can customize the pres<strong>en</strong>tation of the error message. The method returns a string that id<strong>en</strong>tifies<br />

the specific error number and message that occurred.<br />

public override function toString():String<br />

{<br />

return "[APPLICATION ERROR #" + id + "] " + message;<br />

}<br />

Defining the FatalError class<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The FatalError class ext<strong>en</strong>ds the custom ApplicationError class and defines three methods: the FatalError constructor,<br />

getTitle(), and toString(). The first method, the FatalError constructor, takes a single integer argum<strong>en</strong>t,<br />

errorID, and sets the error’s severity using the static constant values defined in the ApplicationError class, and gets<br />

the specific error’s error message by calling the getMessageText() method in the ApplicationError class. The<br />

FatalError constructor is as follows:<br />

public function FatalError(errorID:int)<br />

{<br />

id = errorID;<br />

severity = ApplicationError.FATAL;<br />

message = getMessageText(errorID);<br />

}<br />

The next method in the FatalError class, getTitle(), overrides the getTitle() method defined earlier in the<br />

ApplicationError class, and app<strong>en</strong>ds the text “-- FATAL” in the title to inform the user that a fatal error has occurred.<br />

The getTitle() method is as follows:<br />

public override function getTitle():String<br />

{<br />

return "Error #" + id + " -- FATAL";<br />

}<br />

The final method in this class, toString(), overrides the toString() method defined in the ApplicationError class.<br />

The toString() method is<br />

public override function toString():String<br />

{<br />

return "[FATAL ERROR #" + id + "] " + message;<br />

}<br />

Defining the WarningError class<br />

Flash Player 9 and later, Adobe AIR 1.0 and later<br />

The WarningError class ext<strong>en</strong>ds the ApplicationError class and is nearly id<strong>en</strong>tical to the FatalError class, except for a<br />

couple minor string changes and sets the error severity to ApplicationError.WARNING instead of<br />

ApplicationError.FATAL, as se<strong>en</strong> in the following code:<br />

Last updated 6/6/2012<br />

74

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!