AS3 to TypeScript Conversion Tool

Recommended Posts

I write a lot of HTML5 games and my preferred language of choice is TypeScript. I love the compile-time errors, code-insight and debugging tools it provides. A large part of my work is porting over ActionScript3 code from Flash games. I found that I was going through the same motions over and over again; simple things like changing “Boolean” to “bool”, or rename the class function to “constructor”.



It got to the point where I figured it would save time to write a script to help with the process. So I did, and I’ve released it for anyone else who may benefit from it. The script runs on a local web server and can convert either a single file or a whole directory full of them. It will intelligently deep-scan a folder structure, converting just the ActionScript files that it finds along the way. I’ve successfully run it across the whole of the flixel codebase with no issues, so I’m hopeful it’ll work for you.

Share this post

Link to post
Share on other sites

Wow i'll take it and try right on the moment.


I'll be more than happy if it could convert the ASH as3 game entity framework to typescript. :)


10x for the efort even before testing, i'll share the result soon i hope :)

Share this post

Link to post
Share on other sites

I'm finding and adding new tests as I go (just did another update right then) - but please understand you will still need to do LOADS of work to the code, even after running it through this script. But at least most of the menial stuff will be out of the way for you :)

Share this post

Link to post
Share on other sites

Of course I don't expect to be compile ready ;).


Here what i'm doing in the moment:

1. Conversion when;t perfect

2. I've made new VisualStudio Project and imported the ts files

3. I go trought every class and fix things in this order:


  1. Add import Class = module("path/to/Class");
  2. I tend to make all private variables "_varname"
  3. Then goes trought the methods and add "this."

And using Web Essential with compile on save, it's quite easy to spot errors... so i'm going to work to see how much time really is :)




I think a "int" to "number" will be good convertion too, or no ?



What you tend to do with variable types defined like:


private somevar: Class;

private somevar2: Function;


Shouldn;t the convertor "remove :Function" and Class ?

Share this post

Link to post
Share on other sites

Yep, i check the list in github, but the misunderstand came cause in the convertet ts there was  : Function and : int  ...


There was a space, after the colon ": " in the .as files and that left in the .ts


So i added lines like this in your php script:


$output = str_replace(': Function', '', $output);

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.