Embedding Resources - Adobe FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 Manual

Migrating applications to flex 2
Table of Contents

Advertisement

Embedding resources

In Flex 1.5, embedded resources were bound to Strings that were used to reference the
individual images by name. Although the preferred method of embedding resources in Flex 2
uses Class variables, you can still use String variables for some level of backward compatibility.
However, the various objects and tags that use your embedded assets expect them to be tied to
Class variables, so you need to use the
variables. You also still need to use the
bindable.
For instance, the following application uses string variables and casting to display an
embedded image:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
[Embed(source="logo.gif")]
[Bindable]
public var imgStr:String;
]]>
</mx:Script>
<mx:Image source="{getDefinitionByName(imgStr)}"/>
</mx:Application>
Although this method works, Adobe recommends that you use Class variables instead. The
equivalent application, using a Class variable, is simpler:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
[Embed(source="logo.gif")]
[Bindable]
public var imgCls:Class;
]]>
</mx:Script>
<mx:Image source="{imgCls}"/>
</mx:Application>
Alternatively, when you use MXML, this becomes a one line application:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Image source="@Embed(source='logo.gif')" />
</mx:Application>
For more information, see Chapter 30, "Embedding Assets," in the Flex 2 Developer's Guide.
172
Additional Migration Issues
getDefinitionByName()
metadata tag to declare the string variable
[Bindable]
method to cast your string

Advertisement

Table of Contents
loading

This manual is also suitable for:

Flex 2

Table of Contents