CallFunction(Request: String): String;
CallFunction(Request: String): String;
Request. The XML string that is used to specify the executed function and its parameters.
The CallFunction method executes the function implemented in the loaded Flash object and returns execution result.
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, register this function in the ExternalInterface class. Registration is executed by the ExternalInterface.addCallback method.
Specify an XML string as a 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. The "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 this properties. |
Other embedded 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.
Executing the example requires a regular report. A Flash object with the PrxFlash1 identifier is added on the report sheet. The Flash object contains the following code in its implementation:
//...
function TestFunc(i1,i2: int): Number
{
var i3: Number = i1 * i2 / (i1 + i2);
return i3;
}
ExternalInterface.addCallback("TestFunc", TestFunc); /The function is available with the TestFunc name in containers for the Flash object
//...
A hyperlink set up for calling the following procedure is created in the sheet cell:
Sub TestFunction;
Var
Sheet: IPrxSheet;
TSheet: ITabSheet;
Flash: IPrxFlash;
SWFlash: IShockWaveFlash;
Request, Result: String;
Begin
Debug.WriteLine("TestRun");
Sheet := PrxReport.ActiveReport.ActiveSheet;
TSheet := (Sheet As IPrxTable).TabSheet;
Flash := TSheet.Objects.Object("PrxFlash1") As IPrxFlash;
SWFlash := Flash.ShockWaveFlash;
Request := "<invoke name=""TestFunc"" returntype=""xml"">" +
"<arguments>" +
"<number>2</number>" +
"<number>6</number>" +
"</arguments>" +
"</invoke>";
Result := SWFlash.CallFunction(Request);
TSheet.ParseCell("A0").Value := Result;
End Sub TestFunction;
On executing this procedure the TestFunc function of the Flash object is executed. 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 shown as an XML string: <number>1.5</number>. Execution result is saved to the A0 cell of the sheet.
See also: