I'm having some problems to port as3 code to Haxe 3

131 views
Skip to first unread message

Marcio Andrey Oliveira

unread,
Nov 28, 2013, 4:44:29 PM11/28/13
to haxe...@googlegroups.com

Hi.

I'm trying to port an as3 script to Haxe but I'm having some issues.

There is a function declared as follow:

public static function show(_root:Object, publisherNumber:uint, gameCode:uint, retFunction:Function= null):void

and I ported it to

public static function show(_root:Dynamic, publisherNumber:UInt, gameCode:UInt, retFunction = null):Void

I'm not sure whether Function type can be replaced by Dynamic so I let it with out any type.

Is this approach correct? In negative case, which would be the most appropriate action?


The other part that seems more problematic for me is the following:

var myClient = new Object();
MyLocalConnection.client = myClient;
           
myClient
.receiveMethod = function receiveMethod(fkMessage)
{
   
if (fkMessage == "go_live") // Ad is over, start the game...
        closeAd
();
};


When I try to replace

var myClient = new Object();

by

var myClient:Dynamic = new Dynamic();

I get the following error message from compiler:

src/com/plicatibu/flash/lib/MyLib.hx:74: characters 35-48 : Dynamic<Unknown<0>> cannot be constructed

Then I changed it to the following:

var myClient:Array<Dynamic> = new Array<Dynamic>();

This solved the compiler error but I'd like to understand why the first form doesn't work and the latter does. Also, I'd like to know it's consequences and if there is a better approach for this case.

The remaining of the code became

MyLocalConnection.client = myClient;
           
myClient
[0].receiveMethod = function receiveMethod(fkMessage)
{
   
if (fkMessage == "go_live") // Ad is over, start the game...
        closeAd
();
};

Now when I run the test program, every time that the line

myClient[0].receiveMethod = function receiveMethod(fkMessage)

is executed I get the following error message:

[Fault] exception, information=TypeError: Error #1010: A term is undefined and has no properties.

I thought that the message error was caused because I didn't added anything to myClient[0]  as MyLocalConnection is of type MyLocalConnection I tried the following:

var myClient:Array<Dynamic> = new Array<Dynamic>();

myClient
[0] = new LocalConnection();

funklicksLocalConnection
.client = myClient;
           
myClient
[0].receiveMethod = function receiveMethod(fkMessage)
{
   
if (fkMessage == "go_live") // Ad is over, start the game...
        closeAd
();
};


but now I receive the error message when the line

myClient[0].receiveMethod = function receiveMethod(fkMessage)

is executed changed to

[Fault] exception, information=ReferenceError: Error #1056: Cannot create property receiveMethod on flash.net.LocalConnection.

Does anyone could help me to understand what I'm doing wrong and (hopefully) solve the problem?

Thank you all.

Tom

unread,
Nov 28, 2013, 5:30:29 PM11/28/13
to haxe...@googlegroups.com
Hi!

1. The retFunction type should be Dynamic, too.

2. var myCliend:Dynmic; // is fine. Dynamic doesn't have any constructor. Maybe if you want something to do: var myClient:Dynamic = {}; // is fine too.

3. In this row, You want to redefine the receiveMethod parameter. You can't. You can just point into a function, not redefine.

myClient[0].receiveMethod = function receiveMethod(fkMessage)
{
   
if (fkMessage == "go_live") // Ad is over, start the game...
        closeAd
();
};


And this should work:

var myClient:Dynamic = {receiveMethod: receiveMethodFunction }; // the first one is the name in the "Object", the second is a real function
var LC:LocalConnection = new LocalConnection();
LC
.client = myClient; // myClient can be a Class, which has a function, that You want to handle the LC connection

...

private function receiveMethodFunction(fkMessage)
{
   
if (fkMessage == "go_live") // Ad is over, start the game...
        closeAd
();
};

Cheers!
Tom

Marcio Andrey Oliveira

unread,
Nov 28, 2013, 6:09:23 PM11/28/13
to haxe...@googlegroups.com
Tom, you're my new hero :) 

Seriously, the solution you provided me worked like a charm. 

And the explanation teached me a lot too.

Thank you very much for your help.

Tom

unread,
Nov 29, 2013, 1:39:43 AM11/29/13
to haxe...@googlegroups.com
You are welcome!
Reply all
Reply to author
Forward
0 new messages