Working with the Application entry point

Difficulty: Beginner
Working with the Application entry point

Problem

You want to ensure that your RIAs will always work, even if you use complex architectures based on several nested applications.

Solution

Use the "entry point" internal mechanism provided by the org.flashapi.swing.Application class.

Discussion

In SPAS 3.0 there are several ways of having a main entry point.
The usual practice involves using an entry point function, located in the constructor of the main Application class:

package {
 
	import org.flashapi.swing.Application;
 
	public class MyApplication extends Application {
 
		/**
		* Constructor function.
		*/
		public function MyApplication():void {
			entryPointfunc();
		}
 
		/**
		* Entry point function.
		*/
		private function entryPointfunc():void {
			// Your application starts from here...
		}
	}
}

Most of SPAS 3.0 developers use this technique, but the fact is that it is not the correct way define an application entry point with SPAS 3.0.

The code above will work as long as you wont try to use complex processes, such as adding an Initializator class instance.
In this case, your SPAS 3.0 application will throw an Initialization error.

The best way to define entry point with SPAS 3.0, is to pass the entry point function to the super statement in the constructor function:

package {
 
	import org.flashapi.swing.Application;
 
	public class MyApplication extends Application {
 
		/**
		* Constructor function.
		*/
		public function MyApplication() {
			// Defines the entry point function:
			super(entryPointfunc);
		}
 
		/**
		* Entry point function.
		*/
		private function entryPointfunc():void {
			// Your application starts from here...
		}
	}
}

This structure has a lot of advantages:

  • it works in any case,
  • the code is clean and more readable,
  • nothing else is defined in the constructor of the application.

That is why we invite all SPAS developers to use the initFunction parameter instead of all other techniques, to declare entry points.

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