2 Replies Latest reply on Mar 4, 2009 5:09 AM by robbyk87

    Dynamic Event Listener

      Hey all,

      Got a problem with my code.

      var draftid:int = evt.result.mydrafts.draftid ;

      this stores multiple draft id's which come from http:request e.g <drafid>42</draftid>

      I then create children so that the data can be dynamically displayed. Problem is I want my displayObj to be
      clickable - and when clicked it should bringup the draftid for the object clicked. And because this is done in AS I
      would have to addEventListener for a click event. At the moment the click event only brings up the last draftid - not
      the current one. I've also tried to create an array to store the draftid's however I have no idea what to do with the information that the array contains to make each displayObj clickable and produce the correct draftid for the object clicked.

      Thanks in advance!
        • 1. Re: Dynamic Event Listener
          Level 7
          One way to get the draft id might be to make a subclass of VBox that has
          an extra property called draftid, and then use

          var currentId:Number = event.target.draftid;

          to get the draft id of the current item.

          If you want to do it with exactly the items and format that you have
          now, you could get the draft id out of the tooltip, although that would
          be a bit of a hack.

          var currentId:Number = Number(event.target.toolTip);

          It's a hack, since toolTip doesn't actually convey any information about
          what's stored in it, and so it will be hard for others (and you, when
          looking back on the code) to understand why you're doing it. So I would
          suggest the former.
          • 2. Re: Dynamic Event Listener
            robbyk87 Level 1
            Thanks for the quick reply Nate,

            I tried doing it the class method as you described but got utterly confused by it - however thanks to the investigation you led me on I discovered the inbuilt data class which I could use. And it work beautifully (much as a custom class would have done if I could figure it out).

            So the solution is:

            displayObj.data = draftid;

            private function myFunction(event:MouseEvent):void{

            var currentId:Number = event.target.data;


            This stores the correct variable (draftid) for each item clicked.

            Cheers Nate! Godsend