AS3 - How to import a class file?

10,638
  1. import com.example.* for importing all package or import com.example.Test for single class.

  2. Class and file must have the same name (rename to Test.as or change class name to Courseware)

  3. Test class file (Test.as) must be in com/example folder (create folders and copy class file ).

Share:
10,638
Fariz Luqman
Author by

Fariz Luqman

My Github profile: https://github.com/farizluqman Visit my website: https://farizluqman.com

Updated on June 04, 2022

Comments

  • Fariz Luqman
    Fariz Luqman almost 2 years

    I'm a newbie to Adobe Flash CS 6 and ActionScript 3.0 (AS3). I have difficulties trying to understand how to include a class file into my project.

    The problem is, I want to add a class file (.as) into my flash project (.fla). They are in the same folder with my project file (Courseware.fla and Courseware.as). Among the things that I have tried is:

    On flash project:

    import com.example;
    

    On class file:

    package com.example
    {
        public class Test
        {
            public function display():void
            {
                trace("here");
            }
        }
    }
    

    But however, I received this error:

    Scene 1, Layer 'Master Frame', Frame 1, Line 1  1172: Definition com:example could not be found.
    

    I'm clueless on how to fix this error. Can someone guide me on how to create and import class properly into a flash project? Thank you!