User Guide
Example: Creating a basic application 29
To create an ActionScript application using Flex Builder:
1. Open the HelloWorld.mxml file, and type the following code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
layout="vertical"
creationComplete = "initApp()" >
<mx:Script>
<![CDATA[
private var myGreeter:Greeter = new Greeter();
public function initApp():void
{
// says hello at the start, and asks for the user's name
mainTxt.text = myGreeter.sayHello();
}
]]>
</mx:Script>
<mx:TextArea id = "mainTxt" width="400" />
</mx:Application>
This Flex project includes three MXML tags:
■ An <mx:Application> tag, which defines the Application container
■ An <mx:Script> tag that includes some ActionScript code
■ An <mx:TextArea> tag, which defines a field to display text messages to the user
The code in the
<mx:Script> tag defines a initApp() method that is called when the
application loads. The
initApp() method sets the text value of the mainTxt Text A re a to
the “Hello World!” string returned by the
sayHello() method of the custom class
Greeter, which you just wrote.
2. Select File > Save to save the application.
Continue with “Publishing and testing your ActionScript application” on page 30.