如何在Flex Builder中使用Flash CS3组件

经过我的多次测试,发现直接引用Flash的SWC包只能获得相应的代码提示,并不能完全解决纯FlexBuilder编译的问题。因此,如果你想彻底抛弃FLA,又希望能用Flash CS3的组件,必须先在FlashCS3中导出一个SWC,再将这个SWC引入到Flex的Library Path中。这种解决方案来自大名鼎鼎的moockblog同学:

    As a simple example, let’s assume we want to use the V3 TextArea component in Flex Builder. Here’s the general process we follow:

    1) Create a .swc file containing the desired V3 components.
    2) Add the .swc file from Step 1 to the Flex Builder project’s Library path.
    3) Import and use the component classes.

    To generate the .swc file in Flash CS3, we follow these steps:

    1) Make a new Flash CS3 ActionScript 3.0 .fla file.
    2) Drag the desired component(s) to the Library. In this example, we’ll drag the TextArea component to the Library.
    3) Choose File > Export > Export Movie.
    4) For File name, enter v3components.swf. (We don’t even want the generated .swf, but there’s no other way to get the .swc to compile.)
    5) Select a folder in which to save the .swf file.
    6) Click Save.
    7) In the Export Flash Player dialog, check Export SWC.
    8) Click OK.

    The preceding steps generate two files, v3components.swf and v3components.swc, both of which are placed in the folder selected in Step 5.

    Now let’s use v3components.swc in a Flex Builder project. Follow these steps:

    1) In Flex Builder, select File > New > ActionScript Project.
    2) For Project name, enter "V3Test.as".
    3) Click Next.
    4) For Main source folder, enter "src".
    5) For Main application file, enter "V3Test.as".
    6) On the Library path tab, click Add SWC.
    7) Browse to the v3components.swc file from the preceding procedure.
    8) Click Finish.
    9) Update the code in V3Test.as so it looks like this:

  package {
      import flash.display.Sprite;
      import fl.controls.TextArea;
      public class V3Test extends Sprite {
        public function V3Test() {
          var t:TextArea = new TextArea();
          t.text = "You're not cookin'";
          addChild(t);
        }
      }
    }
 
    10) Run the project.

你可能感兴趣的:(Flex,Flash,actionscript)