4 Replies Latest reply on Jul 8, 2008 6:56 AM by Matt Gifford

    Need help with loop and variable

    Matt Gifford Level 1
      Hi all.

      I'm almost there with this, but I'm stuck on a final issue.

      I'm looping through XML to pick out the images to display, with title and ID (which is used in the link).
      Everything works now, except for the itemID. This used to work, but now the ID is the same for all of the containers/links on the page.

      Code is attached below, and the function is the image.addEventListener.
      The itemID variable is the one not changing to reflect the individual items.

      Please please help.

      Many thanks

        • 1. Re: Need help with loop and variable
          Gregory Lafrance Level 6
          Instead of:

          thisPanel.id = itemID;

          use this:

          thisPanel.name = itemID;

          I don't know why id is not treated as you would think it should, but name works as you would expect.
          • 2. Re: Need help with loop and variable
            Matt Gifford Level 1
            Thanks for your reply Greg.

            I'm still having the same trouble. It's not the actual thisPanel.id or thisPanel.name causing the trouble.

            In the eventListener for the image (I have also created one for a button on the panl to link through to the same page as well), the itemID variable for all is exactly the same, and appears to be the last itemID from the XML item.

            The confusing thing is that within the same function, where the image is created, (and where the button is created in the newer version), the itemID is displaying correctly, with the individual id's. It's purely the eventListener function that has the one single id, and therefore not linking through to the correct page for the items.

            Can anyone help?

            Many thanks
            • 3. Re: Need help with loop and variable
              SujitG Level 2

              You can try using the logic you were using in your previous sample posted. Use the event.currentTarget.id to get the ID of the Image.

              image.addEventListener(MouseEvent.CLICK, function(e:Event):void
              var imgId:String = e.currentTarget.id;
              var url:URLRequest = new URLRequest(" http://localhost/youtubeDownloader-debug/index.cfm?video=" + imgID);
              navigateToURL(url, "_blank");


              You can also use the "data" property of the Image to store the value you want and use the same property to get the value in the event listener.

              Hope this helps.
              • 4. Re: Need help with loop and variable
                Matt Gifford Level 1

                thank you so much, man. That works perfectly.. I'm a very happy bunny now! Thank you! :)