F-IN-BOX DLL Edition Help >> Native Flash ActiveX Interface

External API

F-IN-BOX supports External API. You can call functions of a movie and a movie is able to get data from an application synchronously (instead of fscommand).

Call an ActionScript function from an application

Register your function using ExternalInterface.addCallback:

[ ActionScript ]
  1. import flash.external.*;  
  2.   
  3. ExternalInterface.addCallback("CallMeFromApplication"this, InternalFunction);  
  4.   
  5. function InternalFunction(str: String): String {  
  6.     TextArea1.text = str;  
  7.   
  8.     return "The function was called successfully";  
  9. }  

Use function FPCCallFunction or FPCCallFunctionBSTR:

[ C++ ]
  1. TCHAR szResponse[1024] = { 0 };  
  2.   
  3. DWORD dwLength = sizeof(szResponse) / sizeof(szResponse[0]) - 1;  
  4.   
  5. FPCCallFunction(m_hwndFlashPlayerControl,   
  6.   
  7. _T("<invoke name=\"CallMeFromApplication\" returntype=\"xml\"><arguments><string>Some text for FlashPlayerControl</string></arguments></invoke>"),   
  8.   
  9. szResponse,   
  10.   
  11. &dwLength);  
  12.   
  13. AfxMessageBox(CString(_T("The function returned: ")) + szResponse);  


[ C++ ]
  1. BSTR bstrRequest = SysAllocString(L"<invoke name="\"CallMeFromApplication\"" returntype="\"xml\""><arguments><string>Some text for FlashPlayerControl</string></arguments></invoke>");  
  2.   
  3. BSTR bstrResponse;  
  4.   
  5. if (S_OK ==   
  6.     FPCCallFunctionBSTR(m_hwndFlashPlayerControl,   
  7.                 bstrRequest,   
  8.             &bstrResponse))  
  9. {  
  10.     USES_CONVERSION;  
  11.   
  12.     CString str = OLE2T(bstrResponse);  
  13.   
  14.     AfxMessageBox(CString(_T("The function returned: ")) + str);  
  15.   
  16.     SysFreeString(bstrResponse);  
  17. }  
  18.   
  19. SysFreeString(bstrRequest);  

Call an application function from a flash script

Use flash.external.ExternalInterface.call:

[ ActionScript ]
  1. on (click) {  
  2.     _root.TextArea1.text = flash.external.ExternalInterface.call("SomeFunction");  
  3. }  

Handle notification FPCN_FLASHCALL:

[ C++ ]
  1. <div class="code">  
  2. LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)  
  3. {  
  4.     if (WM_NOTIFY == message)  
  5.     {  
  6.         LPNMHDR lpNMHDR = (LPNMHDR)lParam;  
  7.   
  8.         if (m_hwndFlashPlayerControl == lpNMHDR->hwndFrom)  
  9.             switch (lpNMHDR->code)  
  10.             {  
  11.                 case FPCN_FLASHCALL:  
  12.                 {  
  13.                     SFPCFlashCallInfoStruct* pInfo = (SFPCFlashCallInfoStruct*)lParam;  
  14.   
  15.                     CString str;  
  16.                     str += _T("The request is: '");  
  17.                     str += pInfo->request;  
  18.                     str += _T("'");  
  19.   
  20.                     AfxMessageBox(str);  
  21.   
  22.                     COleDateTime now = COleDateTime::GetCurrentTime();  
  23.                     FPCSetReturnValue(m_hwndFlashPlayerControl,   
  24. _T("<string>Current time is: ") +   
  25. now.Format() +   
  26. _T("\r\nThis info is returned from the handler</string>"));  
  27.   
  28.                     return 1;  
  29.             }  
  30.         }  
  31. ...  
  32. }  
  33. </div>  


Copyright © Softanics. All rights reserved.
F-IN-BOX is a trademark of Softanics.
Macromedia and Shockwave Flash are trademarks of Adobe