5 Replies Latest reply on Jun 21, 2009 5:59 AM by Handycam

    What's with the "unable to bind"?

    Handycam Level 1

      I have a list that originally was created in Flash Catalyst.  I modified the repeating item component to have the text bound to data.label to accomodate my data source:

       

      <s:RichText d:userLabel="0" fontFamily="Helvetica" color="0x252525" fontSize="12" kerning="off" whiteSpaceCollapse="preserve" y="4" x="5" text="{data.label}">
      

       

      My data source is an array collection of objects, each object with a label and data:

       

      <mx:ArrayCollection>
      <mx:source>
      <fx:Object label="No insulation" data="0"/>
      <fx:Object label="Fiberglass Batts" data="4.30"/>
      <fx:Object label="Vermiculite" data="2.4"/>
      <fx:Object label="Rock/Mineral Wool" data="4"/>
      <fx:Object label="Urea-formaldehyde foam" data="4.5"/>
      <fx:Object label="Balsam Wool" data="3"/>
      <fx:Object label="Cotton Batts" data="4"/>     
      </mx:source>
      </mx:ArrayCollection>
      

       

      It seems to work fine except for the warning:
      warning: unable to bind to property ’label’ on class ’Object’ (class is not an IEventDispatcher)

       

      From past experience, perhaps I need to cast data.label, but as what?

        • 1. Re: What's with the "unable to bind"?
          Shongrunden Adobe Employee

          Hi Handycam,

           

          This warning shows up when you try binding to an object that doesn't implement IEventDispatcher.

           

          Object does not implement IEventDispatcher so any time you bind to a property of that object you will get a warning.

           

          If you define a subclass of EventDispatcher with the properties you want:

           

          MyBindableObject.as:

           

          package {

           

            import flash.events.EventDispatcher;

           

            public class MyBindableObject extends EventDispatcher {

           

              [Bindable] public var label:String;
              [Bindable] public var data:Number;

           

            }

           

          }

           

          And then replace the objects in your ArrayCollection with instances of MyBindableObject then the warnings should go away.

           

          SampleList.mxml:

           

          <s:Application
              xmlns:fx="http://ns.adobe.com/mxml/2009"
              xmlns:s="library://ns.adobe.com/flex/spark"
              xmlns:local="*">
             
              <s:List>
                  <s:ArrayCollection>
                      <local:MyBindableObject label="No insulation" data="0"/>
                      <local:MyBindableObject label="Fiberglass Batts" data="4.30"/>
                      <local:MyBindableObject label="Vermiculite" data="2.4"/>
                      <local:MyBindableObject label="Rock/Mineral Wool" data="4"/>
                      <local:MyBindableObject label="Urea-formaldehyde foam" data="4.5"/>
                      <local:MyBindableObject label="Balsam Wool" data="3"/>
                      <local:MyBindableObject label="Cotton Batts" data="4"/> 
                  </s:ArrayCollection>
              </s:List>

           

          </s:Application>

           

          Message was edited by: Shongrunden (adding sample code for SampleList.mxml)

          • 3. Re: What's with the "unable to bind"?
            Handycam Level 1

            If I put that class in my "src" directory, what namespace do I use?  Because <fx:MyBindableObject/> does not (of course) work.

            • 4. Re: What's with the "unable to bind"?
              Shongrunden Adobe Employee

              If you have the MyBindableObject class and your application in the default package (just in the src folder) then you should be able to define a new namespace in your Application tag for example xmlns:local="*" like in the sample shown above.

              • 5. Re: What's with the "unable to bind"?
                Handycam Level 1

                Thanks.  Sorry, but I read your post on Gmail and it stripped out your sample code.