Flash Kid Logo  
Home - Tutorials - Applications - Games - Books - Directory - Community - Site Map - Contact Us  
 
 


 
 
 
Author: Salman Awan
Difficulty Level: Beginner
Flash Version: Flex Builder 3 and higher
Sources to Download: None


Introduction:

In this hello world flex tutorial we will create our first application using Flex Builder and along the way we will look at different views while working with Flex. This tutorial is a quick start guide for those developers who want to get a peek into Flex framework and want to feel comfortable with the tool.


New Project Wizard
Fig. 2 - New project wizard


Enter Project Name ‘Hello World’ and select a custom Project Location for your project files to be placed. Since we are creating a Web application that runs in Flash Player so select Application type accordingly.
We are not going to use any server side language to interact with our Hello World application so we will select None in Server Technology section. Press Next.

On Next wizard step we can specify a custom output folder where compiled swf file will be placed. Swf file is output of any Flash or Flex based project. SWF files are executed within Flash Player, which can be installed freely from Adobe website.

This Output folder will be made in root directory of Project, which we selected in first step. Let’s leave it to default suggested name and press Next.

New Project Debug Options
Fig. 3 - New project debug options


Pressing next will bring focus to wizard step 3 where define and rename source folders and add new libraries to the project. However for our simple Hello World application we won’t be needing additional libraries than what is already provided in Flex framework.

Source Folders and Libraries
Fig. 4 - Source folders and libaries


So let’s press Finish Now. This will initiate a Project creation and loading sequence. Once project “Hello World” is created we can see the hierarchy of project files and folders in “Flex Navigator” panel (Window > Flex Navigator).

Flex Project Structure and Flex Navigator Panel
Fig. 5 - Flex project structure and flex navigator panel


Main.mxml File
By default when a new project is created, its default .mxml file is loaded in editor you can obviously open it by double clicking file name in Flex Navigator.

Default main.mxml file in source mode
Fig. 6 - Flex project structure and flex navigator panel


Flex applications are written using MXML and/or ActionScript. MXML is an XML-based markup language that is primarily used to layout application display elements and associate behaviors with them. ActionScript is an ECMAScript-compliant object-oriented programming language that is primarily used for application logic. In Flex MXML and ActionScript code are compiled into binary SWF files.


Designing Our RIA
In Editor, two modes in which you can view an mxml file are Source and Design view. In above diagram Source view is enabled where you can see opening and closing Application tags and nothing in between. This indicates Application has no UI components defined that should be rendered by flash player.

Let’s now switch to Design view by pressing Design button on top of the code editor. Selecting Design view will show how our main.mxml file will be rendered in flash player, which in our case is blank since we have added no UI control so far. As soon as we select Design view, a set of panels open automatically to facilitated and speedup designing of application layouts. Panel we are interested right now is ‘Components’ panel.

Flex Components and controls panel
Fig. 7 - Flex components and controls panel


Components panel displays all the, by default available UI Controls. We can also create custom UI Controls.

For now, let’s select and drag-drop Label control to design area. By default Label control has text ‘Lable’ inside it, which we need to change now.

Drag and drop label control
Fig. 8 - Drag and drop label control


If not already selected, click on Label control that we just dragged to design area. Properties panel will update to show properties relevant to Label control. If Properties panel is not opened already, you can open it through Windows > Flex Properties.

Flex Component Properties Panel
Fig. 9 - Flex component properties panel


Under Common section, change Text property of this Label control to ‘Hello World’. As soon as you tab out of Text property, Label’s new text is set in design area.


Running RIA
Let’s now run our simple Rich Internet Application. Save file for any changes and then select Run > Run Main from menu.

This will build the project and generate binary SWF file in bin-debug folder. IDE will go ahead and launch default browser with our Hello World RIA loaded in it.

Flex RIA in browser
Fig. 10 - Flex ria in browser



Exercises:

  1. What is Flex?

  2. Why we needed MXML when we already had Action Script 3.0 for Flash?

  3. Change Label to say something other than ‘Hello World’.

  4. Add a Button, CheckBox, ComboBox and Date Chooser controls on design area?

  5. What are the differences in properties panel, when you select above controls one by one?

 
 

 
 
Related Links
Discussion Forums for Tutorials
 
 



 
 
 
 
© 2010 flashkid.org! All Rights Reserved.
 
   
 
a project of: xonsolutions.com, other projects: tutorialkid.org