1 Reply Latest reply on Feb 29, 2008 10:18 AM by Newsgroup_User

    Links to AS functions in text?

    sean_elt
      Is there a way to create hyperlinks to AS functions within text that is imported from an XML file without having to call out to JavaScript and back?

      In other words, I'd like to have a way to put a link in the middle of a line of text and have it call an ActionScript function when clicked.

      Thanks for any help!
        • 1. Re: Links to AS functions in text?
          Level 7
          lectro,

          > Is there a way to create hyperlinks to AS functions within
          > text that is imported from an XML file without having to
          > call out to JavaScript and back?

          I think the answer is yes. It is possible to create hyperlinks (<a>
          tags) in HTML-formatted text in a Flash text field. It is possible to have
          that hyperlink trigger ActionScript, rather then open a URL. The
          HTML-formatted text can indeed be loaded from an XML document. Because none
          of this involves anything outside of the SWF file itself (besides the XML
          document), no JavaScript is required.

          > In other words, I'd like to have a way to put a link in the
          > middle of a line of text and have it call an ActionScript
          > function when clicked.

          Assuming you're using HTML-formatted text, it's as easy as using the
          asfunction pseudo protocol, instead of the http protocol. For example:

          var tf:TextField = this.createTextField("sampleTF", 0, 0, 0, 0, 0);
          tf.autoSize = "left";
          tf.html = true;
          tf.htmlText = "<p>Lorem ipsum dolor <a href='asfunction:myFunction'>sit
          amet</a>.</p>";

          function myFunction():Void {
          trace("I've been clicked!");
          }

          If your function accepts parameters, send those in as a string, like
          this:

          tf.htmlText = "<p>Lorem ipsum dolor <a
          href='asfunction:myFunction,param'>sit amet</a>.</p>";

          function myFunction(msg:String):Void {
          trace(msg);
          }

          In the above example, the parameter's value is "param", so that string
          gets passed into the function, where it is intercepted as the variable msg.
          The line trace(msg) will trace "param" to the Output panel.


          David Stiller
          Co-author, Foundation Flash CS3 for Designers
          http://tinyurl.com/2k29mj
          "Luck is the residue of good design."