Question

I have written a game in Flash (AS3/Flex SDK/MXMLC) that streams music and sound files from my server.

I'm concerned about bandwidth - the audio components are nearly 3MB, and if the game becomes popular it will really rack up the bandwidth charges.

Is there any way to make Flash cache the audio components once they've been downloaded, instead of streaming them every time the game is loaded on the same PC?

I know about the SharedObjects ("cookies") but I don't think there's a way to store binary data in there... or is there?

Was it helpful?

Solution

When you say "stream", I assume you mean progressive download over HTTP.

You'll want to ensure that your media assets are being sent from your server with the appropriate caching headers that meet your goals, for starters. If those are not cache friendly, then files won't be cached. Also, query strings will generally prevent client-side caching.

There is nothing really magical about the Flash player in this regard--everything should work as if this all was just a plain ol' web page.

You may want to consider hosting your large, static media assets on something cheap-ish (like Amazon S3 or CloudFront.) This could reduce the cost of bulk transfers that do not require application logic.

Update inspired by the comments: Here is a possible outline for you to follow in your quest...

  1. Figure out what kind of caching is and is not happening first
    1. Clear your browser cache
    2. Go through a use case in your game
    3. Go through it again, with the expectation of seeing the same content used
    4. Inspect web server log files. The first group of requests should all have HTTP 200 respond codes. For the second group of requests, "cachable" requests for files that have already been delivered you should see either nothing or HTTP 304 (a request just to see if the content cached is valid.) If you see identical sets of requests, all with 200 OK, then caching is not happening
  2. Learn more about caching
    1. Install a FireFox plug-in like TamperData, watch the caching headers
    2. Read the spec, know it. RFC 2616
    3. Experiment

I would not be surprised if you were caching content already but just didn't realize it!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top