Importing user defined classes into other .as files.

Mark Hammond mhammond at skippinet.com.au
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/builtin.abc -import ../shell/toplevel.abc A.as

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 "A.as" and kept it in "avmclass" under root
folder.

> Then I have created new file " caller.as" in root folder.
> The contents of caller.as 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/builtin.abc -import ./avmclass/A.abc caller.as

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/A.abc caller.abc', and you see the trace on your console.

Hope this helps,

Mark




More information about the Tamarin-devel mailing list