0
votes

sorry if this has been answered elsewhere but I can't find anything matching.

I have two swfs; a preloader (let's call it A) and some content (B). A loads B and adds it as a child. Everything is working beautifully (you can even see it here).

There's just one little problem I'm having. Normally when loading, say an image, into flash using the URLLoader Class, I add + "?" + new Date().getTime() to the URLRequest to force flash to load the latest version of the target, in other words to stop it using a cached version. Now, when I try to do this to the Loader that adds B to A, it can't find the URL (#2035 URL not found). So my question is: is what I'm trying to do possible, or should I take another approach to stopping B from caching?

Here's the preloader code:

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);
        }

    }
}
1
it is normal practice. try to wrap new Date().getTime() with brackets ()Ivan Chernykh
@Cherniv this produces the same errorLaurence Summers
what does trace("claudia_summers.swf"+ "?" + new Date().getTime()) produce?Ronnie
@itcouldevenbeaboat it looks right to me. traces out claudia_summers.swf?1370625007600Ronnie
I understand why you're putting the time in there. I've done it before, exactly like this. This may be a long shot, but try this "claudia_summers.swf?" + String(new Date().getTime())Ronnie

1 Answers

0
votes

Not sure how/why, but adding String() around new Date().getTime() and giving main_movie an IOErrorEvent listener resolves the issue. I think I have a bug somewhere, as this surely should have worked without these additions, no? Anyway thanks for all your help!

Working code:

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);
        }

    }
}