Matt Kenefick
Contact Me Experiments Blog Portfolio

Posts Tagged ‘actionscript’

Actionscript to Android

Sunday, February 8th, 2009

Over the next few weeks.. I’m going to write out some very simple to progressively more advanced Actionscript to Android comparisons. Since it’s all Java based, it should be fairly simple to see the differences and merge your way from AS3 to Android. Instead of explaining a bunch of stuff, I’ll just jump directly into it.

Actionscript 3.0

package com.android.hello {
 
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TextView;
 
  public class HelloAndroid extends Activity{
    /** Called when activity is first created */
    public override onCreate( savedInstanceState:Bundle ):void {
      super.onCreate( savedInstanceState );
 
      var tv:TextView = new TextView( this );
      tv.setText("Hello, Android");
      setContentView( tv );
    }
  }
}
Android (Java)

package com.android.hello;
 
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TextView;
 
  public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate( Bundle savedInstanceState ) {
       super.onCreate( savedInstanceState );
 
       TextView tv = new TextView(this);
       tv.setText("Hello, Android");
       setContentView(tv);
    }
}

This is a very simple example that helps show the differences in syntax.

Actionscript 3 Android (Java)
- Enclose package in brackets
- Override after “public”
- Return type (void) AFTER parameters
- Variable type “var varname:Type”
- Do not enclose package
- Override set before method
- Return type (void) BEFORE method name
- Variable type “Type varname”