Haxe swf lib in as3 project, stange error with valueOf()

46 views
Skip to first unread message

Andre Lacasse

unread,
Jun 15, 2016, 3:39:10 PM6/15/16
to Haxe
Hi,

I'm converting a small swf lib writing in as3 to Haxe in flex project and I got a weird error.

I wrote a extern class in my project. 

// Haxe
extern class WList extends TokenElement
{
 
public var items(default, null):Array<IReal>;
 
public var count(default, null):Int;
 
 
public function new(items:Array<IReal>);
 
 
public function valueOf():Array<Float>;
 
}

In Haxe, this line trigger the following error. 

Type Coercion failed: cannot convert Vector.<Number>@1c28a821 to Array.

//Haxe
trace
( "keys.valueOf():" + keys.valueOf() );


The class in Flex project

// AS3 WList function
public function valueOf():Vector.<Number>{return primitiveValue}


I don't understand why the Vector to Array conversion occur. I made a mistake or is bug? 

JLM

unread,
Jun 16, 2016, 6:25:57 AM6/16/16
to Haxe
It might be simpler just to port the code with tools or by hand.

I suspect that haxe.ds.Vector might abstract over as3 Vector ( you might want to look into the implementation on haxe github ).  So maybe you could try that instead.  Haxe array class is a different implementation from as3 vector, they are not really the same inside.

My suggestion is to perhaps create a small swc of https://github.com/polygonal/ds and use that in your as3 code along with Haxe data structures in your as3 code and forget hacky Vector.< as3 code. It will be then much easier to create externs which return haxe vectors, and your as3 code will probably run faster.  If your in a hurry just switch all your Vector.< to use arrays but that might be a typing nightmare and a lot slower.

But yer it's quite feasible to use polygonal and haxe types as a swc in your as3 code and then all your vectors will be compatible, I think polygonal's ones are probably very optimal and you have a wider assortment, which can help with improving performance, for instance polygonal has object pooling.

Andre Lacasse

unread,
Jun 16, 2016, 9:35:06 AM6/16/16
to Haxe
Hi JLM,

The solution with polygonal is interesting, I will look at it. In the manual for the compiler, In the Haxe swf, it's there a way to use haxelib for compilation checking only. Like external-library-path for in as3.

Thanx
André

JLM

unread,
Jun 16, 2016, 12:18:45 PM6/16/16
to Haxe
I am not sure I know, or really understand, suspect the question is beyond me. I found this?
-swf-lib-extern <file> : add the SWF library for type checking but don't include it in the compiled SWF.
If you have real problem with mixing as3 into haxe you can load a swf at runtime and use reflection to resolve classes and types etc... often easier to work with a loaded swf than compiling one into the swf.  I would not advise using Flex components in Haxe it's just too much effort and I never use them. Often it's easier to load haxe into as3 rather than the other way round for instance timeline preloading of assets not on first frame is ideal in flash timeline and load haxe game logic in.

JLM

unread,
Jun 16, 2016, 12:19:30 PM6/16/16
to Haxe
sorry not to be able to answer your extended question.

Andre Lacasse

unread,
Jun 17, 2016, 10:02:09 AM6/17/16
to Haxe
JLM currently your answer is helpful, I was trying to use lib in the Haxe project, but I can use -swf-lib-extern with the polygonal.swc to prevent bytecode duplication.

Thank
Reply all
Reply to author
Forward
0 new messages