• Shyamala Prayaga

Tutorial part 4 – Displaying Images

In this part we will learn the following:

  1. Creating a simple Flex application

  2. Displaying images

Creating a simple Flex application

Application is the default container tag. Skeleton of an MXML application file contains

  1. XML document type definition

  2. Opening and closing component tag set

Specifying namespace

  1. use xmlns:mx attribute for the namespace, which defines the collection of legal MXML tags

  2. http://www.adobe.com/2006/mxml is the uniform resource identifier which associates a prefix (in this case mx) with a manifest file as follows

<namespace> <url>http://www.adobe.com/2006/mxml</url&gt; <manifest>mxml-manifest.xml</manifest> </namespace><namespace> <url>http://www.adobe.com/2006/mxml</url&gt; <manifest>mxml-manifest.xml</manifest> </namespace>

  1. Flex-config.mxml is located in installdirectory\Adobe\Flex Builder 3\sdks\3.0.0\frameworks\flex-config.xml

<strong>Setting the layout property</strong>

The layout property defaults to your last selection when building an application or component from the appropriate dialog box

The following are 3 layout property.

  1. absolute: Visual elements must have specific x, y values or constraints for positioning

  2. horizontal: Visual elements presented horizontally

  3. vertical: Visual elements presented vertically

If the layout property is not used in the Application tag, the default layout is vertical

Adding UI Controls

UI Controls are used to display user interface type components like Text, text input, buttons, images, combo boxes etc in an application

All UI tags are add between the application tag set or another container component

Example of the Label control to display a single line of text

<mx:Label text=“Hello Flexers!” />

Specifying components properties

Component properties can be specified in two ways

  1. As an attribute of the XML tag

<mx:Label text=“Hello” />

  1. As nested tags or nodes

<mx:Label> <mx:text> Hello</mx:text> </mx:Label>

Commenting you MXML code

Flex uses XML style comments which is similar to HTML comments

<! – – this is my comment – – >

<strong>Displaying images</strong>

The following type of images can be used in flex.

  1. JPEG (non progressive)

  2. GIF (can be transparent)

  3. PNG (can be transparent)

  4. SWF

  5. SVG (can only be embedded at compile time)

Methods for displaying images

There are two ways to display images in flex.

  1. Load them dynamically at runtime

  2. Embed them in SWF file

We can Specify image source in three ways

  1. Via source property of an Image control ; will load image dynamically at runtime

  2. Use Image load() method to add the images dynamically at runtime

  3. Embed them in the SWF at compile time using the @Embed directive; useful when you need instantaneous loading and offline application

Displaying images Examples

1) Loading dynamically at runtime

  1. Specify the image using the source attribute of the control

  2. Image is loaded at runtime

<mx:Image source=“myimage.jpg” />

  1. Assign an id to the image to reference in ActionScript

<mx:Image source=“myimage.jpg” id=“imageID” />

2) Using the load() method

Dynamically switch out the image using the load() method of the Image class as mentioned below

<mx:Image source=“addis.jpg” id=“imageID” width=“250” height=“250” />

<mx:Button label=“Change pic” click=“imageID.load(‘flower.jpg’)” />

3) Embedding images at compile time

You can embed images at compile time for instantaneous loading To embed, use the @Embed directive when specifying the image source

<mx:Image source=@Embed(‘../images/myImage.jpg’)” />

Pros of embedding image

  1. Image is available immediately, it is part of the SWF

  2. Very useful for creating application that are able to work offline

Cons of embedding images

  1. Adds to applications SWF size

  2. Slows down application initialization process

  3. Must recompile application every time image changes

  4. Cannot use in data binding calls

Part 5: Laying out Flex application with containers


Recent Posts

See All
  • LinkedIn Social Icon
  • Twitter Social Icon

My name is Shyamala pronounced as shaa-ma-la. I am a UX evangelist turned product owner defining experiences and vision for autonomous digital assistants. 

I am a civil engineer by education, and before moving into user experience and product, I worked as an architect with a construction firm for 2 years. My passion for design and building great things for users pushed me into the UX speciality. I am a self-made UX designer with no formal educational background into UX, but my passion helped me enter and succeed in user experience.