Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Developer
MDAndrewM
Posts: 32
Registered: ‎02-22-2011
My Device: Not Specified

Shared Object Issue

[ Edited ]

So I've been done with my App for a while and looking forward to the release of the playbook.  I finally got it and immediately downloaded my app.  It only took a litle while to discover a small problem.  My App is called Patience and is a simple solitaire card game.  When you exit it is supposed to save everything you've unlocked and even the game state, however it is not doing this.  I tested this thoroughly in the simulator, but I have no idea why it isn't working now.  It saves whenever the app is closed and even shrunk, however it appears to not be working on the actual playbook.  Does anyone have any ideas as to why this must be the case?

 

The listeners I add in the constructor:

 

QNXApplication.qnxApplication.addEventListener(Event.DEACTIVATE, onExit); //listener when minimized
			QNXApplication.qnxApplication.addEventListener(Event.EXITING, onExit); //add listener to exit

 

 

The method it calls:

 

internal function onExit(e:Event):void{
			save();
		}

 

internal function save():void{ 
			var gameData:SharedObject = SharedObject.getLocal("PatienceData");
			gameData.data.highscore = this.highscore;
			gameData.data.backStyle = this.backStyle;
			gameData.data.cardStyle = this.cardStyle;
			gameData.data.board = this.board;
			gameData.flush();
			
		}

 

 

 

And the load code called in the constructor as well:

 

internal function load():void{ 
			
			var gameData:SharedObject = SharedObject.getLocal("PatienceData");
			if(gameData.data.highscore!=undefined){
				this.highscore=gameData.data.highscore;
			}
			if(gameData.data.backStyle!=undefined){
				this.backStyle=gameData.data.backStyle;
			}
			if(gameData.data.cardStyle!=undefined){
				this.cardStyle=gameData.data.cardStyle;
			}
			
			
			
		}
internal function loadBoard():void{
            var gameData:SharedObject = SharedObject.getLocal("PatienceData");
            if(gameData.data.board!=null){
                this.board=gameData.data.board;
            }else{
                this.resetBoardRandom(null);
            }
            this.setCards();
            this.draggable=true;
            this.updateScore();
            if(this.numViable()==0){
                this.displayGameOver();
            }
        }

 

 

 

 

Contributor
galaxyprune
Posts: 45
Registered: ‎03-07-2011
My Device: Not Specified

Re: Shared Object Issue

Hi, the DEACTIVATE Event in 1.0 (actual Device) Version is not triggered depending on the type of Multitasking is selected. As far as I know, only the Setting "Paused" will trigger this Event. Search in the Forums and you will see, that many others have this issue.

Developer
billfoust
Posts: 382
Registered: ‎05-19-2008
My Device: BlackBerry Torch

Re: Shared Object Issue

You didn't specify what kind of error you are getting. 

 

Did you specify the proper permission in your blackberry-tablet.xml file?

Bill
-------------------------------------------
Check out my book on BlackBerry Development for Java.
And my other really really old book
My Apps: FlashKids
Contributor
banzai76
Posts: 28
Registered: ‎02-18-2011
My Device: Not Specified

Re: Shared Object Issue

[ Edited ]

I recommend you build a quick and dirty test app and try it on your playbook to make sure that your SharedObject code is definitely working (i.e that this is an event-related issue and not a permissions issue).

 

This post should help answer your question on why certain events aren't called on the actual device:

 

http://supportforums.blackberry.com/t5/Tablet-OS-SDK-for-Adobe-AIR/How-to-save-data-on-application-e...

 

(it's to do with the multitasking mode set in the PlayBook settings).

 

One potential catch-all solution is to save the game state whenever it changes? If it's solitaire, can you save the game state after each card is played? Then you don't have to rely on exit handlers.

Developer
MDAndrewM
Posts: 32
Registered: ‎02-22-2011
My Device: Not Specified

Re: Shared Object Issue

I am working on figuring out the problem, but I'm having trouble with my debug token (since obviously the VM isn't a good indicator for my issue).

 

http://supportforums.blackberry.com/t5/Tablet-OS-SDK-for-Adobe-AIR/Problem-with-the-Debug-Token/td-p...

Developer
MDAndrewM
Posts: 32
Registered: ‎02-22-2011
My Device: Not Specified

Re: Shared Object Issue

So i got my debugging tokens working, etc and got another ap that is using the shared object on there where it is a button that saves the preferences to an object, however those are not working, so I think it is a permission error.  How do i set the proper permissions in the .xml?

Contributor
banzai76
Posts: 28
Registered: ‎02-18-2011
My Device: Not Specified

Re: Shared Object Issue

I have 2 apps that use sharedobject and neither require any permissions. I don't think you need to unless you are trying to save data outside the apps own directory. Are you intending to do that?

 

What path are you specifiying for the shared object file? I use this command to retrieve them:

 

var sharedObject:smileyfrustrated:haredObject =  SharedObject.getLocal("my_file", "/");   

 

Where the trailing slash ensure a relative path is used.

 

 

Developer
MDAndrewM
Posts: 32
Registered: ‎02-22-2011
My Device: Not Specified

Re: Shared Object Issue

[ Edited ]

I was about to try the local saving with the slash when I noticed something very peculiar.  My saves are partially working.  But they're only saving once.  If you have your Playbook and want to test it yourself, you can download Patience (it's free).  The first time you exit (or the first time it saves) is locked in.  When you exit my app, you are supposed to be able to reenter to the same state.  I noticed that when I exit and reenter it doesn't just randomly place the board as it does the first time you enter the app (and it finds no save data).  It is always starting at the same position.  It is saving once, but only once.  I have slightly recreated this with my VM and my new app as well.  I tried using the clear() function before saving, but that didn't work.  I am just getting more confused on what my problem is.

Developer
shawnblais
Posts: 439
Registered: ‎10-25-2010
My Device: Not Specified

Re: Shared Object Issue

Generally writing to disk on exit is a bad idea, you're creating a race condition where sometimes the write will finish, and other times it won't.

When AIR is closed, it doesn't wait around for File IO's to finish, it just closes.

The better approach is to save state each time it changes.
Developer
MDAndrewM
Posts: 32
Registered: ‎02-22-2011
My Device: Not Specified

Re: Shared Object Issue

The save that I'm talking about in my other app is not being done on exit and it still seems to be having this issue, though.  I am still investigating, but I've got a lot of homework these days.