Event handler for Visual Component in Flex 4


 

Event handler for Visual Component in Flex 4

Flex are provide event driven application. When a programmer interact with the application interface and after that something change occur in the appearance of the component life cycle or change in the Interface.

Flex are provide event driven application. When a programmer interact with the application interface and after that something change occur in the appearance of the component life cycle or change in the Interface.

Event Handler for Visual Components in flex4:

Flex are provide event driven application. When a programmer interact with the application interface and after that something change occur in the appearance of the component life cycle or change in the interface. This is alled Event. Flex provide the ability to create event listener for the particular event that handle event when event occur.

Example:

 <?xml version="1.0"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:s="library://ns.adobe.com/flex/spark"

xmlns:mx="library://ns.adobe.com/flex/mx">

<fx:Script>

<![CDATA[

import mx.controls.Alert;

import spark.components.Button;

public var counter:Number=0;

private function onClick():void {

if(counter<5){

var button:Button = new Button();

button.label = "Hello";

button.width = 100;

button.percentHeight = 20;

shgroup.addElement(button);

counter++;

}

if(counter==5){

Alert.show("Stop");

}

}

]]>

</fx:Script>

<s:Panel width="200" height="200" title="Event Handler Example">

<s:VGroup id="shgroup">

<s:Button id="sbutton" width="100" height="20%" click="onClick()" label="Create Hello Button"/>

</s:VGroup>

</s:Panel>

0

</s:Application>

In this tutorial we have to create a button and set click event for this button. If user click this button then click event handler that is onClick() are called to handle click event and a hello button will be generate on particular click. If the number of hello button is equal to five then a alert generated by the handler to show message.

Output:





Running Application:

To view this page ensure that Adobe Flash Player version 10.0.0 or greater is installed.

1

Download this code

Ads