Skip to content

Instantly share code, notes, and snippets.

@lynxerzhang
Last active August 16, 2019 08:04
Show Gist options
  • Save lynxerzhang/0c94f48aade15c334761067eafcc3d08 to your computer and use it in GitHub Desktop.
Save lynxerzhang/0c94f48aade15c334761067eafcc3d08 to your computer and use it in GitHub Desktop.

Revisions

  1. lynxerzhang revised this gist Aug 16, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion JS_LocalStorage.as
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ public class JS_LocalStorage
    public static function read(_key:String):*
    {
    try {
    var result:* = ExternalInterface.call("function(key) {window.localStorage.getItem(key); }", _key);
    var result:* = ExternalInterface.call("function(key) {return window.localStorage.getItem(key); }", _key);
    return result;
    }catch(e:Error){
    }
  2. lynxerzhang created this gist Aug 16, 2019.
    36 changes: 36 additions & 0 deletions JS_LocalStorage.as
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    package utils
    {
    import flash.external.ExternalInterface;

    //@see https://code.tutsplus.com/tutorials/quick-tip-how-to-communicate-between-flash-and-javascript--active-3370
    public class JS_LocalStorage
    {
    public function JS_LocalStorage()
    {
    }

    public static function save(_key:String, _value:*):void
    {
    try{
    ExternalInterface.call("function(key, value) {window.localStorage.setItem(key, value); }", _key, _value);
    }
    catch(e:Error){
    }
    }

    public static function read(_key:String):*
    {
    try {
    var result:* = ExternalInterface.call("function(key) {window.localStorage.getItem(key); }", _key);
    return result;
    }catch(e:Error){
    }
    }

    public static function contain(key:String):Boolean
    {
    var result:* = read(key);
    return result != null && result != undefined;
    }
    }
    }