Flex current target property example

Example below describes the working of currentTarget property in flex. Code below shows a method .setSelection which is used to highlight the text letters as defined closed indexes.

Flex current target property example

Flex current target property example

     

The example below describes the working flex currentTarget property. Code below shows a method .setSelection which is used to highlight the text letters as per defined closed indexes. Here, use of <![CDATA --- ]]>  is optional. In the code, two functions are defined, viz.,  protocol and virus; both are event handler functions. First method defines the Label control id and  puts data in to core.text, where text is the attribute defined in TextInput control and the second function highlights the text characters from index 5 to 20 in TextInput. Both are click based event functions, however the protocol function gets initialized first because it is passed in the initialize attribute of the root tag. Root tag is coded as <Application/>, and is called as the root tag of the application inside which other flex control and container tags are coded. 

 

 

 

 

currentTarget.mxml

<?xml version = '1.0'?>
<mx:Application xmlns:mx = 'http://www.adobe.com/2006/mxml'>

  <mx:Script>
  <![CDATA[
  public function protocol(event:Event):void{
master.text = 'Label' + event.currentTarget.id + 'is clicked';
core.text = 'Weaving = Agent Smith said that in an 
interview about Matrix Reloaded
';  
  
  }

  public function virus(event:Event):void{
  TextInput(event.currentTarget).setSelection(5,20);
  
  ]]>
</mx:Script>

<mx:TextInput id = 'core' text = 'click on me
c
lick = 'virus(event);' />
  <mx:Label id = 'master' click = 'protocol(event);'/>
</mx:Application>

currentTarget.swf

 

In the code below event.current.Target feature is used in the function constructor. Function is called through the click attribute of Button control.


target.mxml

<?xml version = '1.0' encoding = 'ISO-8859-1'?>
<mx:Application xmlns:mx = 'http://www.adobe.com/2006/mxml'>
<mx:Script>
  import mx.controls.Alert;

  public function nick(s:String):void{
  Alert.show('Button control id is : ' + s);
}

</mx:Script>

  <mx:Button label = 'Click me' id = 'Cathastorus
  click = 'nick(event.currentTarget.id)'/>

</mx:Application>

target.swf

  


Download the source code