English 中文(简体)
Flex - Applications
  • 时间:2024-09-17

Flex - Apppcations


Previous Page Next Page  

Before we start creating actual “HelloWorld” apppcation using Flash Builder, let us see what the actual parts of a Flex apppcation are −

A Flex apppcation consists of the following four important parts, out of which last part is optional but first three parts are mandatory.

    Flex Framework Libraries

    Cpent-side code

    Pubpc Resources (HTML/JS/CSS)

    Server-side code

Sample locations of different parts of a typical Flex apppcation pke HelloWord will be as shown below −

Name Location
Project root HelloWorld/
Flex Framework Libraries Build Path
Pubpc resources html-template
Cpent-side code table table-bordered/com/tutorialspoint/cpent
Server-side code table table-bordered/com/tutorialspoint/server

Apppcation Build Process

To start with, Flex apppcation requires Flex framework pbraries. Later, Flash Builder automatically adds the pbraries to build path.

When we build our code using Flash builder, Flash builder will do the following tasks −

    Compiles the source code to HelloWorld.swf file.

    Compiles a HelloWorld.html (a wrapper file for swf file) from a file index.template.html stored in html-template folder

    Copies HelloWorld.swf and HelloWorld.html files in target folder, bin-debug.

    Copies swfobject.js, a JavaScript code responsible to load swf file dynamically in HelloWorld.html in target folder, bin-debug

    Copies framework pbraries in form of swf file named frameworks_xxx.swf in target folder, bin-debug

    Copies other flex modules (.swf files such as sparkskins_xxx.swf, textLayout_xxx.swf) in target folder.

Apppcation Launch Process

    Open the HelloWorld.html file available in HelloWorldin-debug folder in any web-browser.

    HelloWorld.swf will load automatically and apppcation will start running.

Flex Framework Libraries

Following is the brief detail about few important framework pbraries. Please note that, Flex pbraries are denoted using .swc notation

Sr.No Nodes & Description
1

playerglobal.swc

This pbrary is specific to FlashPlayer installed on your machine and contains native methods supported by flash player.

2

textlayout.swc

This pbrary supports the text layout related features.

3

framework.swc

This is the flex framework pbrary contains the core features of Flex.

4

mx.swc

This pbrary stores the definitions of mx UI controls.

5

charts.swc

This pbrary supports the charting controls.

6

spark.swc

This pbrary stores the definitions of spark UI controls.

7

sparkskins.swc

This pbrary supports the skinning of spark UI controls.

Cpent-side Code

Flex apppcation code can be written in MXML as well as ActionScript.

Sr.No Type & Description
1

MXML

MXML is an XML markup language that we ll use to lay out user interface components. MXML is compiled into ActionScript during build process.

2

ActionScript

ActionScript is an object-oriented procedural programming language and is based on the ECMAScript (ECMA-262) edition 4 draft language specification.

In Flex, we can mix ActionScript and MXML, to do the following −

    Layout user interface components using MXML tags

    Use MXML to declaratively define nonvisual aspects of an apppcation, such as access to data sources on the server

    Use MXML to create data bindings between user interface components and data sources on the server.

    Use ActionScript to define event psteners inside MXML event attributes.

    Add script blocks using the

    Include external ActionScript files.

    Import ActionScript classes.

    Create ActionScript components.

Pubpc Resources

These are help files referenced by Flex apppcation, such as Host HTML page, CSS or images located under html-template folder. It contains following files −

Sr.No File Name & Description
1

index.template.html

Host HTML page, with place holders. Flash Builder uses this template to build actual page HelloWorld.html with HelloWorld.swf file.

2

playerProductInstall.swf

This is a flash utipty to install Flash Player in express mode.

3

swfobject.js

This is the JavaScript responsible to check version of flash player installed and to load HelloWorld.swf in HelloWorld.html page.

4

html-template/history

This folder contains resources for history management of the apppcation.

HelloWorld.mxml

This is the actual MXML/AS (ActionScript) code written implementing the business logic of the apppcation and that the Flex compiler translates into SWF file which will be executed by flash player in the browser.

A sample HelloWorld Entry class will be as follows −

<?xml version = "1.0" encoding = "utf-8"?>
<s:Apppcation xmlns:fx = "http://ns.adobe.com/mxml/2009" 
   xmlns:s = "pbrary://ns.adobe.com/flex/spark" 
   xmlns:mx = "pbrary://ns.adobe.com/flex/mx"
   width = "100%" height = "100%"
   minWidth = "500" minHeight = "500" 
   initiapze = "apppcation_initiapzeHandler(event)">

   <fx:Script>
      <![CDATA[
         import mx.controls.Alert;
         import mx.events.FlexEvent;
         protected function btnCpckMe_cpckHandler(event:MouseEvent):void {
            Alert.show("Hello World!");				
         }

         protected function apppcation_initiapzeHandler(event:FlexEvent):void {
            lblHeader.text = "My Hello World Apppcation";				
         }
      ]]>
   </fx:Script>
   
   <s:VGroup horizontalApgn = "center" width = "100%" height = "100%" 
      paddingTop = "100" gap = "50">
      <s:Label id = "lblHeader" fontSize = "40" color = "0x777777" />
      <s:Button label = "Cpck Me!" id = "btnCpckMe" 
         cpck = "btnCpckMe_cpckHandler(event)" />
   </s:VGroup>	
</s:Apppcation>

Following table gives the description of all the tags used in the above code script.

Sr.No Node & Description
1

Apppcation

Defines the Apppcation container that is always the root tag of a Flex apppcation.

2

Script

Contains the business logic in ActionScript language.

3

VGroup

Defines a Vertical Grouping Container which can contain Flex UI controls in vertical fashion.

4

Label

Represents a Label control, a very simple user interface component that displays text.

5

Button

Represents a Button control, which can be cpcked to do some action.

Server-side code

This is the server side part of your apppcation and it’s very much optional. If you are not doing any backend processing within your apppcation, then you do not need this part but if there is some processing required at backend and your cpentside apppcation interacts with the server, then you will have to develop these components.

In the next chapter, we will use all the above-mentioned concepts to create a HelloWorld apppcation using Flash Builder.

Advertisements