E.7 Calling ActionScript Functions from HTML Links

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Appendix E.  HTML Support in Text Fields

E.7 Calling ActionScript Functions from HTML Links

Though arbitrary statements of ActionScript code cannot be executed from a Flash <A> tag, ActionScript functions can. To invoke an ActionScript function from an anchor tag, we use the following syntax:

<A HREF="asfunction:myFunctionName">invoke the function</A>

The function invocation operator ( ) is not allowed and should not be used when invoking an ActionScript function from an anchor tag. The function name must immediately follow the keyword asfunction: if a space character occurs before the function name, the function will not execute.

In addition to calling an ActionScript function from an anchor tag, we can also pass one parameter to that function using the syntax:

<A HREF="asfunction:myFunctionName,myParameter">invoke the function</A>

where myParameter is the value of the parameter to pass. Inside the invoked function, myParameter is always a string. To pass more than one piece of information to a function from an anchor, we use a delimiter in the myParameter value and dissect the string ourselves in the function. For example, here's a function invocation that passes two values, separated by a | character, to the roleCall( ) function:

<A HREF="asfunction:roleCall,megan|murray">invoke the function</A>

And here's the roleCall( ) function. Notice how it separates the values with the split( ) method:

function roleCall (name) {   var bothNames = name.split("|");   trace("first name: " + bothNames[0]);  // Displays: megan   trace("last name: " + bothNames[1]);   // Displays: murray } 


    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net