Preloader flash AS3 it's no longer working [GZIP issue]

自古美人都是妖i 提交于 2019-12-12 01:08:02

问题


I'm using this preloader AS3 code below. And it's not working! When I execute on Flash CS5.5 works fine, but not online.

var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
l.load(new URLRequest("movie.swf"));

function loop(e:ProgressEvent):void
{
    var perc:Number = e.bytesLoaded / e.bytesTotal;
    percent.text = Math.ceil(perc*100).toString();
}

function done(e:Event):void
{
    removeChildAt(0);
    percent = null;
    addChild(l);
}

I've found the problem and the solution!

The problem is because my online server have gzip on for mod_deflate option on Apache.

The mod_deflate module provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network.

So the movie.swf was been compressed with gzip. That's the great problem.

SOLUTION HERE:

Well, just create or put some code into .htaccess file at server root folder.

Create a file (or put this code into) .htaccess

SetEnv no-gzip dont-vary 

# Don't compress images/flash  
SetEnvIfNoCase Request_URI \ 
\.(?:gif|jpe?g|png|swf|flv)$ no-gzip dont-vary 

Have fun :P


回答1:


If it's not working online but works locally, then here's a few good places to start.

  1. Make sure your file is in the spot your application thinks it is
  2. Make sure when exporting from flash that your network settings are set to remote and not local. To check this, goto Publish Settings, then the flash tab, then down to the advanced section where it says "Local Playback Security".

It's good practice to listen for errors and not just the progress/complete events on your loaders, then you can track down these problems easier.

IOErrorEvent.IO_ERROR and SecurityErrorEvent.SECURITY_ERROR listeners would confirm the possible issues above.




回答2:


The problem is, that when you upload it online, the program trying to reach the movie.swf ON THE SITE'S FTP where you uploaded it. So movie.swf to your own domain, and then paste the url of it. e.g.:

l.load(new URLRequest("http://mysite.com/movie.swf"));



回答3:


Your solution works great if you have access to the server's .htaccess file, but what if you don't. I found I could get around this by adding a header to my HTTP Request. By default, IE will have a request header called "Accept-Encoding", set to "gzip,deflate". You can override this and set its value to "x" or something. Anything but "gzip"

eg.

var header:URLRequestHeader = new URLRequestHeader("Accept-Encoding", "xxx");

var request:URLRequest = new URLRequest("http://www.whatever.com/myfile.zip"); request.requestHeaders = [header];

var loader:Loader = new Loader(); loader.load(request);



来源:https://stackoverflow.com/questions/11570544/preloader-flash-as3-its-no-longer-working-gzip-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!