9.19.2008

All-ActionScript application

It may be desirable to implement a Flex application using 100% ActionScript instead of splitting the code between ActionScript and MXML. Here's a simple way to bootstrap such an application:

App.mxml
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" applicationComplete="LayoutTestImpl.main()"/>


AppImpl.as
package {
import mx.controls.*;
import mx.core.*;

public class AppImpl {
public static function main():void {
new AppImpl().startApp();
}

public function startApp():void {
var helloLabel:Label = new Label();
helloLabel.text = "Hello World";
var app:Application = Application.application as Application;
app.layout = "vertical";
app.addChild(helloLabel);
}
}
}

No comments: