IFlashBox.CallFunction

Fore Syntax

CallFunction(Request: String): String;

Fore.NET Syntax

CallFunction(Request: String): String;

Parameters

Request. The XML string, which helps to specify the executed function and its parameters.

Description

The CallFunction method executes the function implemented in the loaded Flash object and returns execution result.

Comments

Interaction of Flash objects with containers, in which these objects are displayed, is executed in ActionScript by the special ExternalInterface class. To call any function implemented in ActionScript code, this function must be registered in the ExternalInterface class. Registration is executed by the ExternalInterface.addCallback method.

Specify an XML string as the Request parameter, containing the name and parameter values of this function implemented in special format to call the ActionScript code by the CallFunction method. General type of XML string format looks as follows:

<invoke name="functionName" returntype="xml">

    <arguments>

        //Individual values of parameters

    </arguments>

</invoke>

The Invoke root node contains two attributes: name - name of a function, by which it is registered with a help of the ExternalInterface.addCallback method; returntype - value of a type returned by the CallFunction method. xml is always used as an attribute value.

Separate parameter values are specified in special format containing information about the data type in addition to the actual value:

ActionScript class or value Format Comments
null <null/>  
Logical True <true/>  
Logical False <false/>  
String <string>Value</string>  
Number, int, uint <number>Value</number>  
Array (elements can be of different types)

<array>

    <property id="0">

        <number>Value</number>

    </property>

    <property id="1">

        <string>Value</string>

    </property>

    ...

</array>

The "property" node determines a single array element, and the "id" attribute determines an element index. Index specification starts with zero.
Object

<object>

    <property id="Property1">

        <string>Value</ String>

    </property>

    <property id="Property2">

        <string>Value</String>

    </property>

    ...

</object>

The "property" node determines separate object properties, and the "id" attribute determines names of these properties.
Other nested or custom classes

<null/> or

<object> </object>

ActionScript encodes other objects as the null value or as empty objects. Any property values can be lost in any case.

An XML string contains execution results of Flash object specified function that is a result of the CallFunction method work. This string also contains information about the data type in addition to the actual value.

Fore Example

Executing the example requires a form, the FlashBox component with the FlashBox1 name located on it and two buttons named Button1 and Button2. An SWF file, which is loaded to FlashBox1, contains the following code:

//...

function Run(): void

{

//...Function code in ActionScript;

}

function TestFunc(i1,i2: int): Number

{

var i3: Number = i1 * i2 / (i1 + i2);

return i3;

}

ExternalInterface.addCallback("TestRun", Run); //Function is available with the TestRun name in containers for the flash object

ExternalInterface.addCallback("TestFunc", TestFunc); /Function is available with the TestFunc name in containers for the flash object

//...

Implement two procedures to handle the OnClick event of buttons to start specified functions when executing a form:

    Sub Button1OnClick(Sender: Object; Args: IMouseEventArgs);
    Var
        Request: String;
    Begin
        Request := ("<invoke name=""TestRun"" returntype=""xml""/>");
        FlashBox1.CallFunction(Request);
    End Sub Button1OnClick;

    Sub Button2OnClick(Sender: Object; Args: IMouseEventArgs);
    Var
        Request, Result: String;
    Begin
        Request := "<invoke name=""TestFunc"" returntype=""xml"">" +
                    "<arguments>" +
                        "<number>2</number>" +
                        "<number>6</number>" +
                    "</arguments>" +
                "</invoke>";
        Result := FlashBox1.CallFunction(Request);
    End Sub Button2OnClick;

The Run flash object function is executed by clicking the first button. This function has no parameters so the "arguments" node in the passed XML string is not specified.

The TestFunc Flash object function is executed by clicking the second button. The values 2 and 6 will be specified as parameter values for this function. The result of this function execution is the 1.5 value. The CallFunction method returns this value represented as an XML string: <number>1.5</number>.

Fore.NET Example

Executing the example requires a form, the FlashBoxNet component with the FlashBoxNet1 name located on it and two buttons named Button1 and Button2. An SWF file containing the code, specified in the Fore example above, is loaded to FlashBoxNet1.

Implement two procedures to process the Click event of buttons to start Flash object functions when executing a form:

    Private Sub button1_Click(sender: System.Object; e: System.EventArgs);
    Var
        Request: String;
    Begin
        Request := ("<invoke name=""TestRun"" returntype=""xml""/>");
        FlashBoxNet1.CallFunction(Request);
    End Sub;
    
    Private Sub button2_Click(sender: System.Object; e: System.EventArgs);
    Var
        Request, Result: String;
    Begin
        Request := "<invoke name=""TestFunc"" returntype=""xml"">" +
                    "<arguments>" +
                        "<number>2</number>" +
                        "<number>6</number>" +
                    "</arguments>" +
                "</invoke>";
        Result := FlashBoxNet1.CallFunction(Request);
    End Sub;

The Run Flash object function is executed by clicking the first button. This function has no parameters so the "arguments" node in the passed XML string is not specified.

The TestFunc flash object function is executed by clicking the second button. The values 2 and 6 will be specified as parameter values for this function. The result of this function execution is the 1.5 value. The CallFunction method returns this value represented as an XML string: <number>1.5</number>.

See also:

IFlashBox