Table of Contents

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.html">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.html">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.html">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
} 

Table of Contents