绑定自定义属性——[bindable]和事件

<? xml version = " 1.0 "  encoding = " utf-8 " ?>
< 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 "  minWidth = " 955 "  minHeight = " 600 " >
    
< fx:Declarations >
        
<!--  将非可视元素(例如服务、值对象)放在此处  -->
    
</ fx:Declarations >
    
< fx:Script >
        
<! [CDATA[
            
            
// 绑定属性
            [Bindable]
            
private  var _product:String;
            
            
// 在set方法中创建属性更新事件,并触发该事件,以通知Flex属性被更新
             public  function set product(value:String): void
            {
                _product 
=  value;
                dispatchEvent(
new  Event( " productChanged " ));
            }
            
            
// 在get方法声明前,加入[Binndable]元素定义属性绑定。这样,当触发属性更新事件是,
            
// Flex将会修改对应的属性
            
            
// 没弄明白这个绑定事件在什么情况下能用到.
            [Bindable(event = " productChanged " )]
            
public  function get product():String
            {
                
return  _product;
            }

        ]]
>
    
</ fx:Script >
</ s:Application >

你可能感兴趣的:(绑定自定义属性——[bindable]和事件)