Select to view content in your preferred language

Save Session State on client (not Flex Viewer)

1123
8
09-10-2010 08:22 AM
RoyceSimpson
Frequent Contributor
I've searched the forum and haven't seen anything very descriptive about this but...

and this is more of a straight up Flex (4) question than the AGS API...

Is there a way to save out current app settings, such as current map center, map scale, visible layers, etc... to a client side XML file or some such... to be loaded back up later when the user re-initializes the app from that pc?

Thanks,
-r
Tags (2)
0 Kudos
8 Replies
DasaPaddock
Esri Regular Contributor
You can use a FileReference to save and load local files, but this require user interaction.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html

If you're rather have something more like a browser cookie, then you can use SharedObject:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/SharedObject.html
0 Kudos
RoyceSimpson
Frequent Contributor
Thanks Dasa, Will have a look at those.
-r
0 Kudos
RoyceSimpson
Frequent Contributor
Ok, the SharedObject class works very well.  I created an "ApplicationsSettings" class that sets/gets all the appropriate values throughout the app.  That class then manages the SharedObject.  Then when the app loads in subsequent sessions, it checks the applicationsSettings properties and applies them where needed. 

I now have an app that holds all the map settings (scale, layers turned on, map center, other settings) between sessions, if the user turns that feature on.  When the user turns that off, the app clears the SharedObject (through the ApplicationSettings class) and sets all app settings back to defaults.

Next SharedObject task... bookmarks.

Very nice.

Thanks again Dasa.
-r
0 Kudos
IainCampion
Deactivated User
Ok, the SharedObject class works very well.  I created an "ApplicationsSettings" class that sets/gets all the appropriate values throughout the app.  That class then manages the SharedObject.  Then when the app loads in subsequent sessions, it checks the applicationsSettings properties and applies them where needed. 

I now have an app that holds all the map settings (scale, layers turned on, map center, other settings) between sessions, if the user turns that feature on.  When the user turns that off, the app clears the SharedObject (through the ApplicationSettings class) and sets all app settings back to defaults.

Next SharedObject task... bookmarks.

Very nice.

Thanks again Dasa.
-r


are you prepare to share?

that's something we were about to work on too ... we might be able to extend your initial project?

Cheers
Coomsie
0 Kudos
BjornSvensson
Esri Regular Contributor
Next SharedObject task... bookmarks.-r


Maybe you already know, but that is what the Bookmark Widget in the ArcGIS Viewer for Flex does.
0 Kudos
RoyceSimpson
Frequent Contributor
I created a singleton class:  "ApplicationSettings.as"...

package org.larimer
{
 import flash.net.SharedObject;

 public class ApplicationSettings
 {
  // module level vars
  private static var _instance:ApplicationSettings;
  private var _so:SharedObject;
  
  // constructor
  public function ApplicationSettings(enforcer:SingletonEnforcer)
  {
   _so = SharedObject.getLocal("applicationSettings");
  }
  
  public static function getInstance():ApplicationSettings
  {
   if(ApplicationSettings._instance == null)
   {
    ApplicationSettings._instance = new ApplicationSettings(new SingletonEnforcer());
   }
   return _instance;
  }
  
  // public properties
  // scale
  public function get scale():Number
  {
   return _so.data.scale; 
  }
  public function set scale(value:Number):void
  {
   _so.setProperty("scale", value);
  }
               
                //more properties
                ...
       }
}
class SingletonEnforcer{}


Then reference the class in the various components:
private var _applicationSettings:ApplicationSettings = ApplicationSettings.getInstance();



To persist the map scale property:
_applicationSettings.scale = map.scale;


To retrieve the scale upon app load:
map.scale = _applicationSettings.scale;


That's the basic concept.  Map scale is an easy property to deal with but that's the idea.
Good luck,
-r
0 Kudos
RoyceSimpson
Frequent Contributor
Maybe you already know, but that is what the Bookmark Widget in the ArcGIS Viewer for Flex does.


Thanks Bjorn,
I've not actually looked at the viewer for some time but perhaps should at some point.
-r
0 Kudos
BjornSvensson
Esri Regular Contributor
I've not actually looked at the viewer for some time but perhaps should at some point.


@Royce, the source code for Flex Viewer 2.1 (being released later this month) can be a treasure trove of Flex code for Flex API developers even if not planning to use the actual Viewer 🙂
0 Kudos