Catching Errors Generated by Flash
package{
import flash.display.*;
public class Main extends Sprite{
public function Main(){
var object:Object = "Definitely Not a Display Object";
try
{
var displayObject:DisplayObject = DisplayObject(object);
} catch (error:TypeError) {
trace("Incompatible cast!");
displayObject = new Sprite();
}
addChild(displayObject);
}
}
}
Related examples in the same category