230
ActionScript language elements
try {
checkEmail("Joe Smith");
}
catch (e) {
error_txt.text = e.toString();
}
In the following example, a subclass of the Error class is thrown. The
checkEmail()
function
is modified to throw an instance of that subclass.
// Define Error subclass InvalidEmailError // In InvalidEmailError.as:
class InvalidEmailAddress extends Error { var message = "Invalid email
address."; }
In a FLA or AS file, enter the following ActionScript in Frame 1 of the Timeline:
import InvalidEmailAddress;
function checkEmail(email:String) {
if (email.indexOf("@") == -1) {
throw new InvalidEmailAddress();
}
}
try {
checkEmail("Joe Smith");
}
catch (e) {
this.createTextField("error_txt", this.getNextHighestDepth(), 0, 0, 100,
22);
error_txt.autoSize = true;
error_txt.text = e.toString();
}
See also
Error
try..catch..finally statement
try {
// ... try block ...
} finally {
// ... finally block ...
}
try {
// ... try block ...
} catch(
error
[
:ErrorType1
]) {
// ... catch block ...
} [catch(
error
[
:ErrorTypeN
]) {
// ... catch block ...
}] [finally {
// ... finally block ...
Summary of Contents for FLASH 8-ACTIONSCRIPT 2.0 LANGUAGE
Page 1: ...ActionScript 2 0 Language Reference ...
Page 1352: ...1352 ActionScript classes ...