Please help me in converting a normal Actionscript code to Haxe code

Hi Guys,

I am new to OpenFL and Haxe .I am Phaser Developer . Can you please help in converting this simple touch flash file so that it acts as reference for my project conversions .

https://drive.google.com/open?id=1s5u7smKXGNT3YijA5UGCDZC3gCl6VXKE

It would be very helpful if you help me in converting this File ASAP.

Thanks,
Raghava

People already gave you a lot of information in your previous topic : Conversion of Flash game to Hmtl5

The file that you are trying to convert is pretty small, so if you really are a developer, you should know what has to be done. But, I’m a bit skeptical, after realizing that you can’t read compiler errors : TypeError: cl is not a constructor

Moreover, this is not the place to ask others to work for you, neither “ASAP”.
There is a “Jobs” section that you may check instead.

Well thanks for the reply. I have mentioned that I am phaser developer I hoped that some help would be given from community side. I even apologize cause the deadline is short.
Thanks for the help .I have removed the file access .
Admin can removed this thread :sleepy::sleepy::cry:

Hello!

Please don’t feel bad about asking questions. In the future, using the same thread for similar questions is probably better, that’s all :slight_smile:

I’ll send you a PM

@Sai_Raghava Hello again! Thank you for sharing your file!

I have it up and running here. It was quite simple, but I totally understand that these little differences are not something that would be obvious at first.

I opened your project, and ran a command to test your project (like this one):

openfl test html5

I got these five errors:

Source/Main.hx:43: characters 24-29 : Type not found : as3hx.Compat
Source/Main.hx:44: characters 24-29 : Type not found : as3hx.Compat
Source/Main.hx:46: characters 22-28 : Type not found : Player
Source/Main.hx:66: characters 8-36 : Float should be Int
Source/Main.hx:67: characters 8-36 : Float should be Int

Never fear! Here was the first set:

Type not found : as3hx.Compat

Before

_destinationX = as3hx.Compat.parseInt(stage.stageWidth / 2);
_destinationY = as3hx.Compat.parseInt(stage.stageHeight / 2);

After

_destinationX = Math.round(stage.stageWidth / 2);
_destinationY = Math.round(stage.stageHeight / 2);

I did not include the as3hx haxelib in the project, but personally, I don’t use the as3hx Compat class, anyway. I’ll explain Float and Int in a moment, here’s the last two errors:

Float should be Int

Before

_destinationX = event.stageX;
_destinationY = event.stageY;

After

_destinationX = Std.int(event.stageX);
_destinationY = Std.int(event.stageY);

Float vs Int

You probably know, that Float represents a floating point number (1.0001, 2.2 or 3.0) and Int represents an integer (1, 2 or 3).

Haxe does not allow Float to be converted implicitly to an Int. You have to either decide to keep it as a Float, or to use a method such as Std.int to opt-into potentially losing precision between the types. So in the above cases, event.stageX and event.stageY are Float values.

Although stage.stageWidth and stage.stageHeight are Int values, dividing will cause Haxe to treat the result as a Float, so stage.stageWidth / 2 also is a Float.

The alternative approach here is to change _destinationX and _destinationY to Float values. That is probably easiest, but I wanted to explain this. Last one:

Type not found : Player

You need the generate option to generate Haxe classes for the “Export for ActionScript” class names defined in your SWF. You may also need a -clean build if you have already performed a build using the same SWF file before.

It looks like this in your project:

<library path="Assets/layout.swf" preload="true" generate="true" />

Result

Here’s a little screenshot of the project running:

image

You can use the NPM release of OpenFL as well, if you prefer to use JavaScript, TypeScript or ActionScript :slight_smile:

Have a great day :smile:

3 Likes

Thanks Singmajesty :smiley:

1 Like

hello world hello world hello world hello world

I want to use as3hx.Compat.parseInt in my project. My project is openfl project and I am converting as3 to html5. so how can you give me an advice to get rid of the issue like this (Error: Unresolved identifier). latest version of haxe/openfl/lime/as3hx

Math.round is not the same as as3hx.Compat.parseInt . And the question of mine why I am not able to use this clas? Also what is the difference between Std.ParseInt and as3hx.Compat.parseInt ? Because when I use Std.ParseInt errors are gone.

You can try adding this to your project.xml:

<haxelib name="as3hx" />

It looks like Compat.parseInt handles Int, Float and String types: