Flex 学习笔记8

Flex 学习笔记8

数据绑定
a) 使用<mx:Binding>
        单向绑定:<mx:Binding source="bindFrom.text" destination="bindTo.text"/>
        双向绑定:<mx:Binding source="bindFrom.text" destination="bindTo.text"/> <mx:Binding source="bindTo.text" destination="bindFrom.text"/>
示例:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  backgroundColor="#FFFFFF">
 <mx:Binding source="bindFrom.text" destination="bindTo.text" />
 <mx:Binding source="bindTo.text" destination="bindFrom.text" />
 <mx:Panel title="Simple Binding Example" width="300" height="150">
   <mx:Form>
    <mx:FormItem label="Bind From">
       <mx:TextInput id="bindFrom" />
     </mx:FormItem>
     <mx:FormItem label="Bind To">
       <mx:TextInput id="bindTo" />
     </mx:FormItem>
   </mx:Form>
  </mx:Panel>
</mx:Application>
b)使用[Bindable]绑定变量到组件
  如果类声明为[Bindable],那么该类中所有的公共属性都是可绑定的
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
   backgroundColor="#FFFFFF">
   <mx:Script>
     <![CDATA[
       [Bindable]
       public var myLabelName:String = "Hello World";
     ]]>
   </mx:Script>
  <mx:Panel title="Binding With Curly Braces" width="350" height="150">
   <mx:Spacer height="100%"/>
    <mx:Label text="{this.myLabelName}" />
    <mx:Spacer height="100%"/>
  </mx:Panel>
  <mx:TextArea id="ta1" text="" change="this.myLabelName=ta1.text" />
</mx:Application>

直接绑定组件:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
   backgroundColor="#FFFFFF">

  <mx:Panel title="Empty Panel" width="{mySlider.value}" height="150" />
  <mx:TextArea width="300" text="The width property of the Panel above is bound to the value property of the HSlider below." />
  <mx:HSlider id="mySlider" snapInterval="5" minimum="100" maximum="350" value="250"/>
</mx:Application>



你可能感兴趣的:(Flex 学习笔记8)