简体   繁体   English

Flash as3加载程序问题

[英]flash as3 loader question

What I am trying to do is load 2 different swf's using 2 different buttons. 我想做的是使用2个不同的按钮加载2个不同的swf。

What I want to happen is when you click on button 1 it loads the first swf and button 2 loads the second swf removing any other swf from the stage first. 我想发生的是,当您单击按钮1时,它会加载第一个SWF文件,而按钮2会加载第二个SWF文件,然后首先从舞台上移除所有其他SWF文件。

The problem I seem to be running into is with the loader. 我似乎遇到的问题是加载程序。 I cannot seem to load the images into the loader without putting them on the stage. 如果没有将它们放在舞台上,我似乎无法将图像加载到加载器中。 And when I try to load the images dynamically it keeps on recreating the swf's by placing another one in the loader even though I am using : 当我尝试动态加载图像时,即使我使用的是它,它也会通过在加载器中放置另一个来继续创建swf。

stage.removeChild(loader);
loader = new Loader();. 

Any help or tutorials on this information would be great. 关于此信息的任何帮助或教程都将非常有用。

I would use separate Loader's for each image you want to load. 我要为要加载的每个图像使用单独的加载器。 here's a quick example of how you could implement it: 这是一个如何实现它的简单示例:

*edit:It's cutting off the package part, please forgive me for not understanding stackoverflow's code parser. *编辑:它切断了包装部分,请原谅我不了解stackoverflow的代码解析器。 * *

`package `包装
{ import flash.display.Loader; {import flash.display.Loader; import flash.display.Sprite; 导入flash.display.Sprite; import flash.events.Event; 导入flash.events.Event; import flash.events.MouseEvent; 导入flash.events.MouseEvent; import flash.net.URLRequest; 导入flash.net.URLRequest;

public class LoaderTest extends Sprite
{
    //two loaders
    private var _firstLoader:Loader = new  Loader();
    private var _secondLoader:Loader = new  Loader();

    //just assuming you already have the buttons you want setup, use these as theoretical buttons
    private var _buttonOne:Sprite;
    private var _buttonTwo:Sprite;

    public function LoaderTest() 
    {
        _firstLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
        _secondLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);  
        _firstLoader.load(new URLRequest("path/to/image.jpg"));
        _secondLoader.load(new URLRequest("path/to/image.jpg"));

        _buttonOne.addEventListener(MouseEvent.CLICK, showImage);
        _buttonTwo.addEventListener(MouseEvent.CLICK, showImage);
    }

    private function imageLoaded(e:Event):void
    {
        //do something if you want
    }

    private function showImage(e:MouseEvent):void
    {
        switch(e.target)
        {
            case _buttonOne :
                if (!contains(_firstLoader))
                {
                    if (contains(_secondLoader))
                        removeChild(_secondLoader);

                        addChild(_firstLoader);
                }
            break;
            case _buttonTwo :
                if (!contains(_secondLoader))
                {
                    if (contains(_firstLoader))
                        removeChild(_firstLoader);

                        addChild(_secondLoader);
                }
            break;              
        }
    }


}

} ` }`

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

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