Macromedia flex 2-migrating applications to flex 2 Manual De Usuario
172
Additional Migration Issues
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
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
getDefinitionByName()
method to cast your string
variables. You also still need to use the
[Bindable]
metadata tag to declare the string variable
bindable.
For instance, the following application uses string variables and casting to display an
embedded image:
embedded image:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
[Embed(source="logo.gif")]
[Bindable]
public var imgStr:String;
[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:
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;
[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.