Extending the Application class in Actionscript
When creating a custom component, you can either do it mxml or Actionscript. If you want to create a component that contains a number of child components in a specific layout you?ll probably go for mxml, for creating non-visual components or components with modified behavior your best pick would be Actionscript. By adding mx:script tags in your application mxml you?re basically extending the Application class. So if you?re not planning to do much lay-out, want to alter the Applications behavior dramatically or just don?t feel comfortable writing mxml wouldn?t it make sense to just create your custom Actionscript Application component. However the Application is a top level component so you can?t just drop it on the stage or add it as a child to a Display Object Container. The most logical way would be to extend the Application in Actionscript and set it as your default application, but unfortunately Flex does some wacky stuff under the hood (who knows what) when compiling so this doesn?t work. The trick is the create an mxml file as your default application with custom Application component tags and the correct namespace as an attribute. The mxml file will serve as the application entry point and you can go ahead extending the Application class in Actionscript. XML: 1.
2.
3.
Actionscript:
1.
package {
2.
import mx.core.Application;
3.
4.
public class MainApp extends Application {
5.
public function MainApp(){
6.
super();
7.
}
8.
}
9.
}

0 Comments:
Post a Comment
<< Home