* AJAX Offline
Posted on October 8th, 2005 by Dave Johnson. Filed under AJAX, Flash, Flex, JavaScript.
Just a quick post about running AJaX offline. With the recent release of Flash 8 it seems a good time to bring this up since Flash 8 has everything you need for a robust cross-browser data persistence layer. The two main features of Flash 8 are the SharedObject (although this has been around for a few years now - since Flash 6) and more importantly full JavaScript support. The SharedObject allows you to store as much data as the end user wants to allow and this limit can be configured by the end user.
In the Flash file you can use the ExternalInterface to expose methods to the JavaScript runtime like this:
import flash.external.ExternalInterface;
ExternalInterface.addCallback("JavaScriptInterfaceName", null, FlashMethod);
Similarly you can call JavaScript functions from within the Flash file using the call method of the ExternalInterface
ExternalInterface.call("JavaScriptMethod");
And you can call methods in the Flash movie from JavaScript like this:
function CallMethod() {
if (document.getElementById)
myFlash = document.getElementById("FlashMovieNodeId");
if (myFlash)
myFlash.flashFunction();
}
The other piece of the puzzle is the SharedObject which is accessible through ActionScript in Flash.
var my_SO:SharedObject = SharedObject.getLocal("MySharedObjectName");
my_SO.data.eba = dat;
var ret_val = my_SO.flush();
It is importatnt to note that if the end user specified data size limit is smaller than the requested amount of data to be saved it needs to show the Flash movie to the user (do this simply with a little JavaScript) so the user can either increase the cache size or not. The ret_val from the SharedObject flush method can be checked to see the result and determine if the Flash movie needs to be shown for input or not.
The other great thing about this is that the upgrade path to Flash 8 has been made a bit better. You can actually have the Flash 8 player installed through the old Flash player from what I understand (called Express Install I believe).
All and all a pretty slick way to persist data with AJaX without relying on cookies or the User Data behaviour in IE.
5 Responses to “AJAX Offline”
Leave a Reply
Recent Posts
- BlackBerry JavaScript Oddities
- JavaScript Event Merging
- Smart Grid Utilities
- PhoneGap Desktop
- Crockford Facts
Archives
- July 2010
- June 2010
- April 2010
- March 2010
- February 2010
- January 2010
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005

October 8th, 2005 at 11:35 am
Hi Dave. I did exactly this, but made it compatible with Flash 6+ forward. Its still in beta, but its open source. See http://codinginparadise.org/weblog/2005/10/permanent-client-side-storage-for-ajax.html for details.
October 10th, 2005 at 12:12 pm
Dave,
Do you have ideas how can users retrieve the stored information when theyre offline? Say, you have an RSS Reader, and the downloaded messages are saved locally when youre online. You close the web browser and disconnect from the network: now what do you do to read the RSS messages? I guess you open the web browser. But which URL do you type? Do you open a web page from the file system? Do you need a local web server? What are your thoughts?
I would first think of opening a file from the file system, or actually, you should have the entire application locally (which could be 1 or more files). This would be fairly easy to install: download a zip file, expand it, and youre done. Or maybe its possible to store the applications files in the Flash storage area, do you know?
Just some random thoughts
Thanks,
Jep
October 11th, 2005 at 11:14 am
The project looks pretty nice Brad - having made a proof of concept I am happy that someone else has created a project from it
Jep I am not sure about this certainly it would store data between online sessions and work if you leave the browser open from an online to offline session. Havent really thought about how it would work out in the cases you have outlined.
dave
January 18th, 2006 at 8:34 am
FYI, an online/offline wiki prototype: http://blog.monstuff.com/archives/000272.html
The Flash object uses the same technique that you mention. One concern tough: ExternalInterface can get quite slow with large data (100K). Thats not a big problem for a wiki, but it was slowing down my other prototype app (not published yet): an online/offline RSS reader.
January 23rd, 2006 at 4:16 am
Dave, ExternalInterface has significant performance problems; this is why I use the Flash 6+ Flash methods to do Flash/JavaScript communication, such as GetVariable, SetVariable, fscommand, etc. These can reliably pass around megabytes of information very quickly. I use ExternalInterface only for Safari support. Im rolling all of this into dojo.flash (which is used by dojo.storage), so that others can use it in their own projects. It was _really_ hard to find the exact performant, compatible, non-buggy path to achieve the stuff above, but I think I finally found it so that its easier for others to use in their own projects.