Creating your first application

Difficulty: Beginner
Creating your first application

SPAS 3.0 applications are written in ActionScript 3.0. It's important to understand that ActionScript is the base of the RIAs developed on the Flash Platform. Even if you use Adobe's Flex and MXML, you won't be able to create RIAs without ActionScript knowledge.

What SPAS 3.0 tries to do is to simplify the ActionScript 3.0 coding process to make it understandable by normal people. (People who don't speak with strange words like ‘design pattern', ‘iteration' or ‘procedural programming'…)

SPAS 3.0 Application class

SPAS 3.0 applications are wrapped into the Application class, which is a main container class that extends the Document class:

package {
    
   import org.flashapi.swing.*;
   
   public class HelloWorld extends Application {
   
      public function HelloWorld() { super(); }
   }
}

If you are not familiar with the Document class, read: Introduction to the Document Class in ActionScript 3.0.
If you need more information about external files programming in ActionScript 3.0, please read: Make your own reusable classes using Flash and AS3.

SPAS 3.0 "Hello World"

The first line of the HelloWorld constructor function is the Application style declaration:

gradientBackground = bodyVisibility = true;

The gradientBackground and bodyVisibility properties default values are false. It allows Flash graphic designers to deal with the Flash IDE main timeline's background.

The next line defines the container we use to contain other “uiobjects”. The PanelContainer object is a special frame container that includes a title bar, header and footer panels and a content area for its children. The first parameter of the constructor function defines the label displayed by the title of the panel container: My Application.

The Label object represents a Label control, a very simple user interface object that displays text. The first parameter of the constructor function defines the text displayed by the label object: Hello World.

The boldFace and fontSize properties of the Label object change the style of the font used. These properties can be replaced by the font-weight and font-size CSS properties. For more information, see “Applying styles to the application container” in the SPAS 3.0 Cookbook, Chapter 2.

To add these objects to the display list, we use the addElement() method. The SPAS 3.0 display list is thought of as an HTML elements list. So, each object is called an element object, and to add element objects to the element list we simply use an addElement() method.

Notice that to refer to the document object, we can use the this keyword, but it's not an obligation.

package {
    
   import org.flashapi.swing.*;
   
   public class HelloWorld extends Application {
   
      public function HelloWorld() {
         super();
         gradientBackground = bodyVisibility = true;
         
         var pc:PanelContainer = new PanelContainer("My Application");
         var lab:Label = new Label("Hello World");
         lab.boldFace = true;
         lab.fontSize = 24;
         
         pc.addElement(lab);
         this.addElement(pc);
      }
   }
}

Result:

Get Adobe Flash player

Where to go from here

Read SPAS 3.0 Cookbook, Chapter 2: Applying styles to the application container.

Share this article:

Comments:

There are no comments yet for this article.

Leave a reply

Your email is required but will not be displayed.

To prevent abusive emails, please enter the numbers you see in the image below:

Security code