Importing user defined classes into other .as files.

Mark Hammond mhammond at
Mon Jan 14 17:30:11 PST 2008

> I am trying to import one class into another class. For example I have

> package avmclass
> {
>     public class A
>     {
>         public function func()
>         {
>             trace ("A::func123"); 
>         }
>     }
> }

You need to tell the compiler where 'trace' is located.  Inserting:

    import avmplus.System.*

just before the class definition should do the job.  You then need to
compile this to a .abc file.  I used the command:

% java -ea -DAS3 -Xmx200m -DAVMPLUS -classpath ../utils/asc.jar
macromedia.asc.embedding.ScriptCompiler -abcfuture -builtin -import
../core/ -import ../shell/

Note that 2 imports seem necessary - the core builtins (for Object) and the
shell's toplevel, for avmplus.System.trace.  If you use the 'esc' compiler
this doesn't seem necessary.

> I have named this file as "" and kept it in "avmclass" under root

> Then I have created new file "" in root folder.
> The contents of is 

> package
> {
>  import avmclass.A;
> var b1 = new avmplus.A();

Note the typo in the above line - you want to create avmclass.A - avmplus.A
doesn't exist.

>  b1.func();
> }

I can then compile this file with:

% java -ea -DAS3 -Xmx200m -DAVMPLUS -classpath utils/asc.jar
macromedia.asc.embedding.ScriptCompiler -abcfuture -builtin -import
core/ -import ./avmclass/

Note that this time I did not need to reference the shell's .abc, as we
didn't use anything from it - but I did need to reference the .abc we
compiled above.

Once you have the 2 .abc files, you can execute 'avmplus_sd.exe
avmclass/', and you see the trace on your console.

Hope this helps,


More information about the Tamarin-devel mailing list