Flex uses an event-driven application model, which is manifested in both user interaction with the user interface and code execution based on system events. For more information about events, see Working with ActionScript in Flex in Developing Flex Applications.
User interface controls have event properties to which you can assign functions, called event handlers, that respond to events. The following example shows a simple event handler that displays text in a TextArea control when the user clicks a Button control:
<mx:Script>
<![CDATA[
function Hello() {
text1.text="Hello!";
}
]]>
</mx:Script>
<mx:Button label="Clear" click="Hello();" >
<mx:TextArea id="text1" width="150" text="This will be cleared" />
ActionScript code executes asynchronously. This means that code in a Flex application continues executing without being blocked by the execution of other code. However, you need a way to deal with dependencies between the execution of different pieces of code in an application. There are times when you do not want a function to execute until some other function has already executed. You can use event handling for these dependencies.
For example, you might have one web service operation that uses data that another operation returns. A result event is triggered when a web service operation successfully returns a result. You can write a function that calls the second operation with the result of the first operation, and then assign that function as the result event handler of the first operation, as the following example shows. You can use this technique for any code that depends on the execution of other code.
...
<mx:WebService id="myService"...>
<mx:operation name="getFoo" result="myFooResultHandler(event.result)" />
<mx:operation name="getBarWithFooInput" />
</mx:WebService>
<mx:Script>
<![CDATA[
function myFooResultHandler(foo) {
myService.getBarWithFooInput(foo);
}
]]>
</mx:Script>
...
For more information about event handling, see Working with ActionScript in Flex in Developing Flex Applications.
Version 1.5
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flex/15/flex_docs_en/00000065.htm