User Guide

126 Object-Oriented Programming in ActionScript
var sndChannel:SoundChannel = mySound.play();
}
}
}
Alternatively, you can embed an asset with the
@Embed() directive in an MXML tag
definition. For more information, see “About embedding assets” in the Flex 2 Developer’s
Guide.
Interfaces
An interface is a collection of method declarations that allows unrelated objects to
communicate with one another. For example, the Flash Player API defines the
IEventDispatcher interface, which contains method declarations that a class can use to handle
event objects. The IEventDispatcher interface establishes a standard way for objects to pass
event objects to one another. The following code shows the definition of the
IEventDispatcher interface:
public interface IEventDispatcher
{
function addEventListener(type:String, listener:Function,
useCapture:Boolean=false, priority:int=0,
useWeakReference:Boolean = false):void;
function removeEventListener(type:String, listener:Function,
useCapture:Boolean=false):void;
function dispatchEvent(event:Event):Boolean;
function hasEventListener(type:String):Boolean;
function willTrigger(type:String):Boolean;
}
Interfaces are based on the distinction between a method’s interface and its implementation. A
method’s interface includes all the information necessary to invoke that method, including
the name of the method, all of its parameters, and its return type. A method’s implementation
includes not only the interface information, but also the executable statements that carry out
the method’s behavior. An interface definition contains only method interfaces, and any class
that implements the interface is responsible for defining the method implementations.
TIP
To use the [Embed] metadata tag in an Adobe Flex Builder 2 ActionScript project, you
must import any necessary classes from the Flex framework. For example, to embed
sounds, you must import the mx.core.SoundAsset class. To use the Flex framework,
include the file framework.swc in your ActionScript build path. This will increase the size
of your SWF file.