Archive for September, 2008

Detecting mouse movement directions

September 30, 2008

Here

Flex 101: Event “target”/”currentTarget

September 26, 2008

Flex 3/ActionScript 3 follows the 3C DOM event model convention, using the terms “target” and “currentTarget” to describe source of the event and the object who registers its interest in the related events. If a button or its parent container registers interest in a mouse click event, either the button or its container becomes “currentTarget” while the button is the “target” at bubbling propagation.

In Flex/Flash, things like SystemManager (which is instantiated by Application and which inherits from flash.display.MovieClip) can also register its interest in any UIComponent(Note that stylized skins that are drawn by the drawing APIs will not trigger any MouseEvent event if the systemManger registers MouseEvent), which as Matt says will “broadcast” the event(i.e., call the event handlers). In this case, “currentTarget” is the systemManager and “target” can be the visual omponent or the loader of the visual content “under” the stage who is the source of the event.

The same event handler for the same UIComponent can have different event targets for different event types. For example, in the following code, the same function handles “click”/”change”/”close” events that are registered by a comboBox. For a “click” event, the target is never the comboBox but either UITextField or Button depending where you click on the comboBox. This seems to make sense since the client would presumably be more interested in which part of the comboBox a user clicks for a “click” event.

<mx:ComboBox close=”changeCompState(event);” change=”changeCompState(event);” click=”changeCompState(event);” />
//click : componentStateTest1_0._componentStateTest1_ComboBox1.TextInput8.UITextField10
//change : componentStateTest1_0._componentStateTest1_ComboBox1
//close : componentStateTest1_0._componentStateTest1_ComboBox1
//click : componentStateTest1_0._componentStateTest1_ComboBox1.Button6
//change : componentStateTest1_0._componentStateTest1_ComboBox1
//close : componentStateTest1_0._componentStateTest1_ComboBox1
private function changeCompState(event:Event):void
{
trace(event.type+” : “+event.target);
}

Flex 101: Add skins to a Flex application

September 25, 2008

Say you want to use FP drawing API to add some hand-coded vector graphics to your Flex containers, as you normally do in a Flash piece:

this.rawChildren.addChild(triangle);

The reason that Flex uses this.rawChildren property is to distinguish “style elements and skins” from the normal UIComponents that are accessible from addChild/getChildAt/numChildren, etc.