MACROMEDIA FLEX 2-MIGRATING APPLICATIONS TO FLEX 2 Manual do Utilizador Página 172

  • Descarregar
  • Adicionar aos meus manuais
  • Imprimir
  • Página
    / 184
  • Índice
  • MARCADORES
  • Avaliado. / 5. Com base em avaliações de clientes
Vista de página 171
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
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:
<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.
Vista de página 171
1 2 ... 167 168 169 170 171 172 173 174 175 176 177 ... 183 184

Comentários a estes Manuais

Sem comentários