logo
Currently Browsing: Flash Builder

How to Create a Hello World Application in Flash Builder

logo

This tutorial is very similar to my previous post on the same concept in Flex 3, except I am going to spend a little more time highlighting some of the key differences in Flash Builder and its predecessor Flex 3.

Initial Observations

One of the first things you’ll notice visually is the new default styling Flash Builder brings to the table.  The default styling is not only a more fresh approach, but more appealing than Flex 2 and 3.   The buttons are more polished and refined, and the overall styling is much slicker.  Also, no more default blue background!  The screenshot below is the code from my Flash Builder project.  You can download the source files here.

The Code

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
  3.                            xmlns:s="library://ns.adobe.com/flex/spark"
  4.                            xmlns:mx="library://ns.adobe.com/flex/mx"
  5.                            width="436" height="248" creationComplete="mainFunction()">
  6.         <fx:Script>
  7.                 <![CDATA[
  8.                         import mx.controls.Alert;
  9.                        
  10.                         // main function that fires when creation is complete
  11.                         /* adds event listener to the button with the id "hello2"
  12.                          * that listens for a mouseclick event and designates
  13.                          * a function to be called when the mouse is clicked. */
  14.                         private function mainFunction():void
  15.                         {
  16.                                 this.hello2.addEventListener(MouseEvent.CLICK, helloFunction);
  17.                         }
  18.                        
  19.                         //function that is fired on click
  20.                         private function helloFunction():void
  21.                         {
  22.                                 Alert.show(‘Hello World!’, ‘Message 2′);
  23.                         }
  24.                 ]]>
  25.         </fx:Script>
  26.  
  27.         <!–Hello World Example 1 using inline MXML click events –>
  28.         <s:Label y="30" text="Hello World Example 1" color="#000000"
  29.                          fontWeight="bold" horizontalCenter="2"/>
  30.         <s:Button y="50" label="Hello World 1"
  31.                           click="Alert.show(‘Hello World!’, ‘Message’)"
  32.                           id="hello1" color="#000000" horizontalCenter="1"/>
  33.        
  34.         <!– Hello World Example 2 using event handlers in AS3 –>
  35.         <s:Label y="96" text="Hello World Example 2" color="#000000"
  36.                          fontWeight="bold" horizontalCenter="2"/>
  37.         <s:Button y="125" label="Hello World 2"
  38.                           id="hello2" color="#000000" horizontalCenter="1"/>
  39. </s:Application>

You’ll notice that much of the code is very similar to Flex 3, if not the same.  The only difference is that the mx namespace has been replaced with an s or an fx and that there are more XML namespace declarations in the Application tag.  The neat thing with beta 2 of Flash Builder is the fact that you can still use the mx namespace, but Flash Builder kindly suggests to transition to the Spark library by stating:

spark recommendation How to Create a Hello World Application in Flash BuilderI think that by going this route Adobe makes it easier for previous Flex users to migrate and become more comfortable with some of the new changes on older components within the platform.

As always, comments and questions are always welcome. icon smile How to Create a Hello World Application in Flash Builder

Happy coding!

Page 7 of 7« First...34567
logo
Powered by Wordpress. Copyright 2009 Brett Widmann.