1 Reply Latest reply on May 17, 2006 5:26 PM by Newsgroup_User

    TileList, itemRenderer, and adding an eventListener

    Jinglesthula Level 1
      I have been able to successfully get events to be raised and added an eventListener to handle the event. My problem now is that I want to do the same thing for the items in a TileList component and I'm not sure how to reference the items themselves rather than the TileList.

      I created a custom itemRenderer mxml component that includes something like this:
      <mx:Metadata>
      [Event("CustomEvent")]
      </mx:Metadata>

      and then specified that my custom component be used as the itemRenderer for my TileList, which works fine - everything shows up like it's supposed to. In my custom renderer there are a couple of buttons. When one of them is clicked I want to send an event back to the mxml component that contains the TileList. I tried something like the following:

      myTileList.addEventListener("CustomEvent", myEventHandler); // for the TileList component

      and

      dispatchEvent(new CustomEvent("Hello, world.")); // in the custom item renderer when the button is clicked

      but the handler never gets called. That is to say I'm pretty sure the event gets dispatched, but I have no way of adding a listener for it. (Actually, I'm sure that the event gets dispached because I forgot to add super("CustomEvent"); in my custom event class .as file and it threw an error saying that it was receiving one less argument that it was expecting.)

      If anyone has worked with the TileList and events that could help out, I'd appreciate it.

      I dug through the Flex store sample application included in Flex Builder 2 Beta to see how they did it and they apparently aren't even using a TileList, but rather just a canvas with an array of manually instantiated items. Maybe this is why. :) At any rate, the Help documentation is a bit scarce when it comes to item renderers and events thrown up by them and so forth.
        • 1. Re: TileList, itemRenderer, and adding an eventListener
          Level 7
          Hello -

          I believe you need to add the custom event listener in the itemRenderer
          itself. Then the handler can handle the event as appropriate. I think what
          you want to do is something along the lines of this:

          <mx:TileList id="whatever" dataProvider="{data}" ..>
          <mx:itemRenderer>
          <mx:Component>
          <MyCustomRenderer customEvent="myEventHandler(event)" />
          </mx:Component>
          </mx:itemRenderer>
          </mx:TileList >

          You'll need to make sure your custom renderer implements IListItemRenderer.
          The mx:Component tag defines a new context, and everything inside that
          usually applies to the MXML document (script blocks, event handlers, id's,
          bindings, etc) but now it will apply to the new inline component you are
          defining.

          HTH -
          deepa

          "Jinglesthula" <webforumsuser@macromedia.com> wrote in message
          news:e4gb4e$i0s$1@forums.macromedia.com...
          >I have been able to successfully get events to be raised and added an
          > eventListener to handle the event. My problem now is that I want to do
          > the
          > same thing for the items in a TileList component and I'm not sure how to
          > reference the items themselves rather than the TileList.
          >
          > I created a custom itemRenderer mxml component that includes something
          > like
          > this:
          > <mx:Metadata>
          > [Event("CustomEvent")]
          > </mx:Metadata>
          >
          > and then specified that my custom component be used as the itemRenderer
          > for my
          > TileList, which works fine - everything shows up like it's supposed to.
          > In my
          > custom renderer there are a couple of buttons. When one of them is
          > clicked I
          > want to send an event back to the mxml component that contains the
          > TileList. I
          > tried something like the following:
          >
          > myTileList.addEventListener("CustomEvent", myEventHandler); // for the
          > TileList component
          >
          > and
          >
          > dispatchEvent(new CustomEvent("Hello, world.")); // in the custom item
          > renderer when the button is clicked
          >
          > but the handler never gets called. That is to say I'm pretty sure the
          > event
          > gets dispatched, but I have no way of adding a listener for it.
          > (Actually, I'm
          > sure that the event gets dispached because I forgot to add
          > super("CustomEvent"); in my custom event class .as file and it threw an
          > error
          > saying that it was receiving one less argument that it was expecting.)
          >
          > If anyone has worked with the TileList and events that could help out, I'd
          > appreciate it.
          >
          > I dug through the Flex store sample application included in Flex Builder 2
          > Beta to see how they did it and they apparently aren't even using a
          > TileList,
          > but rather just a canvas with an array of manually instantiated items.
          > Maybe
          > this is why. :) At any rate, the Help documentation is a bit scarce when
          > it
          > comes to item renderers and events thrown up by them and so forth.
          >