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.