在flex中加载图像时添加加载器图像
问题描述:
我需要创建一个图库来加载图像并显示它们。这部分是好的:在flex中加载图像时添加加载器图像
/**
* @variable image_name to store the name of the selected item
*/
private function showimage(evt:Event):void
{
// to store the name of the selected image
var image_name : String = evt.currentTarget.selectedItem.img_name;
// checks if any item is clicked
try
{
if(image_name == "")
{
throw new Error("No image selected from the list");
}
// supplying the image source for the Image imgmain
// also supplying the height and width for the image source
imgMain.source = siteurl + image_name.toString();
}
catch(err:Error)
{
Alert.show(err.message);
}
}
其中imgMain是图像组件的id。
但是,我需要一个小小的转折点。应该在加载图像时显示转换图像,即加载图像。 Plz帮助我。
答
这很容易实现。 我会建议这样做。 为您的加载图像创建一个'imageHolder'精灵并将其添加到显示列表中。 在loader.contentLoaderInfo中添加Event.INIT的侦听器,然后在加载完成时删除加载镜像并将loader.content添加到imageHolder。
var _imageHolder:Sprite = new Sprite();
addChild(_imageHolder);
// add your loading image to the _imageHolder
_imageHolder.addChild(new LoadingImage()); // exported in your library?
var _loader:Loader = new Loader();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _onLoadComplete);
_loader.load(new URLRequest('path to assset'));
// image has loaded so remove the display image and add the content
function _onLoadComplete(e:Event):void{
_loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, _onLoadComplete);
_imageHolder.removeChildAt(0);
_imageHolder.addChild(_loader.content);
}