0

在我的代码中,我定义了以下内容: <s:Image id="test" x="50" y="50" width="30" height="30" click="onClick_clickHandler(event)" smooth="true" smoothingQuality="high" source="@Embed('icons/myImage_60_off.png')"/> 我想要的是能够在用户每次单击图像时更改图像的来源——类似于收藏夹在浏览器上的工作方式。我不知道如何从我的代码中更改图像的来源。

谢谢

4

2 回答 2

0


I finally did it!

public var image_loader:Loader; // define a new loader

image_loader = new Loader(); // create the new loader at the desired location (in my case in the initialization method of the page

image_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded); //add a listener and a function to assign to the listener
depending on where the command has to be executed

image_loader.load(new URLRequest('location of the image')); //this will load the image dynamically

function imageLoaded(event:Event):void {image_Id.source = image_loader;} //where image_Id is the id of the s:Image tag to be modified

also, I had to remove the source from the s:Image tag previously posted
The rest is just logic of the way the application needs to implement the functionality, so it's pretty much left to the developer's desires

于 2012-02-13T21:50:58.913 回答
0

我的解决方案有一个隐藏的数据网格,因为它从一个可见的开始。

图像看起来像这样:

 <mx:Image top="153" left="10" right="10" bottom="5" source="{dgpick.selectedItem.ImageFile}" />

每次有人点击图片时,我都会增加数据网格的选定索引,标签会显示相应的数据,因为它们也绑定到它的数据。

该图像还可以包含指向 XML 文件的链接,您可以像这样加载该文件:

<s:HTTPService id="Config"
                   url="config.xml"
                   result="resultHandler(event)"/>

private function resultHandler(event:ResultEvent):void 
{
    ImagesURL = event.result.images.ImagesURL[iCounter];                

}

每次有人点击图片,你可以增加计数器,等等。

希望这能给你一些想法。

有 20 种方法可以做到这一点。

如果您需要更多代码,请添加您需要的注释。

于 2012-02-13T10:59:02.870 回答