Skip to content
seanhess edited this page Sep 13, 2010 · 18 revisions

Bifff’s primary design goal is to provide a way to use Selectors to associate a Behavior class with a component. A behavior must either implement IBehavior, or have a set target function. It should apply itself to the target as a result of that function call.

A simple example Behavior might be the following, called Padding, which sets all four padding values at once.

package me
{
	// import statements // 
	
	public class Padding
	{	
        public var amount:int = 5;

		public function set target(value:UIComponent):void
		{
			value.setStyle("paddingLeft", amount);
			value.setStyle("paddingRight", amount);
			value.setStyle("paddingTop", amount);
			value.setStyle("paddingBottom", amount);
		}
	}
}

You could use this without bifff at all, simply by setting the target to a component you want to add padding to.

<mx:Button id="button" label="Click Me"/>
<me:Padding amount="10" target="{button}"/>

Using Bifff to inject behaviors

You set up a BehaviorMap, which uses Selectors to associate behaviors to components. A simple example would be the following, which adds the Padding behavior to all Boxes. Here, we are using the Behavior tag to create a new instance of Padding for each Box.

<BehaviorMap target="{this}">
    <Selector match="mx.containers.Box">
        <Behavior generator="{Padding}" amount="10"/>
    </Selector>
</BehaviorMap>

Alternatively, you can use the same instance of the behavior for many targets, by putting an instance of the behavior in the selector instead of the behavior tag. The BehaviorMap sets the target whenever a match for the selector is found

<BehaviorMap target="{this}">
    <Selector match="mx.containers.Box">
        <Padding amount="10"/>
    </Selector>
</BehaviorMap>
Clone this wiki locally