User Guide

268 Handling Errors
Status-based error events
The status-based error events are related to the
netStatus and status properties of the
networking and communication classes. If Flash Player encounters a problem when
reading or writing data, the value of the
netStatus.info.level or status.level
properties (depending on the class object youre using) is set to the value
"error". You
respond to this error by checking if the
level property contains the value "error" in
your event handler function.
Working with error events
The ErrorEvent class and its subclasses contain error types for handling errors dispatched by
Flash Player as it tries to read or write data.
The following example uses both a
try..catch statement and error event handlers to display
any errors detected while trying to read a local file. You can add more sophisticated handling
code to provide a user with options or otherwise handle the error automatically in the places
indicated by the comment “your error handling code here”:
package
{
import flash.display.Sprite;
import flash.errors.IOError;
import flash.events.IOErrorEvent;
import flash.events.TextEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.net.URLRequest;
import flash.text.TextField;
public class LinkEventExample extends Sprite
{
private var myMP3:Sound;
public function LinkEventExample()
{
myMP3 = new Sound();
var list:TextField = new TextField();
list.autoSize = TextFieldAutoSize.LEFT;
list.multiline = true;
list.htmlText = "<a href=\"event:track1.mp3\">Track 1</a><br>";
list.htmlText += "<a href=\"event:track2.mp3\">Track 2</a><br>";
addEventListener(TextEvent.LINK, linkHandler);
addChild(list);
}
private function playMP3(mp3:String):void
{
try