0 Replies Latest reply on Mar 3, 2010 4:50 AM by mickfin

    2 Way Binding problem

    mickfin

      Hi,

       

      I am quite new the flex andI have been trying to devel my own project.

       

      Basicly what I want to do is to display some information in a new screen. The user would then process that information and click "Save" and information is sent to php side and stored in the DB. That part is easy.

       

      Then I want to send the newly created record back from php side and update the window with the latest information.

       

      The problem I am have having is updating the window with the new information. Can somebody give me an example of how to do this.

      I have read the documentation on binding, calling invalidate,objectproxy... etc but I can't get it working. I have pasted here a simple example of the problem.

       

      thanks for your time

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*"
          creationComplete="initfunction()">

       

      <mx:Script>
          <![CDATA[
              import mx.collections.ArrayCollection;
              import mx.controls.Alert;
              import mx.binding.utils.BindingUtils;
              [Bindable]
              
               public var obj:Array = new Array();
               [Bindable]
               private var coll:ArrayCollection;
              
               public function initfunction():void {
                 obj["info1"] = "Finland";
                 obj["info2"] = "Sweden";
                 obj["info3"] = "England";
                 obj["info4"] = "Ireland";
                 obj["info5"] = "France";
                 obj["info6"] = "USA";
                 var i:Mycomonent = new Mycomonent(); // pasted below
                 coll = new ArrayCollection(obj);
                 i.obj = coll;
                 box.addChild(i);
               }

       

               private function update():void{
                   obj["info1"] = "NEW ZEALAND";
                  
                   box.invalidateDisplayList();
                   box.invalidateProperties();
                  box.invalidateSize();
                  box.validateNow();
                  trace(obj);
               }
          ]]>
      </mx:Script>

       

      <mx:HBox id="box" height="300" width="300">   
      </mx:HBox>

       

      <mx:Button x="158" y="38" click="update()"/>
         
      </mx:Application>

       

       

      ----------------------------------------------------------------------------------------Th is is the component ------------------------------

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300" creationComplete="initfun()">
          <mx:Script>
              <![CDATA[
                  import mx.collections.ArrayCollection;
                  [Bindable]
                   private var _obj:ArrayCollection;
         
                  private function initfun():void{
                     
                      //trace(obj);
                      //trace(obj);
                  }
         public function get obj():ArrayCollection
         {
            return _obj;
         }
        
         public function set obj( value:ArrayCollection ):void
         {
            _obj = value;
         }

       

              ]]>
          </mx:Script>
          <mx:Label text="{_obj.source.info1}" x="10" y="116"/>
          <mx:Label id="Ma" text= "{_obj.source.info2}" x="10" y="90"/>
          <mx:Label text="{_obj.source.info3}" x="10" y="64"/>
          <mx:Label text="{_obj.source.info4}" x="12" y="38"/>
          <mx:Label text="{_obj.source.info5}" x="10" y="168"/>
          <mx:Label text="{_obj.source.info6}" x="10" y="142"/>

       

      </mx:Canvas>