2 Replies Latest reply on Sep 5, 2007 5:24 PM by Handycam

    Dumb binding question

    Handycam Level 1
      I have an XMLList: [Bindable] public var _xmlData:XMLList;

      Which is loaded from an XML file like:
      <step title="step 1">
      <bodyText>Some body text for step 1</bodyText>
      <step title="step 2">
      <bodyText>Some body text for step 2</bodyText>

      If I do trace(_xmlData.step.bodyText[0]); I get the text from step 1 as expected.

      If I try to bind to this in a control:
      <mx:Text text="{app._xmlData.step.bodyText[0]}" />

      The compiler fails saying not to use the quare bracket, to use get item at instead. But if I use
      <mx:Text text="{app._xmlData.step.bodyText.getItemAt(0)}" />

      I get nothing in the text object. What gives here?

        • 1. Re: Dumb binding question
          ntsiii Level 3
          getItemAt is a method of collections, it does not exist on XMLList.

          I don't think you want what you have. Try this:
          <mx:Text text="{app._xmlData.step[0].bodyText}" />

          Now, do you really need binding in this case? Does the data change?
          If not then youcan do this:
          <mx:Text id="txt1" creationComplete="{txt1.text=app._xmlData.step[0].bodyText}"

          • 2. Re: Dumb binding question
            Handycam Level 1
            The first suggestion did not work. Compiling fails with:
            Error: Data binding will not be able to detect changes when using square bracket operator. For Array, please use ArrayCollection.getItemAt() instead.

            The second compiles but throws a RTE:

            TypeError: Error #1009: Cannot access a property or method of a null object reference.
            at myComponents::Step0/__txt1_creationComplete()
            at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
            at flash.events::EventDispatcher/dispatchEvent()
            at mx.core::UIComponent/dispatchEvent()
            at mx.core::UIComponent/set initialized()
            at mx.managers::LayoutManager/::doPhasedInstantiation()
            at Function/ http://adobe.com/AS3/2006/builtin::apply()
            at mx.core::UIComponent/::callLaterDispatcher2()
            at mx.core::UIComponent/::callLaterDispatcher()

            However, info you posted in my other similar post DID work:
            <mx:Text text="{XML(app._stepData0).bodyText}" />