简体   繁体   English

Flash CS6 as3:加载之前先下载图像数组

[英]Flash CS6 as3: dowload array of images before loading

I can't figure out how to download all array(~10 pic) of images and then use them on screen. 我不知道如何下载所有图像(约10张图片),然后在屏幕上使用它们。 The problem is that in order not to weight the server, the pictures should be downloaded one time . 问题是,为了不给服务器加权,应将图片下载一次

Now I load images like this: [code specially without the array just for example] 现在,我加载这样的图像:[例如,仅在没有数组的情况下专门编码]

    var shirt1 = String("https://static.topsport.lt/sites/all/themes/topsport2/files/images/marskineliai_png/215.png");
    var img1Request:URLRequest = new URLRequest(shirt1);
    var img1Loader:Loader = new Loader();
    img1Loader.load(img1Request);
    myMovieClip.removeChildAt(0);
    myMovieClip.addChild(img1Loader);

I'm thinking about somehow in one flash keyframe as3 code load all images, and in second add load images to screen. 我正在考虑以某种方式在一个Flash关键帧中使用as3代码加载所有图片,然后在第二个添加加载图片到屏幕。

ps I add and remove array of Child's for the same movieclip symbol. ps我为相同的动画片段符号添加和删除了孩子的数组。

[edit] Here's that I try to compile: [edit]这是我尝试编译的:

FRAME 1 框架1

    function startLoad(e:Event = null):void {

        var marsk1 = String("https://static.topsport.lt/sites/all/themes/topsport2/files/images/marskineliai_png/215.png");
        var img1Request:URLRequest = new URLRequest(marsk1);
        var img1Loader:Loader = new Loader();
        img1Loader.load(img1Request);
        myMovieClip.removeChildAt(0);
        if(_2 != null){

        myMovieClip.smoothing = true;}

        //myMovieClip.addChild(img1Loader).addEventListener(Event.COMPLETE, startLoad);

        function achild(){
            myMovieClip.addChild(img1Loader);
        }
    }

FRAME 2 框架2

    achild().addEventListener(Event.COMPLETE, startLoad);

I tried to apply my situation to Andrey Popov suggestion. 我试图将我的情况应用于安德烈·波波夫的建议。 Can I import the function from the previous frame? 我可以从上一帧导入功能吗? Because I'am trying to do it and I get method not found 因为我正在尝试这样做,但我找不到方法

You need to use addEventListener , and wait until the loading is finished. 您需要使用addEventListener ,并等待加载完成。 Then start a new one. 然后开始一个新的。 Something like this: 像这样:

var currentImage:uint = 0;

function startLoad(e:Event = null):void {
    if (currentImage == 5) {
        // we are all done
        return;
    }

    var loader:Loader = new Loader();
    // loader specific stuff..
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, startLoad);
    currentImage++;
}

This is a rough pseudo code but the idea is simple - wait for a loader to load, then load new image. 这是一个粗糙的伪代码,但思路很简单-等待加载程序加载,然后加载新图像。

I've solved the problem between frame actionscript connection by taking 我已经解决了框架动作脚本连接之间的问题

var img1Loader:Loader = new Loader();

and putting it in front of the function. 并将其放在函数的前面 That's how the loader can be accessed on the other frame. 这就是可以在另一帧上访问加载程序的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM