Skip navigation
sadensmol
Currently Being Moderated

Cant understand why binding not works

Jul 9, 2012 11:12 AM

Hello. Please help me.  simple example not works for me (((

 

<?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"

                                 creationComplete="application1_creationCompleteHandler(event)">

<fx:Script>

                    <![CDATA[

                              import mx.events.FlexEvent;

 

 

 

                              private var eee:test123;

                              protected function application1_creationCompleteHandler(event:FlexEvent):void {

                                        eee = new test123(this);

                              }

 

                              protected function button1_clickHandler(event:MouseEvent):void {

                                        dispatchEvent( new Event("test2"));

                              }

 

                    ]]>

</fx:Script>

 

<s:layout>

  <s:VerticalLayout/>

  </s:layout>

 

          <s:Label text="{eee.text}"/>

          <s:Button click="button1_clickHandler(event)"/>

</s:Application>

 

 

and file test123.as

 

package {

          import flash.events.Event;

          import flash.events.EventDispatcher;

 

          import mx.binding.utils.BindingUtils;

 

 

          public class test123 extends EventDispatcher{

          [Bindable(event = "test1")]

          public var text:String ;

 

                    public function test123(obj:EventDispatcher){

                              obj.addEventListener("test2",ontest2);

                    }

 

                    protected function ontest2(event:Event):void {

                              text = "fdsfadsf";

                              dispatchEvent(new Event("test1"));

                    }

          }

}

 

 

When i clicked the button label not changes. But if i transfer all code from test123 directly to main program it works fine. What is wrong???

 
Replies
  • Currently Being Moderated
    Jul 9, 2012 2:43 PM   in reply to sadensmol

    I don’t see Re: Cant understand why binding not works metadata in the example that is not working.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 10, 2012 9:49 AM   in reply to sadensmol

    Aren’t you getting warnings in the console about eee not being bindable?  I would think it would need metadata too.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 11, 2012 10:12 AM   in reply to sadensmol

    If you don’t have the binding events on each level of the expression, then you are relying on timing, or that certain parts of the expression do not change.  In your first case, eee was being assigned late, in this case the singleton is ready right away.

     
    |
    Mark as:
  • Currently Being Moderated
    Jul 11, 2012 5:38 PM   in reply to sadensmol

    I’m unclear what code ran and didn’t run.  I would put in more breakpoints or trace statements.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points