0

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

Maurício
  • 25
  • 6
  • 1
    What specifically isn't working? Also I don't think setting `percent` to `null` is what you're wanting to do there. – Marty Jul 19 '12 at 23:05

3 Answers3

0

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.

Marty
  • 39,033
  • 19
  • 93
  • 162
BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40
0

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"));
Zhafur
  • 1,626
  • 1
  • 13
  • 31
0

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