代码之家  ›  专栏  ›  技术社区  ›  Andrew Keeton ShuggyCoUk

Flex中的一些[Bindable]属性有效,一些则无效

  •  2
  • Andrew Keeton ShuggyCoUk  · 技术社区  · 17 年前

    问题已解决,见下文

    我在Flex Builder 3中工作,我有两个ActionScript 3类( ABC XYZ main.mxml 作为财产 XYZ公司 的属性可见( [Bindable] )在Flex项目的文本控件中。

    不幸的是,只有 prop3 prop4 prop1 prop2 更改,但它们不会在文本控件中更新。

    ABC.as

    [Bindable]
    public class ABC extends UIComponent {
        /* Other properties */
    
        public var xyz:XYZ = new XYZ();
    
        /* Methods that update xyz */
    }
    

    XYZ.as

    [Bindable]
    public class XYZ extends Object {
         private var _prop1:uint = 0;
         private var _prop2:uint = 0;
         private var _prop3:uint = 0;
         private var _prop4:uint = 1;
    
         public function get prop1():uint {
             return _prop1;
         }
    
         public function set prop1(value:uint):void {
             _prop1 = value;
         }
    
         /* getters and setters for prop2, prop3, and prop4 */
    }
    

    主程序文件

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:com="com.*" />
        <com:ABC id="abc" />
        <mx:Text text="{abc.xyz.prop1}" />
        <mx:Text text="{abc.xyz.prop2}" />
        <mx:Text text="{abc.xyz.prop3}" />
        <mx:Text text="{abc.xyz.prop4}" />
    </mx:Application>
    

    XYZ公司 _prop3 _prop4 使用他们的设定器。相反,我更新了 _prop1 _prop2 通过它们的私有变量,而不是它们的设定者。因此,属性1和2没有调度更新事件。

    2 回复  |  直到 17 年前
        1
  •  6
  •   Christian Nunciato    17 年前

    Main.mxml:

    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*" creationComplete="onCreationComplete()">
    
        <mx:Script>
            <![CDATA[
    
                private function onCreationComplete():void
                {
                    var t:Timer = new Timer(1000);
                    t.addEventListener(TimerEvent.TIMER, t_tick);
                    t.start();
                }
    
                private function t_tick(event:TimerEvent):void
                {
                    var i:uint = Timer(event.currentTarget).currentCount;
    
                    abc.xyz.prop1 = i;
                    abc.xyz.prop2 = i;
                    abc.xyz.prop3 = i;
                    abc.xyz.prop4 = i;
                }
    
            ]]>
        </mx:Script>
    
        <local:ABC id="abc" />
    
        <mx:VBox>
            <mx:Text text="{abc.xyz.prop1}" />
            <mx:Text text="{abc.xyz.prop2}" />
            <mx:Text text="{abc.xyz.prop3}" />
            <mx:Text text="{abc.xyz.prop4}" />
        </mx:VBox>
    
    </mx:Application>
    

    package
    {
        import mx.core.UIComponent;
    
        [Bindable]
        public class ABC extends UIComponent
        {
            public var xyz:XYZ = new XYZ();
    
            public function ABC()
            {
                super();
            }
        }
    }
    

    package
    {
        [Bindable]
        public class XYZ extends Object
        {
            private var _prop1:uint = 0;
            private var _prop2:uint = 0;
            private var _prop3:uint = 0;
            private var _prop4:uint = 1;
    
            public function XYZ()
            {
                super();
            }
    
            public function get prop1():uint {
                return _prop1;
            }
    
            public function set prop1(value:uint):void {
                _prop1 = value;
            }
    
            public function get prop2():uint {
                return _prop2;
            }
    
            public function set prop2(value:uint):void {
                _prop2 = value;
            }
    
            public function get prop3():uint {
                return _prop3;
            }
    
            public function set prop3(value:uint):void {
                _prop3 = value;
            }
    
            public function get prop4():uint {
                return _prop4;
            }
    
            public function set prop4(value:uint):void {
                _prop4 = value;
            }
        }
    }
    

    看看这些,插上电源,你应该会看到它们都在一起。如果你有任何问题,请回复。干杯。

        2
  •  1
  •   Mircea Grelus    17 年前

    [Bindable]
    public class XYZ extends Object {
         private var _prop1:uint = 0;
         private var _prop2:uint = 0;
         private var _prop3:uint = 0;
         private var _prop4:uint = 1;
    
         [Bindable(event="prop1Changed")]
         public function get prop1():uint {
             return _prop1;
         }
    
         public function set prop1(value:uint):void {
             _prop1 = value;
             dispatchEvent (new Event ("prop1Changed"));
         }
    
         /* getters and setters for prop2, prop3, and prop4 */
    }
    

    推荐文章