2 Replies Latest reply on Aug 18, 2009 11:24 AM by JonKaros

    Recent Document Loader, addEventListener with dynamic functions.

    JonKaros

      I have an application which I am trying to display a list of recent documents, that you can click on to open them.

       

      So far they display but only the last item gets the new event and works. Here is the code that I use to generate the call.

       

      The code is attached. Its as if the code only rembers the last added eventListner. Please help, thank you!

        • 1. Re: Recent Document Loader, addEventListener with dynamic functions.
          Jeff Swartz Level 3

          Jon,

           

          The problem in your code where you use an unnamed callback function as the event listener:

           

               document.getElementById('recDocName' + arrCount).addEventListener('click', function() {
                      OpenFile(stringName, true);},true);

           

          Try something like this:

           

                  document.getElementById('sdf' + arrCount).addEventListener('click', clickEventListener, true);

           

          Then define a separate clickEventListener() function that looks like this:


          function clickEventListener(event) {

              var targetID = event.target.id;
              air.trace(targetID);

              // Calculate the filename based on the targetID, possibly looking up in an Array

              // Call the funciton to open the file
          }

          • 2. Re: Recent Document Loader, addEventListener with dynamic functions.
            JonKaros Level 1

            Adobe Air, is really making me think pretty hard for some things wich I think should be simple.

             

            Thank you, that helped. I had a minor programing issue, which put me into an instant loop.

             

            My problem is solved, thank you.