Flash External API
F-IN-BOX supports the Flash External API, which enables two-way communication between a Flash movie and the host application.
Unlike fscommand
, External API calls are synchronous and allow direct data exchange.
Call an ActionScript Function from an Application
In the Flash movie, register a function 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";
}
In the application, use FPCCallFunction
or FPCCallFunctionBSTR
to call this function:
C++ Example (FPCCallFunction)
TCHAR szResponse[1024] = { 0 };
DWORD dwLength = sizeof(szResponse) / sizeof(szResponse[0]) - 1;
FPCCallFunction(
m_hwndFlashPlayerControl,
_T("<invoke name=\"CallMeFromApplication\" returntype=\"xml\"><arguments><string>Some text for FlashPlayerControl</string></arguments></invoke>"),
szResponse,
&dwLength
);
AfxMessageBox(CString(_T("The function returned: ")) + szResponse);
C++ Example (FPCCallFunctionBSTR)
BSTR bstrRequest = SysAllocString(
L"<invoke name=\"CallMeFromApplication\" returntype=\"xml\"><arguments><string>Some text for FlashPlayerControl</string></arguments></invoke>"
);
BSTR bstrResponse;
if (S_OK == FPCCallFunctionBSTR(m_hwndFlashPlayerControl, bstrRequest, &bstrResponse)) {
USES_CONVERSION;
CString str = OLE2T(bstrResponse);
AfxMessageBox(CString(_T("The function returned: ")) + str);
SysFreeString(bstrResponse);
}
SysFreeString(bstrRequest);
Call an Application Function from a Flash Script
From the Flash side, use ExternalInterface.call
:
on (click) {
_root.TextArea1.text = flash.external.ExternalInterface.call("SomeFunction");
}
On the application side, handle notification FPCN_FLASHCALL:
C++ Example
LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
if (WM_NOTIFY == message) {
LPNMHDR lpNMHDR = (LPNMHDR)lParam;
if (m_hwndFlashPlayerControl == lpNMHDR->hwndFrom) {
switch (lpNMHDR->code) {
case FPCN_FLASHCALL: {
SFPCFlashCallInfoStruct* pInfo = (SFPCFlashCallInfoStruct*)lParam;
CString str;
str += _T("The request is: '");
str += pInfo->request;
str += _T("'");
AfxMessageBox(str);
COleDateTime now = COleDateTime::GetCurrentTime();
FPCSetReturnValue(
m_hwndFlashPlayerControl,
_T("<string>Current time is: ") +
now.Format() +
_T("\r\nThis info is returned from the handler</string>")
);
return 1;
}
}
}
}
return 0;
}