2

由于我开发了一些应用程序,因此我遇到了 ProgressEvent.PROGRESS 的一些问题。我尝试将此事件分配给从 XML 数据加载的每个图像。最后一次正确调用的每个图像都会预加载。问题是每个以前都没有。我试图找出这个解决方案: problem with progressEvent Listener,但可能我在某处出错。

这是我的代码:

var total_columns_preview = myXML.table[companyNumber].column.length();         
for (var p:int=0; p < total_columns_preview; p++) 
{

    var foto_nest:String = myXML.table[companyNumber].column[p].@name.toString();   
    var foto_name:String = myXML.table[companyNumber].column[p].toString(); 
    if (foto_nest == "foto") 
    {
        var foto_icon_mc = new image(); 
        images_container_mc.addChild(foto_icon_mc);
            if (foto_name != "") {

        var varrLoadersFoto:Loader = new Loader();
            varrLoadersFoto.name = "image"+p; 
            varrLoadersFoto.load(new URLRequest("igwodociagi/min_pic/min/"+foto_name));
            varrLoadersFoto.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressLoadFoto);
            varrLoadersFoto.contentLoaderInfo.addEventListener(Event.COMPLETE, onFotoLoaded);
            foto_icon_mc.photo_container.addChild(varrLoadersFoto);                                         
                var preloader:MovieClip = new preloader_mc();
                foto_icon_mc.addChild(preloader);                               
                images_container_mc.addChild(foto_icon_mc);

            }               
    }   
}

    function onFotoLoaded(event:Event) {

            event.target.content.smoothing = true;
            preloader_foto_dimm = new Tween(preloader, "alpha", Strong.easeOut, 1, 0, 0.6, true);
            immage_foto_undim = new Tween(event.target.content, "alpha", Strong.easeOut, 0, 1, 0.6, true);


    }               

    function progressLoadFoto(e:ProgressEvent) {

            var percent:Number = e.bytesLoaded / e.bytesTotal * 100;
            preloader.logo_preload.text = (Math.floor(percent) / 100) + "%";                                                        
            preloader.preload_box.scaleX = (Math.floor(percent) / 100);


    }

我的问题是如何为每个图像分别分配事件,以便预加载器将为每个图像更新。

4

1 回答 1

2

好的,对于寻求解决方案的人来说,这是我遵循的https://stackoverflow.com/users/1206613/cherniv建议的实现。“不要将它们加载到 for 循环中,而不是在上一个 onFotoLoaded 之后加载每个下一个”

    var total_columns_preview = myXML.table[companyNumber].column.length();
for (var p:int=0; p < total_columns_preview; p++){
    var foto_nest:String = myXML.table[companyNumber].column[p].@name.toString();
    var foto_name:String = myXML.table[companyNumber].column[p].toString();
    if (foto_nest == "foto"){
        //loading object from library
        var foto_icon_mc = new image(); 
        loadPictures();
    }
}
function loadPictures(){
    var varLoadersFoto:Loader = new Loader();
        varLoadersFoto.contentLoaderInfo.addEventListener(Event.INIT, initLoadFoto);
        varLoadersFoto.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressLoadFoto);
        varLoadersFoto.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadedFoto);
        varLoadersFoto.load(new URLRequest("igwodociagi/min_pic/min/"+foto_name));
        foto_icon_mc.photo_container.addChild(varLoadersFoto);
            //loading preloader object from library
            var preloader:MovieClip = new preloader_mc(); 
            foto_icon_mc.addChild(preloader);
    function initLoadFoto(e:Event):void{
        //here i place where photo should be visible (x, y - possition)
    }
    function progressLoadFoto(e:ProgressEvent){
        var percent:Number = e.bytesLoaded / e.bytesTotal * 100;
        preloader.logo_preload.text = (Math.floor(percent) / 100) + "%";
        preloader.preload_box.scaleX = (Math.floor(percent) / 100);
    }
    function onLoadedFoto(e:Event){
        //smoothing loaded content (bitmap) if dimentions of loaded file are too big
        e.target.content.smoothing = true; 
        preloader_foto_dimm = new Tween(preloader,"alpha",Strong.easeOut,1,0,0.6,true);
        immage_foto_undim = new Tween(e.target.content,"alpha",Strong.easeOut,0,1,0.6,true);
    }
}

谢谢你。希望对某人有所帮助。

于 2013-05-25T22:00:10.830 回答