2010-02-23 195 views
0

我需要創建一個圖庫來加載圖像並顯示它們。這部分是好的:在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幫助我。

回答

0

這很容易實現。 我會建議這樣做。 爲您的加載圖像創建一個'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); 
}