Flash External API
F-IN-BOX supports the Flash External API. This enables two-way communication:
- Applications can call ActionScript functions inside a Flash movie.
- Flash movies can synchronously call functions exposed by the host application.
This mechanism works instead of the legacy fscommand
approach.
Call an ActionScript Function from an Application
First, register a function in the Flash movie using ExternalInterface.addCallback
:
import flash.external.*;
ExternalInterface.addCallback("CallMeFromApplication", this, InternalFunction);
function InternalFunction(str: String): String {
TextArea1.text = str;
return "The function was called successfully";
}
Then call the ActionScript function from the application using CallFunction:
Delphi Example:
var
Response: WideString;
begin
Response := FlashPlayerControl1.CallFunction('Some text for TFlashPlayerControl');
ShowMessage(Format('The function returned: %s', [Response]));
end;
C++Builder Example:
WideString Response = FlashPlayerControl1->CallFunction("Some text for TFlashPlayerControl");
ShowMessage("The function returned: " + Response);
Call an Application Function from a Flash Script
From ActionScript, call an application function using flash.external.ExternalInterface.call
:
on (click) {
_root.TextArea1.text = flash.external.ExternalInterface.call("SomeFunction");
}
Handle the call in the application with the OnFlashCall event and provide a return value using SetReturnValue:
Delphi Example:
procedure TMainForm.FlashPlayerControl1FlashCall(ASender: TObject; const request: WideString);
begin
FlashPlayerControl1.SetReturnValue('Current time is: ' +
TimeToStr(Time) + #13#10 +
'This info is returned by application');
end;
C++Builder Example:
void __fastcall TMainForm::FlashPlayerControl1FlashCall(TObject *ASender, const WideString request)
{
FlashPlayerControl1->SetReturnValue("Current time is: " +
TimeToStr(Time()) +
"\r\nThis info is returned by application");
}