一直不明白如何将很多的类编译成一个swc文件,并且在Flash里可用,就像Google Map Flash API一样,今天终于找到了。http://vincent.the.tsao.googlepages.com/ 这篇文章有很详细的说明。现转于此:
Using Flex SWC Files in the Flash CS3 Authoring Environment
by Vincent Tsao
Problem
Many API’s or code libraries written in ActionScript 3 and compiled into SWC files are meant for use with Flex tools and are unable to be imported into the Flash CS3 Authoring Environment. This tutorial will show you how you can (theoretically) take any SWC made for Flex and use it in Flash CS3.
Resources
You will need the following programs/tools:
- Flash CS3
- Flex SDK 2.0.1 with Hotfix 3
(note that we are intentionally NOT using Flex SDK 3.0)
You can get Flex SDK 2.0.1 with Hotfix 3 here:
http://labs.adobe.com/technologies/flex/sdk/flex2sdk.html
Explanation
If you just want the steps, you can skip down to the next section, but this describes why the method works. When we say “Flex SWC”, what we really mean is a code-only SWC file which contains no DisplayObject components. Only SWC files with a DisplayObject component can be imported into the Flash CS3 Authoring Environment. Thus in order to make a Flex SWC usable in Flash CS3, we use the Flex SDK’s compc tool to statically link it with a stub SWC file generated in Flash CS3 that is a DisplayObject. We require the Flex SDK 2.0.1 Hotfix 3 version of compc because Flex SDK 3.0’s compc utility generates SWC files of version 1.2 and Flash CS3 can only use SWC files of version 1.0. More over, earlier versions of the Flex SDK 2.0.1 compc utility could not read SWC files compiled by the Flash CS3 authoring environment, thus the need for Hotfix 3. So the newly compiled SWC file is actually two SWC files put into one – a DisplayObject SWC and the original Flex SWC and can therefore be used within Flash CS3.
Steps
Part I: Creating a Stub DisplayObject SWC in Flash CS3
- Create a new ActionScript 3 FLA file in Flash CS3.
- Create a new symbol in the library (you do not need to create an instance of it), name it whatever you want.
- Go into your library and right click on the symbol you just created. Select “Component Definition…”
- Type in whatever you want your component to be called as the class name (no spaces).
- Under the options part, check all the boxes and ensure the minimum Flash Player is 9 and the minimum ActionScript version is 3.
- Leave everything else alone, press OK.
- Right click the symbol again in your library and select and select “Linkage…”
- Check the “Export for ActionScript” box and the “Export in first frame” box should be automatically checked as well.
- The class name should be the same name you gave it earlier.
- Ensure the base class is indeed MovieClip, click OK.
- Right click the symbol again in your library and select “Export SWC File…”
- Pick a place to save it.
Part II: Putting the two SWC Files Together
- Use the compc program to wrap what you have just created with the Flex SWC you want to use in the Flash CS3 authoring environment. Here is a simple example:
compc -source-path+=. -output=bin\map_flash_1_6.swc -include-libraries=.\GoogleMapsFlashAPI.swc,.\map_flex_1_6.swcNote the above command is all on one line (no line breaks). The file “map_flash_1_6.swc” is the name we choose for the component we output. “GoogleMapsFlashAPI.swc” is the name of the SWC we created in Flash CS3 in Step 1 and “map_flex_1_6.swc” is the SWC you want to be able to use in Flash CS3. - Place your newly generated SWC file in your Flash components folder. It should be something like “\Adobe Flash CS3\en\Configuration\Components\”. If you are unsure where this is located on your computer, Google it.
- Open the FLA file you want to import the SWC into and open the Components panel (Ctrl+F7 in Windows).
- Reload the Components panel if necessary.
- Drag your SWC file into your library (note: that there does NOT need to be an instance of the SWC on your stage since it would be useless).
Please let me know if this does not work.
My contact is vincent.the.tsao [--at--] gmail [--dot--] com
Hi, interesting post. I have been thinking about this issue,so thanks for posting. I’ll definitely be subscribing to your blog. Keep up the good posts
[Translate]
Спасибо, весьма познавательно! Вот только не пойму как rss канал настроить
[Translate]
Great post! Just wanted to let you know you have a new subscriber- me!
[Translate]
Killzone 2 – the best PS3 game yet?Still LittleBigPlanet for me, but Sony’s new shooter is mightily impressive.
What you think about my web? http://www.easyfaxlesspaydayloan.com/payday-loans-online.html
[Translate]
Some of us even don’t realize the importance of this information. What a pity.
[Translate]