Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Flex application


May 25, 2021 Flex


Table of contents


Before we get started with Flash Builder to create an actual HelloWorld application, let's look at the actual part of the Flex application. The Flex application consists of four important sections, the last of which is optional, but the first three are mandatory:

  • Flex Framework Library

  • The client code

  • Public Resources (HTML / JS / CSS)

  • Server-side code

Examples of different parts of HelloWord, a typical Flex application, are as follows:

Name Position
The root of the project HelloWorld/
Flex Framework Library Build Path
Public resources html-template
The client code table table-bordered / com / tutorialspoint / client
Server-side code table table-bordered / com / tutorialspoint / server

The application build process

Flex applications require a Flex framework library. /b10> Flash Builder automatically adds libraries to the build path.

When we build code with Flash Builder, Flash Builder does the following

  • Compile the source code into a HelloWorld .swf file.

  • Compile HelloWorld files (wrapped files for swf files.html) from files stored in the html-template folder .html index.template)

  • Copy the HelloWorld and HelloWorld .swf files in the .html folder, bin-debug.

  • Copy the swfobject .js, a javascript code responsible for dynamically loading the swf file, bin-debug, in the HelloWorld .html in the target folder

  • Copy the framework library frameworks_xxx.swf, bin-debug, as a swf file named "Swf" in the destination folder

  • Copy other flex modules in the destination folder (.swf files, such as sparkskins_xxx.swf, textLayout_xxx.swf).

Flex application

The application startup process

  • Open helloWorld's file in any web browser in the HelloWorld's .html folder.

  • HelloWorld .swf will load automatically and the application will start running.

Flex Framework Library

Here are a few brief details of the important framework libraries.

Use the .swc notation in the flex library

S.N. Nodes and descriptions
1

playerglobal.swc

This library is dedicated to Flash Player installed on your computer and contains the local methods supported by Flash Player.

2

textlayout.swc

This library supports text layout-related features.

3

framework.swc

This is the core feature of the Flex framework library that contains Flex.

4

mx.swc

This library stores the definition of the mx UI control.

5

charts.swc

This library supports chart controls.

6

spark.swc

This library stores the definition of the spark UI control.

7

sparkskins.swc

This library supports skin change for spark UI controls.

The client code

Flex application code can be written in MXML and ActionScript.
S.N. Nodes and descriptions
1

MXML

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

2

ActionScript

ActionScript is an object-oriented, process programming language based on the draft language specification of ECMAScript (ECMA-262) Version 4.

In Flex, we can mix ActionScript and MXML, to do the following:
  • Use MXML tags to lay out user interface components

  • Use MXML to declare non-visual aspects of an application, such as accessing data sources on a server

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

  • Use ActionScript to define event listeners in MXML event properties.

  • Add a script block label with .lt; mx:Script.

  • Includes external ActionScript files.

  • Import the ActionScript class.

  • Create actionScript components.

Public resources

These are secondary files referenced by Flex applications, such as Host HTML pages, CSS, or images located under the html-template folder. It contains the following files

S.N. Nodes and descriptions
1

index.template.html

Host HTML page with placeholders. /b10> Flash Builder uses this template to build the actual .swf HelloWorld using HelloWorld's .html.

2

playerProductInstall.swf

This is a Flash utility for installing Flash Player in quick mode.

3

swfobject.js

This is the version of Flash Player that Javascript is responsible for checking for installation and loading helloworld .html on the HelloWorld .swf.

4

html-template / history

This folder contains resources for history management for your application.

HelloWorld.mxml

This is the actual Written MXML/ACTIONScript code that implements the business logic of the application, and the Flex compiler converts to a SWF file, which will be executed by the Flash player in the browser. The example HelloWorld Entry class would look like this:

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

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

         protected function application_initializeHandler(event:FlexEvent):void
         {
            lblHeader.text = "My Hello World Application";				
         }
      ]]>
   </fx:Script>
   <s:VGroup horizontalAlign="center" width="100%" height="100%" 
   paddingTop="100" gap="50">
      <s:Label id="lblHeader" fontSize="40" color="0x777777"/>
      <s:Button label="Click Me!" id="btnClickMe" 
      click="btnClickMe_clickHandler(event)" />
   </s:VGroup>	
</s:Application>

The following table gives a description of all the labels used in the above code script.

S.N. Nodes and descriptions
1

Application

Define the application container that is always the root tag for the Flex application.

2

Script

Contains business logic in the ActionScript language.

3

VGroup

Define vertically grouped containers that can contain Flex UI controls vertically.

4

Label

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

5

Button

Represents the Button control, which you can click to do something about.

Server-side code

This is the server-side part of the application and is very optional. /b10>If you do not perform any back-end processing in your application, you do not need this section, but if the back-end requires some processing and your client application interacts with the server, you will have to develop these components.

The next chapter uses all of these concepts to create the Hello World application using Flash Builder.