Local Storage

Monkey Forums/Monkey Code/Local Storage

Indiepath(Posted 2011) [#1]
Grab the files and plop them in your modules directory to use : http://www.moofoo.net/monkey/moofoo.rar

* This also includes the Async Module

Currently only supporting Flash & HTML5.. etc..etc..

This module enables you to store information to the devices local storage system. The data is stored and access using a key based system.

Import moofoo.localstorage

Global lclStorage:localStorage = New localStorage()
lclStorage.save("testkey", "Test String")
Print lclStorage.load("testkey")
lclStorage.remove("testkey")
Print "**"+lclStorage.load("testkey")



BigAnd(Posted 2011) [#2]
This looks cool Tim, nice one.


degac(Posted 2011) [#3]
Interesting (tested with FF4 and Chrome9)

I checked your code and the one provided by mojo for SaveState: mojo's code doesnt' work under FF4

Your code
moofooLocalStorage.prototype.save = function( key, data){
	localStorage.setItem( "moofooLocalStorage@"+key, data );
};

mojo-
gxtkApp.prototype.SaveState=function( state ){
	localStorage.setItem( "gxtkapp@... );
}


edit: there is some problem with code-box; there is NO \ after @

The only - apparent to me - difference is in the 'key' name (your is user-defined, the mojo's one id linked with the URL.


Indiepath(Posted 2011) [#4]
Sure - mojo allows you to save a single state per application (document.URL is the app title) . My Code allows many different saves per application.

If it does not work in pre-release versions of software then don't worry about it - local storage is probably off by default to prevent breakages.


Indiepath(Posted 2011) [#5]
Updateding to include expiry times so that localStorage can be used as a simple time based cache.


Indiepath(Posted 2011) [#6]
No idea why I'm wasting time on Flash - what a cad!


GW_(Posted 2011) [#7]
flash is the most lucrative target imo. Monkey has a long way to go to make the flash target viable and every little mod helps.


marksibly(Posted 2011) [#8]
Hi,

You should include something like document.url in the key or all apps will see the same data.


Indiepath(Posted 2011) [#9]
Hmm, my understanding was that localstorage is already domain specific. Obviously that's different for non-web-based apps..


Warpy(Posted 2011) [#10]
You could still have two monkey apps hosted on the same domain.


marksibly(Posted 2011) [#11]
Hi,

I remember having this problem when getting AppState going - may only be on some browsers - and munging with document.URL solved it.


Indiepath(Posted 2011) [#12]
Hello,

It slipped my mind that there WILL be *many* monkey apps on portals! How bad am I!! Wouldn't want all BigPortal.com HTML5 games sharing each others data! I will correct my errors - bye!

Tim.


diemar(Posted 2016) [#13]
Uh, 5 years ago... still. I don't understand, how munging mith document.URL would prevent other apps from reading the files, if that is indeed possible. I am sure this feature is not by design, but a bug/vulnerability of early html5 implementations.