×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    2

    SharedObject utility doesn't work properly

    I'm developing a Flash Lite 2.1 application for the N90 series of Nokia phones, and the retrieving of data from SharedObjects in Flash Lite is working unreliably.

    Below is the code I'm using:

    Code:
    // Initialising and using shared object data on frame 2
    var savedData:SharedObject = SharedObject.getLocal("littlefarmer_strawman");
    var savedDataInit:Function = function (so:SharedObject) {
    	if (so.getSize()>0) {
    		for (var wl:Number = 0; wl<menuItems.length; wl++) {
    			var pap:Number = so.data.objState[wl];
    			_root[menuItems[wl]].gotoAndStop(pap);
    		}
    	} else {
    		so.data.objState = new Array();
    		head.gotoAndStop(2);
    		face.gotoAndStop(2);
    		body.gotoAndStop(2);
    		legs.gotoAndStop(2);
    	}
    	savedDataInitCheck = true
    };
    SharedObject.addListener("littlefarmer_strawman", savedDataInit);
    Code:
    // saving of code on keypress, several frames after frame 2
    ...
    if (menuItems[menuInteger] != "clear") {
    	if (Key.getCode() == 37) {
    		theClip = _root[menuItems[menuInteger]]
    		_root.indicator.gotoAndPlay("left")
    		theClip.prevFrame()
    		savedData.data.objState[menuInteger] = theClip._currentframe
    		savedData.flush()
    	} else if (Key.getCode() == 39) {
    		theClip = _root[menuItems[menuInteger]]
    		_root.indicator.gotoAndPlay("right")
    		theClip.nextFrame()
    		savedData.data.objState[menuInteger] = theClip._currentframe
    		savedData.flush()
    	}
    } else {
    ...
    The code is extremely fickle in choosing the platforms that it works on. In its current state, it works perfectly (i.e. the saves are loaded every time I test the movie) ONLY when I test the movie with CTRL+Enter from my FLA on a player emulating Flash Lite 2.1 on N90. When I run the generated .SWF file, the whole SharedObject class does not work because the listener does not run. When running on an actual phone (N97), the listener is initialised, but SharedObject.flush() returns 'pending' without any popup.

    Why do the same lines of code work so differently on different platforms?

    If I don't use a listener to initialise my Sharedobject, the whole application works perfectly fine on my computer (regardless of whether I'm using CTRL+Enter or running the generated SWF). On the actual phone, the SharedObject is loaded, but when I try to flush the data it doesn't save into the SharedObject (my guess is that it returns a status of 'pending' too, but I haven't traced the value).

    Any help would be greatly appreciated.

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2005
    Location
    Karachi, Pakistan
    Posts
    277

    Re: SharedObject utility doesn't work properly

    Hello,

    You can try initialing the SO, saving the data, and delete reference to it. And when loading do the same.

    This code works for me. Take a look:

    Code:
    function loadNick()
    {
    	loadNick_onLoad = function(so:SharedObject)
    	{
    		if(so.getSize() > 0)
    			nick = so.data.nick;
    		else
    			nick = "Guest";
    	}
    	
    	SharedObject.addListener("myAppKey", loadNick_onLoad);
    	var so:SharedObject = SharedObject.getLocal("myAppKey");
    }
    
    
    function saveNick(nick:String)
    {
    	var so:SharedObject = SharedObject.getLocal("myAppKey");
    	so.data.nick = nick;
    	so.flush();
    }
    Notice that I initialize a new SO in each function.

    Hope it helps,

    // chall3ng3r //
    Faisal Iqbal (skype: chall3ng3r)
    Flash Mobile Specialist | Orison Technologies
    _____________________________________
    blog: F·L·A·S·H·I·S·M
    swf2go: www.swf2go.com

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    126

    Re: SharedObject utility doesn't work properly

    Hi,
    Some tips that might help:
    1. Try putting the addListener() before getLocal() call
    2. When you run the swf file on your PC, the addListener()doesn't work. SharedObjects in Flash are not the same as Flash Lite. So you need to call yourself. This is what I usually do:
    Code:
            if (isFlashLite()) // my simple implementation - see below
            {
                if(System.capabilities.hasSharedObjects)
                {
                   SharedObject.addListener(SOName, soInitHandler);
                   StatSO = SharedObject.getLocal(SOName);
                   StatSO.path = this;  // this is because I use it within a class
                }
                else
                {
                   ... (do whatever you want...)
                }
            }
            else // Flash
            {
               StatSO        = SharedObject.getLocal(SOName);
               StatSO.path   = this;
               soInitHandler(StatSO);
            }
    isFlashLite() is simple, but has to handle a stupid bug:
    Code:
        function isFlashLite():Boolean
        {
           var ver:String = getVersion();
           if (ver.substr(0,2) == "FL" || ver.substr(1,2) == "FL")
                return (true);
           return (false);
        }
    3. using semicolon at the end of each line is a very good practice!
    Hope it helps,

    Ranco
    www.mobilityCraft.com

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    2

    Re: SharedObject utility doesn't work properly

    The first method worked for the application I was working on.

    I tried the same method on another similar application that was designed with touch functionality (and is coded similarly). Flash Lite chooses not to work on that application. I've tried every single possible thing that the above two posts have stated, but it either returns a flush state of true and doesn't load the damn thing at all, or it returns the flush state of pending. SharedObjects are so buggy and frustrating.

    Code:
    // saved data bullshit
    var savedDataArray:Array = new Array();
    var savedDataBool:Boolean = true
    var savedDataStart:Function = function (so:SharedObject) {
    	if (so.getSize()>0) {
    		so.path.savedDataArray = so.data.objData.splice()
    	} else {
    		so.data.objData = new Array();
    		so.path.savedDataBool = false
    	}
    };
    SharedObject.addListener("litterfarmer_strawmanTouch", savedDataStart);
    var savedData:SharedObject = SharedObject.getLocal("litterfarmer_strawmanTouch");
    savedData.path = this
    
    delete savedData;
    Code:
    function RecordData(index:Number,nama:String) {
    	//var savedData:SharedObject = SharedObject.getLocal("litterfarmer_strawmanTouch"); (this method works sometimes, but just completely refuses to work other times)
    	_root.savedDataArray[index] = nama
    	_root.savedData.data.objData = _root.savedDataArray
    	_root.savedData.flush()
    	//delete savedData
    }


    Thanks for helping guys.

  5. #5
    Registered User
    Join Date
    Oct 2009
    Posts
    126

    Re: SharedObject utility doesn't work properly

    You have to remember that flush() is asynchronous, so when you get "pending" it just means "be patient, I'm only a phone!"
    About reading data - you have to wait for the data, so don't use it in the first frame.
    I usually load in the first frame, and wait for some user interaction (like "Start game") to move to the frame that actually uses the data.
    I had some rough time with SO at first, but now it works everytime (quoting from the 10 classic programmers excuses: "it works on my machine" (1st excuse))
    On the other hand, I've tested my apps only on 5800 and N97, never on N90.
    Ranco

Similar Threads

  1. S60 emulator and SVG don't work properly.
    By kelele in forum Tools and SDK Feedback (Closed)
    Replies: 4
    Last Post: 2007-01-28, 14:08
  2. Replies: 5
    Last Post: 2006-10-12, 09:25
  3. Caching of WML-SCRIPT does not work properly on 6210
    By HarryD in forum Mobile Web Site Development
    Replies: 2
    Last Post: 2005-01-09, 14:40
  4. CommConnection does not work with Series 60 SDK, but works in JWT
    By jackiechan2001 in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2004-02-04, 09:07
  5. fopen don't work properly on Nokia 9210
    By Nokia_Archive in forum Symbian C++
    Replies: 2
    Last Post: 2002-05-29, 13:10

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •