我从Flash CS3 HELP里找来的...[ 进入FLASH CS3 IDE 然后按F1键打开 HELP ]
那两个例子都写在里面
章节路径分别是:
Programming ActionScript 3.0 > Using the external API > Example: Using the external API with a web page container
Programming ActionScript 3.0 > Using the external API > Example: Using the external API with an ActiveX container
例子很好理解...各文件也都有说明.因为章节太长.我就不贴了。 ..不过我还是贴了ExteranlAPI的基础说明....
说明如下.
____________________________________________________[摘抄 FlashCS3 Help 章节]________
Programming ActionScript 3.0 [ Chapter:章节名 as3编程 ]
Using the external API > Basics of using the external API [ Path:该章小节名: 使用扩展API > 使用扩展API基础]
Common external API tasks[扩展API基础任务]
The following common external API tasks are explained in this chapter:
- Getting information about the container application
- Using ActionScript to call code in a container application, including a web page or desktop application
- Calling ActionScript code from code in a container application
- Creating a proxy to simplify calling ActionScript code from a container application
Important concepts and terms[概念及重点]
The following reference list contains important terms used in this chapter:
- ActiveX container: A container application (not a web browser) that includes an instance of the Flash Player ActiveX control to display SWF content within the application.
- Container application: The application within which Flash Player is running a SWF file, such as a web browser and HTML page that includes Flash Player content.
- Projector: A SWF file that has been converted into a standalone executable file including Flash Player as well as the SWF file's content. A projector can be created in Adobe Flash CS3 Professional or using the standalone Flash Player. Projectors are commonly used to distribute SWF files by CD-ROM or in similar situations where download size is not an issue and the SWF author wants to be certain the user will be able to run the SWF file, regardless of whether Flash Player is installed on the user's computer.
- Proxy: A go-between application or code that calls code in one application (the "external application") on behalf of another application (the "calling application"), and returns values to the calling application. A proxy can be used for various reasons, including:
- To simplify the process of making external function calls by converting native function calls in the calling application into the format understood by the external application
- To work around security or other restrictions that prevent the caller from communicating directly with the external application
- Serialize: To convert objects or data values into a format that can be used to pass the values in messages between two programming systems, such as over the Internet or between two different applications running on a single computer.
Working through in-chapter examples[例子]
While you're working through this chapter, you might want to test the example code listings. Many of the code listings in the chapter are small listings of code for demonstration purposes rather than full working examples or code that checks values. Because using the external API requires (by definition) writing ActionScript code as well as code in a container application, testing the examples involves creating a container (for example, a web page containing the SWF) and using the code listings to interact with the container.
To test an example of ActionScript-to-JavaScript communication:
- Create a new Flash document and save it to your computer.
- From the main menu, choose File > Publish Settings.
- In the Publish Settings dialog box, on the Formats tab, confirm that the Flash and HTML check boxes are selected.
- Click the Publish button. This generates a SWF file and HTML file in the same folder and with the same name that you used to save the Flash document. Click OK to close the Publish Settings dialog box.
- Deselect the HTML check box. Now that the HTML page is generated, you are going to modify it to add the appropriate JavaScript code. Deselecting the HTML check box ensures that after you modify the HTML page, Flash will not overwrite your changes with a new HTML page when it's publishing the SWF file.
- Click OK to close the Publish Settings dialog box.
- With an HTML or text editor application, open the HTML file that was created by Flash when you published the SWF. In the HTML source code, add a script element and copy into it the JavaScript code from the example code listing.
- Save the HTML file and return to Flash.
- Select the keyframe on Frame 1 of the Timeline, and open the Actions panel.
- Copy the ActionScript code listing into the Script pane.
- From the main menu, choose File > Publish to update the SWF file with the changes that you've made.
- Using a web browser, open the HTML page you edited to view the page and test communication between ActionScript and the HTML page.
To test an example of ActionScript-to-ActiveX container communication:
- Create a new Flash document and save it to your computer. You may want to save it in the folder where your container application will expect to find the SWF file.
- From the main menu, choose File > Publish Settings.
- In the Publish Settings dialog box, on the Formats tab, confirm that only the Flash check box is selected.
- In the File field next to the Flash check box, click the folder icon to select the folder into which your SWF file will be published. By setting the location for your SWF file, you can (for example) keep the Flash document in one folder, but put the published SWF file in another folder such as the folder containing the source code for the container application.
- Select the keyframe on Frame 1 of the Timeline, and open the Actions panel.
- Copy the ActionScript code for the example into the Script pane.
- From the main menu, choose File > Publish to re-publish the SWF file.
Create and run your container application to test communication between ActionScript and the container application.
The two examples at the end of this chapter are full examples of using the external API to communicate with an HTML page and a C# desktop application, respectively. Those examples include the full code, including ActionScript and container error-checking code, which you should use when writing code using the external API. For another full example using the external API, see the class example for the ExternalInterface class in the ActionScript 3.0 Language and Components Reference.