03.05.2013 Views

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

FLASH® LITE™ 2.x - Adobe Help and Support

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

output: DivideByZeroError -> Unable to divide by zero.<br />

} catch (e_err:DivideByZeroError) {<br />

// divide by zero error occurred<br />

trace(e_err.name+" -> "+e_err.toString());<br />

} catch (e_err:Error) {<br />

// generic error occurred<br />

trace(e_err.name+" -> "+e_err.toString());<br />

}<br />

To add a custom error, add the following code to a .AS file called DivideByZeroError.as <strong>and</strong><br />

save the class file in the same directory as your FLA document.<br />

class DivideByZeroError extends Error {<br />

var name:String = "DivideByZeroError";<br />

var message:String = "Unable to divide by zero.";<br />

}<br />

See also<br />

throw statement, try..catch..finally statement<br />

toString (Error.toString method)<br />

public toString() : String<br />

Returns the string "Error" by default or the value contained in Error.message, if defined.<br />

Returns<br />

String - A String<br />

Example<br />

In the following example, a function throws an error (with a specified message) if the two<br />

strings that are passed to it are not identical:<br />

function compareStrings(str1_str:String, str2_str:String):Void {<br />

if (str1_str != str2_str) {<br />

throw new Error("Strings do not match.");<br />

}<br />

}<br />

try {<br />

compareStrings("Dog", "dog");<br />

// output: Strings do not match.<br />

} catch (e_err:Error) {<br />

trace(e_err.toString());<br />

}<br />

336 ActionScript classes

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

Saved successfully!

Ooh no, something went wrong!