AS call JS method (example)
The code is as follows: |
Copy code |
Code in Flash: // Import the package Import flash. external .*; Get_btn.onRelease = function (){ // Call JS functions on the page Var temp_str = String (ExternalInterface. call ("say", "Hello, World ")); Result_txt.text = temp_str; } Code in Html: Function say (txt ){ Return txt; } |
JS calls the AS method
The code is as follows: |
Copy code |
Code in FLASH: // Import package Import flash. external .*; // Provide the function name for JS access Var _ method: String = "say "; // Specify the scope of this variable in the local function. It can be set to null and left empty. Var e_area: Object = null; // AS internal function name Var method: Function = say; // Register the function to the container list Var wasSuccessful: Boolean = ExternalInterface. addCallback (_ method, e_area, method ); // Check whether the registration is successful If (wasSuccessful ){ Result_txt.text = "function registration successful "; } // Local function Function say (txt: String ){ Result_txt.text = txt; } Code in Html: <div> <Form> <Input type = "button" onclick = "callExternalInterface ()" value = "JS call AS method"/> </Form> <Script> Function callExternalInterface (){ ThisMovie ("demo"). say ("Hello, World "); } // The browser is compatible with DOM Function thisMovie (movieName ){ If (navigator. appName. indexOf ("Microsoft ")! =-1 ){ Return window [movieName] } Else { Return document [movieName] } } </Script> </Div> |
All of the above functions are described. The following describes how to highlight the IE window when FLASH has a message.
Add code in HTML
The code is as follows: |
Copy code |
<Script language = "JavaScript"> Function windowstiao (){ Window. focus (); } </Script> |
Add the call function in FLASH. Pay attention to the bold section.
The code is as follows: |
Copy code |
Import flash. external. ExternalInterface; Function textadd (): Void { My_text.text + = "Add a first! "; ExternalInterface. call ("windowstiao "); } My_id = setInterval (textadd, 3000 ); Function clearit (): Void { ClearInterval (my_id ); } My_id2 = setInterval (clearit, 30000 ); |
Is it easy.