Subclassing with Flex

If you are familiar with subclassing concept by using ActionScript (2.0, 3.0) with Flash, you may wanna do the same with Flex.  With Flex application, ActionScript class code exists within separate documents, apart from the MXML application and component documents. ActionScript class files are text files that use the file extension .as

This short example below illustrates how to apply subclassing in Flex:

First of all, you should create an actionscript file first. Each as file should be contains on class only, then extended by one MXML file.

package com.main {   
  import mx.core.Application;
  import mx.events.FlexEvent;
  import mx.controls.Button;

   public class MainApplication extends Application {
      public var btnAlert:Button;
         public function MainApplication() {
               this.addEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler);
         }            

         public function creationCompleteHandler(e:FlexEvent):void {
         }
   }
}

<main:MainApplication
	xmlns:mx="http://www.adobe.com/2006/mxml"
	xmlns:main="com.main.*"
	xmlns:view="view.*">
	<mx:Button id=”btnAlert” />
</main:MainApplication>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s