What is the correct way to use AS3 externs?

132 views
Skip to first unread message

Tiago Ling

unread,
Oct 2, 2013, 6:47:20 PM10/2/13
to haxe...@googlegroups.com
Hi, 

I'm using Haxe 3.0.1, targetting Flash 10.3 and trying to use a swc library with -swf-lib.
If i only add the library with "-swf-lib lib/framework.swc" it compiles, however the application does not recognize any "protected" variables, functions and properties. It returns me this error:

"[Fault] exception, information=TypeError: Error #1006: alignSite is not a function"

This happens because at runtime alignSite (in AS3 a protected function) the function simply does not exist.
I figure i could use extern classes to map this function and other properties which doesn't seem to appear at runtime and i did this: "haxe -swf nothing.swf --no-output -swf-lib framework.swc --gen-hx-classes" (just like in the haxe site).
After doing this i put the generated files in a classpath for my application to recognize. The extern classes generated also don't have the protected functions / properties, so i edited them manually to include these fields.

But when trying to compile, i receive the following error:

"[Fault] exception, information=VerifyError: Error #1053: Illegal override of onResize"

This is the original onResize function in AS3:

"protected function onResize(event:Event):void {}"

The extern class (this was added to the extern class manually and tested with private and public declarations - both resulted in the same error described above):

"function onResize(event:Event):Void;"

The haxe code which tries to override the function is this (also tried with public and private, same error):

"override function onResize(event:Event):Void {}"

I don't know if there is any step i'm missing, or if i'm doing something wrong, but it seems that using as3 classes with -swf-lib isn't a fully implemented solution yet, since protected declarations just aren't recognized both when using the library itself and when creating extern classes. 

Any help would be much appreciated,

Thanks in advance!

Luca

unread,
Oct 3, 2013, 2:52:31 AM10/3/13
to haxe...@googlegroups.com
protected functions in AVM2/AS3 can only be used from the class which defines them, or from a class which extends it. Functions most likely have to be overidden with the same access restrictions or tighter, so you'd have to add @:protected to your override method which will make Haxe compile that method with AS3 protected access instead of public access.

Tiago Ling

unread,
Oct 3, 2013, 9:38:03 AM10/3/13
to haxe...@googlegroups.com
Hi Luca,

Thanks for your answer, it solved my overriding problems!

But i still have the problem in which some functions and variables with protected declaration aren't being recognized at runtime (they are recognized normally at compile time, even with autocomplete from Flashdevelop). I have a haxe class which extends an as3 class from the swc. I also have an extern to this class, created from the swc.

On the child haxe class, trying to call "super.alignSite(0, 0)" yield the following runtime error:

[Fault] exception, information=ReferenceError: Error #1065: Variable alignSite is not defined.

Also, trying to just call "alignSite(0, 0)" or "this.alignSite(0, 0)" returns this error:

[Fault] exception, information=TypeError: Error #1006: alignSite is not a function

I'm declaring this function in the extern like this:

@:protected function alignSite(w:Int, h:Int):Void;
 
Any clues on why this is happening? Do i have to use any metadata in my class which extends from the one inside the swc, or are these only used in the extern? 

Thanks!

Tiago Ling Alexandre
Tel: +55 41 8819-3191



2013/10/3 Luca <delta...@hotmail.com>
protected functions in AVM2/AS3 can only be used from the class which defines them, or from a class which extends it. Functions most likely have to be overidden with the same access restrictions or tighter, so you'd have to add @:protected to your override method which will make Haxe compile that method with AS3 protected access instead of public access.

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages