9 Replies Latest reply on Jun 20, 2007 1:18 AM by John_Milton

    Binding error

    John_Milton
      I have a bindable XML variable "Store" and am binding to an element in mxml using {Store.Address}

      All works as expected, but I'm getting a warning :

      "Data binding will not be able to detect changes to XMLList Address, need an XML instance".

      Is there a different way to bind to XML elements, or a way to make the elements bindable?

      Thanks!

      John
        • 1. Re: Binding error
          BLXWebMaster Level 1
          Can you post your code?
          • 2. Re: Binding error
            John_Milton Level 1
            Hi - actual code is like this :

            [Bindable] public var GLInfo:XML = new XML(null);

            ...on getting results from HTTPService as e4x XML :

            GLInfo = XML(e.result.Stores.Store.(Code == "GL"));

            ...used like this :

            <mx:Text text="{GLInfo.Address}" />

            The source XML looks like this :

            <InitResults>
            <Stores>
            <Store>
            <Code>GL</Code>
            <Address>Address here...</Address >
            ...other elements...
            </Store>
            ...more store elements...
            </Stores>
            </InitResults>

            I'm only displaying the elements (which is working fine) but I'd like to get rid of the warnings if possible...

            Thanks!

            John

            • 3. Re: Binding error
              BLXWebMaster Level 1
              A little tough without the complete code... However if it is something like this, you should not get any compile warnings. Are you sure you are using Flex 2.01. There were extraneous binding warnings with older versions.

              <mx:Script>
              <![CDATA[
              import mx.events.*;
              import mx.controls.*;
              import mx.collections.XMLListCollection;
              import mx.rpc.events.ResultEvent;

              [Bindable]
              public var GLInfo:XML = new XML(null);

              private function getStoresRPCResult(event:ResultEvent):void {
              GLInfo = XML(event.result.Stores.Store.(Code == "GL"));
              }
              ]]>
              </mx:Script>

              <mx:HTTPService
              id="getStores"
              resultFormat="e4x"
              showBusyCursor="true"
              url=" http://127.0.0.1/text.php"
              result="getStoresRPCResult(event);"/>

              <mx:Text text="{GLInfo.Address}" />

              • 4. Re: Binding error
                John_Milton Level 1
                Hi

                Sorry - was just trying to extract the relevant bits on the assumption that I was doing something basic wrong.

                I'm on 2.0.155577 on Mac FWIW.

                You are right though - pulling the basic bits out into a fresh application results in no errors.

                Back to the real app - copy & pasting the problem <mx:Text> controls and a recompile leads to no warning on the new control (warning still on the original). Must be something confused somewhere in my app...

                So, I guess I'll just recreate the controls...

                Thanks for your assistance, it's appreciated!

                John
                • 5. Re: Binding error
                  John_Milton Level 1
                  OK - just in case this helps someone else...

                  I've discovered the Project > Clean... menu item - this removed all the warnings!

                  John
                  • 6. Re: Binding error
                    ntsiii Level 3
                    Be aware that the XML() function is doing a conversion for you in this line
                    GLInfo = XML(e.result.Stores.Store.(Code == "GL"));

                    All E4x expressions return an XMLList, and so you are feeding an XMLList into the XML function. Clearly the function is successfully doing this coversion. Making it explicit might be safer:
                    GLInfo = XML(e.result.Stores.Store.(Code == "GL")[0]);

                    Tracy
                    • 7. Re: Binding error
                      John_Milton Level 1
                      Hi Tracy

                      OK, I see what you're saying...

                      I guess I could assign the whole result to an XML var & bind using an e4x expression :

                      {XMLResult.Stores.Store.(Code == "GL").Address} etc

                      essentially my GLInfo XML variable is just a shortcut....

                      IIRC I originally moved to an XML var due to binding warnings on an XMLList object not being bindable?

                      Is there a preferred way to deal with this situation, ie wanting to break large XML results into more manageable chunks for binding - I guess it's pretty common, but I've spent a surprisingly large amount of time fiddling with it (and RTFM) to get it working!

                      Thanks

                      John

                      • 8. Re: Binding error
                        ntsiii Level 3
                        No, you are fine. I just wanted to remind you that e4x expressions always return an XMLList.

                        Actually, the XML function in the above is not really necessary. You could do:
                        GLInfo = e.result.Stores.Store.(Code == "GL")[0]; //but without the array index, this would give a datatype compile error.


                        I typically have an instance level XML variable to hold the whole shebang. I also have [Bindable]XMLListCollection variables to hold commonly used node lists. I populate all those variables in a result handler function. (Remember to use *new* XMLListCollection(XMLList))

                        If you are not going to be updating the items of a dataProvider individually on the client, then XMLList is ok for a dataProvider. It is just that the XMLList API methods do not dispatch the events necessary to automatically sync the UI. But I habitually wrap XMLList in and XMLListCollection. There is no reason not to (Flex does it internally if you do not).

                        Tracy
                        • 9. Re: Binding error
                          John_Milton Level 1
                          Tracy -

                          Thanks that's a helpful information.

                          John