
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Calling ActionScript Functions from HTML Links
|
1001
In ActionScript, we can also execute JavaScript statements from an <A> tag, like this:
theField_txt.htmlText = "<A HREF='javascript:alert(5);'>display the number 5</A>";
However, to include string values in JavaScript statements, we must use the HTML
entity
" for quotation marks, as in:
theField_txt.htmlText = "<A HREF=
'javascript:alert("hello world");'>"
+ "display hello world</A>";
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. ...