类名:-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+"')";
}
希望这可能会有所帮助......