Flash SDK for Java/Android

From Forskningsavdelningen Wiki
Revision as of 08:06, 22 July 2011 by Senseitg (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

[edit] Introduction

With the recent release of Adobe AIR for Android it just became a lot easier to get Flash applications and games running on the platform. While this works for graphically simple applications we soon discovered that high performance applications with complex graphics run very slowly.

Our idea is to rewrite the flash AS3 object model in Java so that we can, instead of using Flash, easily port the entire application over to native Android code and use OpenGL to render the scene using the GPU. This should give us all the performance we need.

[edit] Participants

[edit] Source Code

Patience... GitHub

[edit] Log

We can render a hierarchy of MovieClips in 2D with some basic color filters.

We can now convert an entire AS3 application model (structural and declarative statements) to Java.
Code segments (such as "a = b + c") are not yet parsed so the results will not compile unless they happen to be syntactically compatible.

Code is now parsed and the resulting Java files should compile with little or no modifications.
Exceptions include string comparisons, ECMAScript and non-boolean expressions used as boolean, for example if( obj ), if( num ) or bool = num && obj. AS3 implies != 0 for numbers and != null for objects, Java does not.

All named variables, functions etc. are now resolved to their base types by going through the intrinsic and project classfiles.

AS3
if( obj ) {
for( n = 10; n; n-- ) {
bool = num1 || num2
Java
if( obj != null ) {
for( n = 10; n != 0; n-- ) {
bool = ( num1 != 0 ) || ( num2 != 0 )

ECMAScript operations are now converted, but inline XML is not. It is necessary to replace inline xml with "XML( '<xmldata/>' )" instead of just "<xmldata/>".

AS3
node.@param = 'data';
call( node.@param );
delete node.children()[ 0 ];
Java
node.setParam( "param", "data" );
call( node.getParam( "param" ) );
node.children()[ 0 ].delete();

Arrays & Vectors rely on a separate xml file containing porting information. Getters and setters are suffixed with Get and Set respectively.

AS3
var stuff:Array = [ 0, 1, 2 ];
takesArray( [ "a", "b", "c" ] );
aVector[ ix ] *= 0.95;
function property set var( data:int ) {
var++;
Java
byte[] stuff = { 0, 1, 2 };
takesArray( new String[]{ "a", "b", "c" } );
aVector.access( ix, aVector.access( ix ) * 0.95 );
void varSet( int data ) {
varSet( varGet() + 1 );
Function pointers for events are now ported. Porting is very limited and requires all function pointers to be implemented as events and refer directly to a local function.
AS3
addEventListener( MouseEvent.MOUSE_MOVE, handler );
Java
addEventListener( MouseEvent.MOUSE_MOVE, handler_wrapper );
...
private EventListener handler_wrapper = new EventListener() {
  @Override
  public void onEvent( Event e ) {
    handler( ( MouseEvent )e );
  }
};
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox