Actionscript/Shared Object issue

Out of context: Reply #1

  • Started
  • Last post
  • 4 Responses
  • thatblokemike0

    you can check the folder where shared objects are stored... not sure if your on mac or pc, but google it and find where that is, somewhere deep in your computer.

    or call SharedObject.getLocal( COOKIE_NAME, "/" );

    I just modded a class I have that does similar to suit your needs... altho I admit untested in this case as just opened my class and stripped it down, it should provide a way to get your prob sussed and may work off the bat.

    package com.yoursite.utils
    {
    import flash.events.EventDispatcher;
    import flash.net.SharedObject;

    /**
    * @author mike
    *
    * simple class for getting setting or clearing the users data
    *
    */
    public class UserSharedObject extends EventDispatcher
    {

    /**
    * the name of the sharedobject that we're placing on the users machine
    */
    public static const COOKIE_NAME:String = "mywebpage.mywebsite.com";

    /**
    * Stores the arrays
    * @param myBoolean - a boolean to store in the array
    * @param reference - a hash for storage
    */
    public static function setData( myBoolean:Boolean, reference:String ) : void
    {
    var _so:SharedObject = getUserData();

    var items:Array = _so.data.items;

    try
    {
    // check if the reference already exists and replace it
    for( var i:int=0; items.length; i++ )
    {
    if(items[i].reference == reference)
    {
    _so.data.items[i] = { reference:reference, myBoolean:myBoolean };
    _so.flush();
    return;
    }
    }

    }catch( e:Error )
    {
    trace( "ERROR: there was no exisiting references" );
    }

    _so.data.items = [];
    _so.data.items.push( { reference:reference, myBoolean:myBoolean } );
    _so.flush();
    }

    /**
    * gets a specific boolean
    */
    public static function getDataByReference( reference:String ):Boolean
    {
    var _so:SharedObject = getUserData();

    var items:Array = _so.data.items;

    try
    {
    for( var i:int=0; i<items.length; i++ )
    {
    if( reference == items[i].reference )
    {
    return items[i].myBoolean;
    }
    }
    }catch( e:Error )
    {
    trace("ERROR: shared object didnt have a array length");
    }

    return false;
    }

    /**
    * Returns the entire shared object
    */
    public static function getUserData() : SharedObject
    {
    return SharedObject.getLocal( COOKIE_NAME, "/" );
    }

    /**
    * clears the users shared object
    */
    public static function clearUserData() : void
    {
    var _so:SharedObject = SharedObject.getLocal( COOKIE_NAME, "/" );
    _so.clear();
    }

    }
    }

    • I have to admit that is a bit over my head. I'll head to the gym and come back with a fresh look. Thanks for the help.CyBrain

View thread