
28
Chapter 2: Using MXML
The following example shows the code for a version of the application in which the event handler
is contained in an ActionScript function in an
<mx:Script>
tag:
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">
<mx:Script>
<![CDATA[
function hello(){
textarea1.text="Hello World";
}
]]>
</mx:Script>
<mx:Panel title="My Application" marginTop="10" marginBottom="10"
marginLeft="10" marginRight="10" >
<mx:TextArea id="textarea1"/>
<mx:Button label="Submit" click="hello();"/>
</mx:Panel>
</mx:Application>
For more information about using ActionScript with MXML, see Chapter 16, “Working with
ActionScript in Flex,” in
Developing Flex Applications
.
Binding data between components
Flex provides simple syntax for binding the properties of components to each other. In the
following example, the value inside the curly braces ({ }) binds the
text
property of a TextArea
control to the text property of a TextInput control. When the application initializes, both controls
display the text
Hello
. When the user clicks the Button control, both controls display the text
Goodbye
.
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml">
<mx:Panel title="My Application" marginTop="10" marginBottom="10"
marginLeft="10" marginRight="10" >
<mx:TextInput id="textinput1" text="Hello"/>
<mx:TextArea id="textarea1" text="{textinput1.text}"/>
<mx:Button label="Submit" click="textinput1.text='Goodbye';"/>
</mx:Panel>
</mx:Application>
Содержание FLEX-GETTING STARTED WITH FLEX
Страница 1: ...Getting Started with Flex...
Страница 4: ...4 Contents...
Страница 22: ...22 Chapter 1 Introducing Flex...