14 Replies Latest reply on Jul 26, 2009 10:14 AM by kglad

    can't use image as link using asfunction for some reason

    Nancy Gill Level 1

      I have a pretty large which was coded using AS2 in about 2006 so I'm trying to make a few changes using AS2 which I'm pretty rusty on.  I have a swf which loads an xml file into a textarea in flash and it all works well.  I have to link some images which appear in the xml file but those images have to be links to external sites and that is where I am running into problems with my asfunction.  Here is the code.

       

      Function in my AS:

       

      function launchSite(arg) {
        if(arg == "agri") {
          getURL("http://www.usda.gov/wps/portal/usdahome", "_blank");
        }
      }

       

      then of course arg will take different values for the other links:

       

      In the xml file, here is the asfunction code:

       

      <a href='asfunction:_root.launchSite,agri'><img src="images/agri.gif"></a>

       

      What is happening is the function is working and the external link is opening in a new browser window, but the xml stops at that point so most of the agri.gif image and the rest of the page are gone.  If I change the img tag to just a text link, then all is well .. but my client wants the images to be the link.

       

      To further complicate, if I remove the link text and have only the img tag, the page is fine.  They just won't work together for some reason.  Any thoughts?

       

      Thanks!

      Nancy

        • 1. Re: can't use image as link using asfunction for some reason
          kglad Adobe Community Professional & MVP

          is your html code in a cdata node?

          • 2. Re: can't use image as link using asfunction for some reason
            Nancy Gill Level 1

            in the xml file?  No .. but I have many other instances of links, etc. and they all work fine.  I do have html set to true in the FLA.  A plain text link with this code works fine .. it's only when I change the link text to an img tag that I have problems.

             

            I'll try putting the img tag in a CDATA block and see if that helps.

             

            Thanks,

            Nancy

            • 3. Re: can't use image as link using asfunction for some reason
              Nancy Gill Level 1

              I did that and now the rest of the page renders .. but the CDATA did what it is supposed to and just printed out the img tag on the xml page rather than rendering the image. 

               

              I'm assuming that was not what you meant to do.

               

              Thanks,

              Nancy

              • 4. Re: can't use image as link using asfunction for some reason
                kglad Adobe Community Professional & MVP

                the cdata tag is needed so you can load the xml that contains html tags.  after that you need to parse the xml correctly and assign to your textarea.  are you?

                • 5. Re: can't use image as link using asfunction for some reason
                  Nancy Gill Level 1

                  >the cdata tag is needed so you can load the xml that contains html tags.

                   

                  Interesting since my xml files are full of html tags and everything else renders just fine without CDATA tags.  My textarea is configured to allow HTML.

                   

                  AS as follows:

                   

                  //set up the textarea
                  //init TextArea component
                  myText.html = true;
                  myText.wordWrap = true;
                  myText.multiline = true;
                  myText.label.condenseWhite=true;

                   

                  //set up the XML
                  myXML = new XML();
                  myXML.ignoreWhite = true;
                  myXML.load("xml/acts.xml");
                  myXML.onLoad = function(success)
                  {

                   

                  var myArray:Array = myXML.firstChild.childNodes;
                  myTitle.text = myXML.firstChild.attributes.title
                  myLoader.contentPath = myXML.firstChild.nextSibling.attributes.src
                  myText.text = myXML.firstChild.nextSibling.nextSibling
                  }

                   

                  function loadFunction(target){

                   

                  myXML.load(target);
                  myXML.onLoad = function(success)
                  {
                  var myArray:Array = myXML.firstChild.childNodes;
                  myTitle.text = myXML.firstChild.attributes.title
                  myLoader.contentPath = myXML.firstChild.nextSibling.attributes.src
                  myText.text = myXML.firstChild.nextSibling.nextSibling
                  }
                  }

                   

                  //function to load the external XML

                   

                  function launchSite(arg) {
                    if(arg == "agri") {
                      getURL("http://www.usda.gov/wps/portal/usdahome", "_blank");
                    }
                  }

                   

                  pertinent part of the xml as follows (portion of the text node which displays all the text):

                   

                  <a href='asfunction:_root.launchSite,agri'><![CDATA[<img src="images/agriculture.gif">]]></a> Department of Agriculture:  The Department of Agriculture began in 1862.  The main job of this department is to keep our food is safe and healthy.  They also work with farmers if they need help selling their crops both in the US and around the world.  Secretary of Agriculture is Mr. Thomas J. Vilsack.

                   

                  I added the CDATA tags at your suggestion.  What that gives me in the browser is a working function (loads the external site in a new window as desired) but instead of the image, I have the img tag printed out due to the CDATA tags (which by definition is not parsed).

                   

                  I have had pages on pages like this in this site since 2006 (which is why it's done in AS2 and not 3) and have never had a problem until the client wanted the images to be links to the external sites.  If I put in the image tag without the link, it works.  If I put in the link tag with a text link rather than the image, it works.  It's the two together that do not work.

                   

                  Does that make sense?

                   

                  Thanks again!

                  Nancy

                   

                   

                   

                   

                    after that you need to parse the xml correctly and assign to your textarea.  are you?

                  • 6. Re: can't use image as link using asfunction for some reason
                    kglad Adobe Community Professional & MVP

                    the cdata tag should surround the html text:

                     

                     

                    <textareaText>

                    <![CDATA[

                    <a href='asfunction:_root.launchSite,agri'><img src="images/agriculture.gif"></a> Department of Agriculture:  The Department of Agriculture began in 1862.  The main job of this department is to keep our food is safe and healthy.  They also work with farmers if they need help selling their crops both in the US and around the world.  Secretary of Agriculture is Mr. Thomas J. Vilsack.

                    ]]>

                    </textareaText>

                    1 person found this helpful
                    • 7. Re: can't use image as link using asfunction for some reason
                      Nancy Gill Level 1

                      That made all my html tags appear as tags .. so this is what I now see in the browser in the text area:

                       

                      For example, if the President is thinking about raising the speed limits on highways. He would talk to the Secretary of Transportation to see if this is a good idea or not. <br><br> Below is the list of Cabinet level departments, the year they were started, a little bit about what they do and their current leader. Click on their seal to go to each department’s website to learn more about it. <br><br> <a href='asfunction:_root.launchSite,agri'><img src="images/agriculture.gif"></a> Department of Agriculture: The Department of Agriculture began in 1862. The main job of this department is to keep our food is safe and healthy. They also work with farmers if they need help selling their crops both in the US and around the world. Secretary of Agriculture is Mr. Thomas J. Vilsack. <br><br> <img src="images/commerce.gif">Department of Commerce: The Department of Commerce began in 1903. The main job of this department is to help all Americans have jobs and to help businesses to grow. If you come up with a new invention or write a book, you would go to the Commerce Department to get a copyright, patent or trademark. This would protect your idea and keep others from using it without your permission. Secretary of Commerce is Mr. Gary F. Locke. <br><br>

                       

                       

                      CDATA is making it so none of the tags are interpreted as tags .. surely this cannot be right.  

                       

                      Thanks,

                      Nancy

                      • 8. Re: can't use image as link using asfunction for some reason
                        kglad Adobe Community Professional & MVP

                        the textarea/textfield that's displaying that is not html-enabled.

                        1 person found this helpful
                        • 9. Re: can't use image as link using asfunction for some reason
                          Nancy Gill Level 1

                          well .. this is the AS for the textarea:

                           

                          //set up the textarea
                          //init TextArea component
                          myText.html = true;
                          myText.wordWrap = true;
                          myText.multiline = true;
                          myText.label.condenseWhite=true;

                           

                          doesn't myText.html = true mean that it is html enabled?  Or am I confused?

                          also .. all the other html tags I have put in this area work just fine and there are hundreds of them .. but for some reason, this one is either the link or the img tag but not both.


                          I will readily admit that ActionScript isn't my best thing .. and I do more AS3 nowadays but I really don't want to recode this entire site, so AS2 it is.

                           

                          Thanks for all your advice!

                          Nancy

                          • 11. Re: can't use image as link using asfunction for some reason
                            Nancy Gill Level 1

                            the one in question is attached.  Thanks!

                            • 12. Re: can't use image as link using asfunction for some reason
                              kglad Adobe Community Professional & MVP

                              replace your line where you assign text to your textarea with:

                               

                              myText.text = myXML.firstChild.nextSibling.nextSibling.firstChild.nodeValue;

                              1 person found this helpful
                              • 13. Re: can't use image as link using asfunction for some reason
                                Nancy Gill Level 1

                                Thanks, kglad .. that did the trick.  The only problem is that all my text areas in the rest of the section (I think there are about 50) now just say null where the xml should load but that is just a matter of adding the CDATA tags to all those files so not a huge problem.

                                 

                                Thank you so much .. I'll review my AS knowledge to figure out why this needed to be this way .. it only seems to effect links since I could already put in an image tag if it wasn't a link the way I had it and that worked fine. 

                                 

                                Thanks again .. much appreciated!

                                Nancy