クラス名: -HeaderIconClass
//////////
package
{
import spark.components.Image;
internal dynamic class HeaderIconClass extends Image
{
public function HeaderIconClass()
{
super();
}
}
}
コンポーネントまたはアプリケーション レベル内: -
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
creationComplete="application1_creationCompleteHandler(event)">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
[Bindable]
public var headerIcon:HeaderIconClass = new HeaderIconClass();
//For your testing
protected function button1_clickHandler(event:MouseEvent):void
{
// TODO Auto-generated method stub
imageID.source = headerIcon.source
}
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
headerIcon.source = "@Embed('/assets/images/Header.png')";
}
]]>
</fx:Script>
<mx:VBox x="100" y="100">
<s:Button label="Show Image" click="button1_clickHandler(event)"/>
<s:Image id="imageID" width="50" height="50"/>
</mx:VBox>
</s:Application>
これを使用したい場合は、これを変数に保存できます: -
private var imagePath:String = xmlObject.child('icon').toString();
以下の機能を次のように変更します。
protected function application1_creationCompleteHandler(event:FlexEvent):void
{
// TODO Auto-generated method stub
headerIcon.source = "@Embed('"+imagePath+"')";
}
これが役立つことを願って.....