Flash
  Home arrow Flash arrow Page 4 - Introduction to Flex
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
FLASH

Introduction to Flex
By: Adi Reddy Mora
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 24
    2005-03-07

    Table of Contents:
  • Introduction to Flex
  • Flex Languages: MXML and ActionScript 2.0
  • About ActionScript 2.0 in MXML applications
  • Writing a simple application
  • More Flex features

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Introduction to Flex - Writing a simple application


    (Page 4 of 5 )

    Because MXML files are ordinary XML files, you have a wide choice of development environments. You can write MXML code in a simple text editor, a dedicated XML editor, or an integrated development environment (IDE) that supports text editing.

    Macromedia has its own IDE for developing flex applications, Flex Builder. The Flex Builder IDE lets you write, edit, debug, and preview MXML and ActionScript files.

    Note: MXML filenames must end in a lowercase .mxml file extension.

    The following example shows a simple "Hello World" application that contains just an <mx:Application> tag and one child tag, the <mx:Label> tag. The <mx:Application> tag is always the root tag of a Flex application. The <mx:Label> tag represents a Label control, a very simple user interface component that displays text.

    <?xml version="1.0" encoding="utf-8"?>
    
    <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" pageTitle="Hello
    World Sample"  marginTop="125"
    marginBottom="5" marginLeft="5" marginRight="5" >
    
        <mx:Label text="Hello World!"/>
    
        <mx:Label text="Hello World!" color="#003366" fontSize="40"/>
    
    </mx:Application>
    

    The above sample MXML file tells the application to write two labels with the text "Hello World" in them. The second Label modifies the size of the text and its color. The first line of the above example specifies an optional declaration of the XML version. It is good practice to include encoding information that specifies how the MXML file is encoded. Many editors let you select from a range of file encoding options. On North American operating systems, ISO-8859-1 is the dominant encoding format, and most programs use that format by default. You can use the UTF-8 encoding format to ensure maximum platform compatibility. UTF-8 provides a unique number for every character in a file, and it is platform-, program-, and language-independent. If you specify an encoding format, it must match the file encoding you use. The above example uses UTF-8 encoding format.

    To deploy the application, you copy the MXML file to a Web application directory. The first time a user requests the MXML file URL in a Web browser, the server compiles the MXML code into a SWF file. The server then sends the SWF file to the Web browser where it is rendered in Flash Player. Unless the MXML file changes, the SWF file is not recompiled on subsequent requests.

    When the Flex compiler automatically generates the HTML file that contains this application, it uses the height and width properties of the <mx:Application> tag to determine height and width properties of the <object> and <embed> tags. The <object> and <embed> tags determine the size of the Flash drawing surface.

    The following figure shows the "Hello World" application shown above rendered in a Web browser window:

    In addition to being the root tag of a Flex application, the <mx:Application> tag represents an Application container. A container is a user-interface component that contains other components and has built-in layout rules for positioning its child components. By default, an Application container lays out its children vertically from top to bottom. You can nest other types of containers inside an Application container to position user-interface components according to other rules.

    The properties of an MXML tag, such as the text, color, and fontSize are the properties of <mx:Label> tag, which let you declaratively configure the initial state of the component. You can use ActionScript code in an <mx:Script> tag to change the state of a component at runtime.

    Now let's see another example with MXML and ActionScript combined together in a single file using <mx:Script> tag.

    <?xml version="1.0" encoding="utf-8"?>
    
    <mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" pageTitle=
    "Fahrenheit to Celsius converter"  marginTop="125"
    marginBottom="5" marginLeft="5" marginRight="5" >
    
       <mx:Script>
                   function convert():Void {
    
                                celsius.text=frmt.format((fahrenheit.text-32)/1.8);
                   }
    
       </mx:Script>
       <mx:NumberFormatter id="frmt" precision="2"/>
       <mx:Label text="Temperature in Fahrenheit:" fontSize="24" color="#003366" />
       <mx:TextInput id="fahrenheit" width="200" fontSize="24" />
       <mx:Button label="Convert" click="convert()" fontSize="24" />
       <mx:Label text="Temperature in Celsius:" fontSize="24" />
       <mx:Label id="celsius" width="250" fontSize="24" color="#003366" />
    </mx:Application> 

    The above example converts Fahrenheit to Celsius with the Fahrenheit value entering in an input text box and by clicking the convert button. The convert button has a click event handler which call the ActionScript function convert() which was written in between <mx:Script> and  </mx:Script> tags.

    The following figure shows the converter application shown above rendered in a Web browser window:

    In a similar way you can combine ActionScript and MXML to create some powerful Enterprise Rich Internet Applications.

    More Flash Articles
    More By Adi Reddy Mora


       · I am Adi Reddy Mora, the author of this article from India. This is my 3rd article...
       · I enjoyed reading this intro to Flex. Any chance of a follow-up or...
       · Thank you for your interest in my article. I will definitely come up with more...
       · Hey do u know how to export a table present in flex to excel ??
       · Your article makes someone think they can create a text file, change it to mxml...
     

    FLASH ARTICLES

    - Organizing Frames and Layers
    - Using XML and ActionScript with Flex Applica...
    - Interfaces and Events with ActionScript and ...
    - Manipulating Data with ActionScript in Flex ...
    - ActionScript Syntax for Flex Applications
    - ActionScript in Flex Applications
    - A Closer Look at Apollo`s File System API
    - Using the File System API
    - ActionScript 101
    - Flash Buttons
    - Advanced Flash Animation
    - Creating Your First Animated Movie with Flas...
    - Flash: Building Blocks
    - Building Preloaders
    - Fun Things to Do with Movie Clips in Flash MX







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway