1 Reply Latest reply on Jul 25, 2007 2:50 PM by ntsiii

    xml can't be bound??

    dilbertje
      Greetings,

      Again, a small problem:

      I would like to, when clicked on the btnAddItem.jpg-image, (<mx:Image id="btnAddItem" source="assets/btnAddItem.jpg" click="addItem(repConsumables.currentItem,event.currentTarget)" />
      ) a trace is triggered with the corresponding xmlstructure bound to that image.

      I can't seem to get this working.
      Also, when running in debugmode, I get the warnings below

      CODE
      ----------------------

      Code:
      <?xml version="1.0" encoding="utf-8"?>
      <mx:VBox xmlns:mx=" http://www.adobe.com/2006/mxml" color="#400000" creationComplete="
      printerData.send()" xmlns:c="comp.*">
      <mx:Metadata>
      [Event(name="itemSelected", type="events.itemEvent")]
      </mx:Metadata>
      <mx:Script>
      <![CDATA[
      import mx.rpc.events.ResultEvent;
      import mx.collections.ArrayCollection;
      import mx.collections.XMLListCollection;
      import events.itemEvent;

      [Bindable]
      private var printerXML:XMLList;
      [Bindable]
      private var printerDP:XMLListCollection;

      private function printerDataHandler(event:ResultEvent):void
      {
      printerXML = event.result..confItem;
      printerDP = new XMLListCollection (printerXML);
      }

      [Bindable]
      public var selectedItem:Object;
      private function addItem(itemObj:Object,event:Object):void{
      event.source = "assets/btnRemoveItem.jpg";
      selectedItem = new Object();
      selectedItem = itemObj;
      var eventObj:itemEvent = new itemEvent(selectedItem,"itemSelected");
      trace(selectedItem);
      /*dispatchEvent(eventObj);*/
      }
      ]]>
      </mx:Script>
      <mx:HTTPService id="printerData"
      url="data/data.xml"
      showBusyCursor="true"
      result="printerDataHandler(event)" resultFormat="e4x"/>
      <mx:Spacer height="43" />
      <mx:HBox width="100%">
      <mx:Image source="assets/btnDisk.jpg"/>
      <mx:Image source="assets/btnPrint.jpg"/>
      <mx:Image source="assets/btnSend.jpg"/>
      </mx:HBox>
      <mx:Accordion id="accOptions" width="100%" height="100%" headerHeight="32" backgroundAlpha="0"
      fontSize="11" color="#0066CB" resizeToContent="true">
      <mx:Repeater id="repAccOptions" dataProvider="{printerDP}" startingIndex="0" >
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" label="
      {repAccOptions.currentItem.label}" width="100%" height="100%" verticalScrollPolicy="off">
      <mx:VBox>
      <mx:Text width="198" htmlText="{repAccOptions.currentItem.text}" />
      <mx:Repeater id="repConsumables" dataProvider="
      {repAccOptions.currentItem.consumables.consumable}">
      <mx:HBox width="100%">
      <mx:Image id="btnAddItem" source="assets/btnAddItem.jpg" click="
      addItem(repConsumables.currentItem,event.currentTarget)" />
      <mx:Text width="100%" htmlText="
      {repConsumables.currentItem.consumableLabel}" />
      <mx:Image source="assets/btnInfoItem.jpg" >
      <mx:toolTip>
      {repConsumables.currentItem.consumableLabel}&#13;Partnumber:
      {repConsumables.currentItem.consumablePartnr}&#13;Price:{repConsumables.currentItem.consum ablePrice}
      &#13;&#13;Omschrijving&#13;{repConsumables.currentItem.consumableDescr}
      </mx:toolTip>
      </mx:Image>
      </mx:HBox>
      </mx:Repeater>
      </mx:VBox>
      </mx:Canvas>
      </mx:Repeater>
      </mx:Accordion>
      </mx:VBox>



      WARNINGS
      -------------

      Code:
      warning: unable to bind to property 'text' on class 'XML' (class is not an IEventDispatcher)
      warning: unable to bind to property 'label' on class 'XML' (class is not an IEventDispatcher)
      warning: unable to bind to property 'consumables' on class 'XML' (class is not an IEventDispatcher)
      warning: unable to bind to property 'consumable' on class 'XMLList' (class is not an IEventDispatcher)
      warning: unable to bind to property 'text' on class 'XML' (class is not an IEventDispatcher)
      warning: unable to bind to property 'label' on class 'XML' (class is not an IEventDispatcher)
      warning: unable to bind to property 'consumables' on class 'XML' (class is not an IEventDispatcher)
      warning: unable to bind to property 'consumable' on class 'XMLList' (class is not an IEventDispatcher
        • 1. Re: xml can't be bound??
          ntsiii Level 3
          Note, this forum is for Flex Builder questions. Post Flex language questions in the General Discussion forum. It also has much more traffic.

          First, "currentItem" ONLY exists while the repeater is rendering, so you cannot use it in an event handler. You will need to look into getRepeaterItem.

          Second, the warnings are because currentItem, returns an Object, and you can't bind to Object. The warnings are kind of stupid, since the compiler obviously knows it is XML, but whatever. This is the fix:
          htmlText="{XML(repAccOptions.currentItem).text}"

          This "casts" (not really, but..) the Object into XML, which is bindable.

          Tracy