Actionscript 3 将变量引用传递到函数中

Actionscript 3 将变量引用传递到函数中,actionscript-3,Actionscript 3,我有一个图像数组,我需要循环抛出它们以获取url并通过此函数加载它们loadImage,该函数工作正常并加载图像将我的问题放入Movieclip块当我将图像添加到其中时,图像是否已添加到循环中的最后一个Movieclip var relatedJSON = JSON.decode(e.target.data); var relatedStories = relatedJSON.stories; if(relatedStories.length > 0){ f

我有一个图像数组,我需要循环抛出它们以获取url并通过此函数加载它们loadImage,该函数工作正常并加载图像将我的问题放入Movieclip当我将图像添加到其中时,图像是否已添加到循环中的最后一个Movieclip

var relatedJSON = JSON.decode(e.target.data);
    var relatedStories = relatedJSON.stories;
    if(relatedStories.length > 0){
        for(var j:Number=0;j<relatedStories.length;j++){
            if(relatedStories[j].yahki_thumb){
                var one = j+1;
                var block = related_stories.getChildByName('related_stories_block'+one);
                // load the image
                loadImage({
                    path:relatedStories[j].yahki_thumb,
                    success:function(e:Event,my_loader:Loader)
                    {
                        my_loader.width = this[block].width;
                        my_loader.height = this[block].height;
                        this[block].img.addChild(my_loader);
                    },
                    error:function(e:Event)
                    {
                        // error
                        echo('error to load an image');
                    }
                });
            }
        }
        // replay button event
        //replay
    }else{
        // error
        echo('no related stories');
    }
var relatedJSON=JSON.decode(e.target.data);
var relatedStories=relatedJSON.stories;
如果(relatedStories.length>0){
对于(var j:Number=0;j请在循环内尝试以下操作:

   var that:* = this;
   (function(block:*):void{
       loadImage({
                path:relatedStories[j].yahki_thumb,
                success:function(e:Event,my_loader:Loader)
                {
                    my_loader.width = that[block].width;
                    my_loader.height = that[block].height;
                    that[block].img.addChild(my_loader);
                },
                error:function(e:Event)
                {
                    // error
                    echo('error to load an image');
                }
            });
   })(block);
由于加载是异步的,当调用success函数时,
block
值已经
相关的故事。getChildByName('related\u stories\u block'+relatedStories.length)
值。这就是为什么元素被添加到最后一个
MovieClip