3 Replies Latest reply on Oct 28, 2010 11:58 AM by Flex harUI

    Binding issue in Flex4, working example from Flex3

    travr

      The following example works in Flex3 but importing into the Flex4 there appears to an issue with binding. When the button is pressed the "userEvent" dispatched to Components.instance should cause the binding for "user" to update in the TextInput.

       

      This works in Flex 3 but not in Flex 4. I've tried compiling with Flex 3 compatibility mode to no avail. I have also tried creating a new Flex4 project with same functionality.

       

      Any idea why this should not work in Flex4?

       

       

      Application MXML

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:local="*">
           
              // initialize service
           <local:ASComponents />
           
           <mx:Script><![CDATA[
                
                protected function handleClick():void
                {
                     Components.instance.user = "test";
                     Components.instance.dispatchEvent( new Event( "userEvent" ) );
                }          
           ]]></mx:Script>
                
           <mx:Label text="User:" />
           <mx:TextInput text="{Components.instance.user}" editable="false" />
           <mx:Button label="Update User" click="handleClick()" />
      </mx:Application>
      

       

       

      ASComponents MXML

       

      <?xml version="1.0" encoding="utf-8"?>
      <Components xmlns="*" xmlns:mx="http://www.adobe.com/2006/mxml">     
      </Components>
      

       

       

      Components ActionScript Class

       

      package
      {
           import flash.events.Event;
           import flash.events.EventDispatcher;
           import flash.events.IEventDispatcher;
           
           import mx.core.IMXMLObject;
           import mx.events.FlexEvent;
      
           public class Components extends EventDispatcher implements IMXMLObject
           {
                /** Reference to singleton instance of this class. */
                private static var _instance:Components;          
                private var _user:String = "";
      
                public function Components(target:IEventDispatcher=null)
                {
                     super(target);
                     _instance = this;
                     dispatchEvent(new Event("instanceChanged"));               
                }
                
                public function initialized(document:Object, id:String):void
                {
                     this.dispatchEvent( new FlexEvent("creationComplete",true));               
                }
      
                [Bindable(event="instanceChanged")]
                public static function get instance():Components
                {
                     return _instance;
                }
                
                [Bindable(event="userEvent")]
                public function get user():String
                {
                     return this._user;
                }               
                
                public function set user( val:String ):void
                {
                     this._user = val;
                }
           }
      }