How to Import SWC to AS3

SWC files store Flash components that can be used in other Flash programs. Because SWC components are so easy to incorporate into a Flash project, developers will build libraries of SWC components to reuse in all their Flash projects. This saves developers the task of having to recode components and the tedious job of having to import ActionScript 3 (AS3) code. Working from SWC component libraries is often preferred over directly importing AS3. The function of SWC components can't be inadvertently changed, which makes large scale SWC-based Flash projects easier to maintain and more reliable.

Instructions

    • 1

      Check the documentation associated with the SWC file for the class package name. Look on the website you downloaded the SWC file from or ask the developer that created the SWC for the class package name. For this example, a SWC file named "rotateanimation.swc" was used. The SWC file was linked with a class package named "star4.star."

    • 2

      Start the Flash program. Click "Flash File(ActionScript 3.0)" from the splash window to create a new file for an AS3 Flash animation project. Save the file and write down the directory that you saved it into.

    • 3

      Move the "swc" file to the same directory as the Flash file you just saved.

    • 4

      Select "Actions" from the "Window" menu on the main Flash menu bar to open the ActionScript 3 editor. Position your mouse cursor on the first line of the ActionScript 3 editor. Click your mouse button, and type in the code below:

      import star5.star;

      This import statement will import the component called star from the "rotateanimation.swc" SWC file into the Flash program when the Flash program is played.

    • 5

      Type in the code below to place the SWC component on the stage when the movie plays to verify that the component was imported:

      var firststar:star = new star();

      stage.addChild(firststar);

      firststar.x = 400

      firststar.y = 200

      The code creates an instance of the component in the SWC file and places it on the Flash stage at stage coordinates (400,200) when the movie plays.

    • 6

      Click "Test Movie" in the "Control" menu to play the program and verify that the component from the SWC file has been imported. The component will be displayed on the stage at location (400,200).

Learnify Hub © www.0685.com All Rights Reserved