8 Replies Latest reply on Apr 20, 2006 7:28 PM by Codeless

    Listener Proble

    Codeless
      I have a menu component that uses a xml file, there are two types of links in
      the xml, one that loads a .jpg into the loader component and one that opens a pop-up window for an .swf file. My problem is how to create a listener that will know which is which.

      Here is the code I am using for to load the .jpg into the loader component

      var listenerObject = new Object();
      listenerObject.elementClick = function(e){
      var action = e.action; // xml 'action' attribute value
      gallery.contentPath = (action);
      };
      PN.addEventListener("elementClick",listenerObject) ;

      Thanks for any help with this, I have been trying and search for an answer for days.

      BTD
        • 1. Re: Listener Proble
          sneakyimp Level 2
          my guess is that the event object, 'e', passed to your eventhandler will be able to tell you what object has been selected. did you try reading the documentation? I have always found that the documentation SUCKS for this kind of thing. Maybe try this event handler to see what's in e...i haven't tested it but i think it will work:

          • 2. Re: Listener Proble
            Codeless Level 1
            Here is the output for the AS code:

            e.action=images/CRYSTAL1.jpg
            e.target=_level0.PN.holder.item2.holder.item1.holder.item1.square
            e.type=elementClicke.action=images/CRYSTAL1.jpg

            How would I use this information to open a pop-up window for the other links. Can you call other types of values from the xml file tha getsloaded into flash?

            Thanks for the help on this - I did look at the documentation and not any help.

            BTD
            • 3. Re: Listener Proble
              sneakyimp Level 2
              ok sounds to me like you need to add an extra attribute for each node in your xml file if you can which specifies linkType="jpg" or linkType="swf"

              then in your onclick event, you can check e.target.linkType.

              make sense? maybe try this code to find out more about what's in e.target

              listenerObject.elementClick = function(e){
              for (item in e.target) {
              trace("e.target." + item + "=" + e.target[item]);
              }
              };
              • 4. Re: Listener Proble
                sneakyimp Level 2
                *or* maybe you can parse the action item for its last 3 digits. i'm not sure what action would look like for the other type of link.
                • 5. Re: Listener Proble
                  TimSymons Level 1
                  From sneakyimp's idea you could use something like this:

                  if (e.action.substr(-3).toLowerCase() == "jpg") {
                  // it is an image
                  } else {
                  // it is an swf file
                  }

                  Tim
                  • 6. Listener Proble
                    Codeless Level 1
                    The if statement works great, Thanks. Now the only thing left is the wa to open a popup window for the .swf. I have a script that will resize a popup window to the size of an image, does the swf work in the same way as an image? Also I can't get the call in the AS to work here is the code:

                    var listenerObject = new Object();
                    listenerObject.elementClick = function(e){
                    var action = e.action; // xml 'action' attribute value
                    if (e.action.substr(-3).toLowerCase() == "jpg") {
                    gallery.contentPath = (action); // it is an image
                    } else {
                    getURL("javascript opImage(action)"); // it is an swf file
                    }
                    };


                    PN.addEventListener("elementClick",listenerObject);

                    Got any more Ideas?

                    Thanks for the help - I have been banging my head against this for days now.

                    BTD
                    • 7. Re: Listener Proble
                      sneakyimp Level 2
                      quote:


                      var listenerObject = new Object();
                      listenerObject.elementClick = function(e){
                      var action = e.action; // xml 'action' attribute value
                      if (e.action.substr(-3).toLowerCase() == "jpg") {
                      gallery.contentPath = (action); // it is an image
                      } else {
                      getURL("javascript opImage(action)"); // it is an swf file
                      }
                      };


                      without knowing exactly what's in action and without seeing code for PopImage, it would be impossible to tell what the problem is.
                      if action is a relative path to a SWF file on your server, you could try:
                      getURL(action, "_blank");

                      or you could try

                      var mc:MovieClip = _root.createEmptyMovieClip('popupSWF', _root.getNextHighestDepth());
                      mc.loadMovie(action);
                      • 8. Re: Listener Proble
                        Codeless Level 1
                        Thanks guys for all your help with this. It seems to work best to put the link and the popup info into the xml.

                        Thanks again for the help.

                        BTD