| Flex 2 Developer's Guide > Flex Programming Topics > Using View States > Creating your own override classes | |||
You can define custom overrides by creating a class that implements the IOverride interface. For example, you can create a class that adds a bitmap filter, such as a filter that blurs an object.
The IOverride interface contains the following methods:
|
Method |
Description |
|---|---|
initialize()
|
Initializes the override. |
apply()
|
Saves the original value and applies the override. |
remove()
|
Restores the original value. |
The following example shows an AddBlur override class that applies the Flash BlurFilter class to blur the target component.
package myOverrides
{
import flash.display.*;
import flash.filters.*;
import mx.core.*;
import mx.states.*;
/* State override that adds a Blur effect to a component. */
public class AddBlur implements IOverride
{
/* Constructor. */
public function AddBlur(
target:DisplayObject = null)
{
this.target = target;
}
/* Property: The object to blur. */
public var target:DisplayObject;
/* The initialize() method is empty for this example. */
public function initialize():void {
}
/* The apply method adds a BlurFilter to the filters array. */
public function apply(parent:UIComponent):void {
var obj:DisplayObject = target ? target : parent;
var filters:Array = obj.filters;
filters.push(new BlurFilter());
obj.filters = filters;
}
/* The remove method removes the BlurFilter from the filters array. */
public function remove(parent:UIComponent):void {
var obj:DisplayObject = target ? target : parent;
var filters:Array = obj.filters;
filters.pop();
obj.filters = filters;
}
}
}
Flex 2.01