About creating a custom effect
235
Example: Passing parameters to effects
To make your effects more robust, you often design them to let the user pass parameters to
them. The example in this section modifies the sound effect from the previous section to take
a parameter that specifies the MP3 file to play:
package myEffects
{
// MySoundParam.as
import mx.effects.Effect;
import mx.effects.EffectInstance;
import mx.effects.IEffectInstance;
public class MySoundParam extends Effect
{
// Define a variable for the MP3 URL
// and give it a default value.
public var soundMP3:String=
"http://localhost:8100/flex/assets/default.mp3";
// Define constructor with optional argument.
public function MySoundParam(targetObj:Object = null) {
// Call base class constructor.
super(targetObj);
// Set instanceClass to the name of the effect instance class.
instanceClass= MySoundParamInstance;
}
// Override getAffectedProperties() method to return an empty array.
override public function getAffectedProperties():Array {
return [];
}
// Override initInstance() method.
override protected function initInstance(inst:IEffectInstance):void {
super.initInstance(inst);
// initialize the corresponding parameter in the instance class.
MySoundParamInstance(inst).soundMP3 = soundMP3;
}
}
}
In the MySoundParam class, you define a variable named soundMP3 that enables the user of
the effect to specify the URL of the MP3 file to play. You also modify your override of the
initInstance()
method to pass the value of the soundMP3 variable to the instance class.
Содержание FLEX 2 - CREATING AND EXTENDING COMPONENTS
Страница 1: ...Creating and Extending Flex 2 Components Adobe Flex 2...
Страница 6: ...6 Contents...
Страница 10: ...10 About Flex Documentation...
Страница 12: ......
Страница 24: ...24 Creating Flex Components...
Страница 74: ...74 Compiling Components...
Страница 76: ......
Страница 118: ...118 Creating Advanced MXML Components...
Страница 120: ......
Страница 182: ...182 Creating Advanced Visual Components in ActionScript...
Страница 194: ...194 Creating Custom Style Properties...
Страница 204: ...204 Creating Template Components...
Страница 206: ......
Страница 216: ...216 Creating Custom Formatters...
Страница 254: ...254 Index...