Adobe FLEX 2 - CREATING AND EXTENDING COMPONENTS Manual page 233

Creating and extending flex 2 components
Hide thumbs Also See for FLEX 2 - CREATING AND EXTENDING COMPONENTS:
Table of Contents

Advertisement

To define your instance class, you create a subclass from the mx.effects.EffectInstance class. In
the class definition, you must define a constructor and
optionally define an
end()
package myEffects
{
// myEffects/MySoundInstance.as
import mx.effects.EffectInstance;
import flash.media.SoundChannel;
import flash.media.Sound;
public class MySoundInstance extends EffectInstance
{
// Embed the MP3 file.
[Embed(source="sample.mp3")]
[Bindable]
private var sndCls:Class;
// Define local variables.
private var snd:Sound = new sndCls() as Sound;
private var sndChannel:SoundChannel;
// Define constructor.
public function MySoundInstance(targetObj:Object) {
super(targetObj);
}
// Override play() method.
// Notice that the MP3 file is embedded in the class.
override public function play():void {
super.play();
sndChannel=snd.play();
}
// Override end() method class to stop the MP3.
override public function end():void {
sndChannel.stop();
super.end();
}
}
}
method to stop the effect.
methods, and you can
play()
About creating a custom effect
233

Advertisement

Table of Contents
loading

Table of Contents