Accessibility

TechNote

Using asfunction

Flash 5's undocumented asfunction command allows an HREF link in an HTML-enabled text field, or a text field linked using the URL field in the Character panel, to call a user-defined function. Typically, URL text links in Flash are limited to calling other HTML pages, similar to the getURL action. Usingasfunction, a text link can call a function that can then perform a variety of ActionScript statements.

Syntax

The asfunction command can only be called from the URL field of the Character panel or from an HREF tag in an HTML-enabled text field.

 asfunction:functionName,parameter 

Note: One parameter can be passed to the function, delimited by a comma.

Arguments

functionName: Name of the user-defined function to be called when link is clicked.

parameter: Specifies the value to pass into the function.

Note: The function specified byfunctionName is called without concluding parentheses and must be defined in the Flash movie before being called.

Description

The asfunction command is used to call a function from a link in an HTML-enabled text field or from a text field linked using the URL field in the Character panel.

Examples

To see how asfunction works, add the following function definition to the first frame of a movie:

 function myFunction () {   trace("Testing asfunction..."); } 

Next, select a text block on the stage and open the Character panel (Window > Panels > Character). In the Character panel's URL field enter the following (as illustrated below):

 asfunction:myFunction 

Note: This is equivalent to assigning"<A HREF="asfunction:myFunction">Click here</A>" to an HTML-enabled text field variable.

Test the movie (Control > Test Movie) and click the linked text. The string "Testing asfunction..." should appear in the Output window. (If nothing appears in the Output window, double-check spelling and syntax in the URL field and the function definition.)

Passing a function parameter

You can pass a single, string parameter toasfunction. For example, modify the function declaration shown above as follows:

 function myFunction (param) {   trace("Testing asfunction with parameter: " + param); } 

Next, modify the asfunction call in the Character panel's URL field to include an argument:

 asfunction:myFunction,argument_1 

Note: This is equivalent to assigning"<A HREF="asfunction:myFunction,argument_1">Click here</A>" to an HTML-enabled text field variable.

The string "Testing asfunction with parameter: argument_1" should appear in the Output window when you test the movie in Flash.

Passing multiple function parameters

As mentioned above, the function called byasfunction is only passed a single string argument. One way to mimic passing multiple arguments is to separate the"arguments" using a predetermined string delimiter. Below, three comma-delimited arguments are passed tomyFunction.

 asfunction:myFunction,argument_1,argument_2,argument_3 

In the new version of myFunction, thesplit method is used to break the comma-delimited string into an array of arguments, argumentArray.

 function myFunction(param){   argumentArray = new Array;   argumentArray = param.split(",");   for (i=0; i< argumentArray.length; ++i){     trace("Function argument " + i + " = " + argumentArray[i]);   } } 

Testing the movie should result in the following being reported to the Output window:

 Function argument 0 =  argument_1
		
Function argument 1 = argument_2
Function argument 2 = argument_3
Additional information

Using HTML formatting in Flash 5 (TechNote 14808) contains information on creating links in HTML-enabled text fields.

AlertThis content requires Flash

To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Download the free Flash Player now!

Get Adobe Flash Player

Creative Commons License

Search Support


Document Details

ID:tn_15639
Browser:Chrome
Internet Explorer
Netscape
Opera
Safari
Firefox
Database:DB2
Informix
MySQL
Oracle
SQL Server
Sybase
MS Access

Products Affected: