Avg. Rating 3.8

Problem

Create a dynamic instance of images you can change at runtime.

Solution

With Actionscript 3 it's possible to make an embedded image reusable using the Embed Metadata and creating a subclass of mx.core.MovieClipAsset

Detailed explanation

Only 3 Flex containers allow the use of layout="absolute" : Application, Panel and Canvas. Using the absolute positioning, you can create a layering effect on your application.

To overlap an image to a Panel, it's enough to create an instances of the  embedded image class.
With Actionscript 3 it's possibile to create reusable embedded images with the following code :

[Embed(source="assets/logo.swf")]
[Bindable]
private var myIcon:Class;

Note that the data type I use is the Class. Then I used the variable as the source of the Image :

Flex automatically creates an instance of the class. It's possible to use the superclass for a SWF file creating a subclass of mx.core.MovieClipAsset:

import mx.core.MovieClipAsset;
[Embed(source="assets/logo.swf")]
   public var myIcon:Class;
   [Bindable]
   public var myIcon_1:MovieClipAsset = new myIcon();

For overlapping the image on a Panel we just use the x and y property of the Image tag :



</mx:DataGrid>

</mx:Panel>

Flex_image_overlap

The cool thing is that using the bindable variable for images you can update the image at runtime and make it dynamic !

dynamic_image.zip
[files include the main MXML application and the graphical assets.]
Report abuse

Related recipes