0

抱歉,如果这已在其他地方得到回答,但我找不到任何匹配的东西。

我有两个瑞士法郎;一个预加载器(我们称之为 A)和一些内容(B)。A 加载 B 并将其添加为子项。一切都运行良好(你甚至可以在这里看到)。

我只有一个小问题。通常,当使用 URLLoader 类将图像加载到 flash 中时,我添加+ "?" + new Date().getTime()到 URLRequest 以强制 flash 加载目标的最新版本,换句话说,使用缓存版本停止它。现在,当我尝试对将 B 添加到 A 的加载程序执行此操作时,它找不到 URL ( #2035 URL not found)。所以我的问题是:我正在尝试做的事情是否可行,或者我应该采取另一种方法来阻止 B 缓存?

这是预加载器代码:

package 
{
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.events.ProgressEvent;
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.ErrorEvent;
    import flash.net.URLLoader;
    import flash.text.TextField;

    public class claude_loader extends MovieClip
    {
        public var main_movie:Loader = new Loader();
        public var rss_loader:URLLoader;
        private var perc_text:TextField = new TextField();
        public function claude_loader()
        {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            with (perc_text)
            {
                x = this.stage.stageWidth / 2;
                y = this.stage.stageHeight / 2;
            }
            addChild(perc_text);
            main_movie.load(new URLRequest("claudia_summers.swf"+ "?" + new Date().getTime()));
            main_movie.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, load_progress);
            main_movie.contentLoaderInfo.addEventListener(Event.COMPLETE,on_complete);
        }
        public function load_progress(e:ProgressEvent):void
        {
            var perc:Number = Math.round((e.bytesLoaded/e.bytesTotal)*100);
            perc_text.text = "Loading " + perc + "%";
            if (e.bytesLoaded == e.bytesTotal)
            {
                perc_text.text = "Loading done";
            }
        }
        public function on_complete(e:Event):void
        {
            rss_loader = new URLLoader(new URLRequest("http://news.sulsc.org/feed"));
            rss_loader.addEventListener(Event.COMPLETE,rss_complete);
            perc_text.text = "Loading RSS";
        }
        public function rss_complete(e:Event):void
        {
            MovieClip(main_movie.content).rss_xml = XML(e.target.data);
            addChild(main_movie);
        }

    }
}
4

1 回答 1

0

不知道如何/为什么,但添加String()周围new Date().getTime()并给 main_movie 一个IOErrorEvent监听器可以解决问题。我想我在某处有一个错误,因为如果没有这些添加,这肯定可以工作,不是吗?无论如何,感谢您的帮助!

工作代码:

package 
{
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.display.Loader;
    import flash.net.URLRequest;
    import flash.events.ProgressEvent;
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.ErrorEvent;
    import flash.net.URLLoader;
    import flash.text.TextField;
    import flash.events.IOErrorEvent;

    public class claude_loader extends MovieClip
    {
        public var main_movie:Loader = new Loader();
        public var rss_loader:URLLoader;
        private var perc_text:TextField = new TextField();
        public function claude_loader()
        {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            with (perc_text)
            {
                x = this.stage.stageWidth / 2;
                y = this.stage.stageHeight / 2;
                textColor = 0xFFFFFF;
            }
            addChild(perc_text);
            main_movie.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,catch_error);
            main_movie.load(new URLRequest("claudia_summers.swf" + "?" + String(new Date().getTime())));
            function catch_error(e:IOErrorEvent):void
            {
            main_movie.load(new URLRequest("claudia_summers.swf"));
            perc_text.text = "Failed non-cache load"
            }
            main_movie.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, load_progress);
            main_movie.contentLoaderInfo.addEventListener(Event.COMPLETE,on_complete);
        }
        public function load_progress(e:ProgressEvent):void
        {
            var perc:Number = Math.round((e.bytesLoaded/e.bytesTotal)*100);
            perc_text.text = "Loading " + perc + "%";
            if (e.bytesLoaded == e.bytesTotal)
            {
                perc_text.text = "Loading done";
            }
        }
        public function on_complete(e:Event):void
        {
            rss_loader = new URLLoader(new URLRequest("http://news.sulsc.org/feed"));
            rss_loader.addEventListener(Event.COMPLETE,rss_complete);
            perc_text.text = "Loading RSS";
        }
        public function rss_complete(e:Event):void
        {
            MovieClip(main_movie.content).rss_xml = XML(e.target.data);
            addChild(main_movie);
        }

    }
}
于 2013-06-07T19:59:04.577 回答