Assigning a class to symbols in Flash

You can also assign a class to symbols that you might use in a Flash file, such as a movie clip object on the Stage.

To assign a class to a movie clip symbol:

  1. Select File > New and then select ActionScript File, and then click OK.
  2. Select File > Save As, name the file Animal.as, and save the file on your hard disk.
  3. Type the following code into the Script window:
    class Animal {
        public function Animal() {
            trace("Animal::constructor");
        }
    }
    

    This ActionScript creates a new class called Animal that has a constructor method that traces a string to the Output panel.

  4. Save your changes to the ActionScript file.
  5. Select File > New and then select Flash Document to create a new FLA file, and then click OK.
  6. Select File > Save As, name the file animal_test.fla, and save the file to the same folder as the Animal.as file you created in step 2.
  7. Select Insert > New Symbol to launch the Create New Symbol dialog box.
  8. Enter a symbol name of animal, and select the Movie Clip option.
  9. Click the Advanced button in the lower-right corner of the Create New Symbol dialog box to enable more options.

    The Advanced button is available when you are in the basic mode of the Create New Symbol dialog box.

  10. Click the Export for ActionScript check box in the Linkage section.

    Enabling this option allows you to dynamically attach instances of this symbol to your Flash documents during runtime.

  11. Enter an identifier value of animal_id, and set the ActionScript 2.0 Class to Animal (to match the class name specified in step 3).
  12. Select the Export in First Frame check box and click OK to apply your changes and close the dialog box.
  13. Save the Flash document and select Control > Test Movie.

    The Output panel displays the text from your Animal class's constructor function.

    NOTE

     

    If you need to modify the Movie Clip's Linkage properties, you can right-click the symbol in the document's library and select Properties or Linkage from the context menu.


Flash CS3