当我在整个应用程序中进入不同的状态时,我使用状态来显示不同类型的媒体。我正在处理图像状态,我可以从我的 XML 中获取数据以显示在我布局的数据网格中,并在单击它时显示我正在查看的图像的名称,但是图像不显示。这是我现在的代码:
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<fx:XML id="images" source="img_data/images.xml" />
<s:XMLListCollection id="imageCollection" source="{images.IMAGE}" />
</fx:Declarations>
<s:HGroup>
<s:DataGrid id="imageGrid" dataProvider="{imageCollection}" click="onClick()" />
<s:VGroup height="55">
<s:Label text="Now viewing: {imageGrid.selectedItem.@name}" />
<s:Label id="txtPosition" width="91"/>
</s:VGroup>
</s:HGroup>
<fx:Script>
<![CDATA[
import mx.controls.Image;
public var newImage:Image;
public var myXML:XML;
[Bindable]public var myURLLoader:URLLoader = new URLLoader;
public function onClick():void{
newImage = new Image();
newImage.load(new URLRequest(imageGrid.selectedItem.file.toString()));
newImage.addEventListener(Event.COMPLETE, processXML);
newImage.source = images.IMAGE.@src;
}
public function processXML(e:Event):void{
myXML = new XML(e.target.data);
//newImage = new Image();
newImage.height = 200;
newImage.width = 400;
imgGroup.addElement(newImage);
}
]]>
</fx:Script>
我从中提取的 XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<GALLERY COLUMNS="5" XPOSITION="30" YPOSITION="30" WIDTH="100" HEIGHT="100">
<IMAGE name="Cabin in the Woods" >
<file>img_data/cabin.jpg </file>
</IMAGE>
<IMAGE name="Batman" src="img_data/batman.jpg" >
<file>img_data/batman.jpg</file>
</IMAGE>
<IMAGE name="Christmas Vacation">
<file>img_data/christmasVacation.jpg</file>
</IMAGE>
<IMAGE name="Inception">
<file>img_data/inception.jpg</file>
</IMAGE>
</GALLERY>