Application Development with MTASC / First Steps


We begin with a simple example. A small app with a button. If you click on it an alert window will show up.
Steps:

1. Preparations

- make a new directory (e.g. hello_world)
- open the notepad and save the (yet empty file) file as helloworld.as in that directory

2. Getting the components in the library

- start the Flash IDE
- make a new flash (.fla) file
- drag a button and a alertbox from the “UI Components” on the stage, or make a double-click on the components
- when the components are in the library you can even delete it from the stage
- mark the only frame in the timeline, so that you see the action panel and add a class reference to the application logic

r = helloworld();

- compile the .fla into a flash movie (.swf) and close the IDE

3. Writing the App

Open the helloworld.as file into your texteditor and add the following code:

  import mx.controls.Button;
          
  class helloworld {
          
      function helloworld(){
          var myBut:Button = _root.createClassObject(Button,"button2",5,{label:"Push me!"});
          myBut._x = 300;
          myBut._y = 100
          myBut.addEventListener("click", buttonclicked);
      }
          
      private function buttonclicked(event:Object):Void {
          mx.controls.Alert.show("hello world","title");
      }
  }

4. Compile the App

- open your text editor again for writing the compile.bat
- add the line:

  mtasc -cp "c:\program files\macromedia\flash mx 2004\en\First Run\Classes" -mx -swf helloworld.swf helloworld.as

- now open a command prompt on your working directory and type “build.bat” - thats it!

Files:
helloworldmtasc.zip