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
Posts: 166
Registered: ‎03-04-2011
My Device: Playbook
Accepted Solution

Storing data within my mobile app.

[ Edited ]

Hello.

 

I'm developing a PlayBook application using ActionScript. I'm very very new with this.

 

I want to store three list of words. I'm wondering to use an XML. Is there any way to read XML? I've found this: XML.

 

It will be like a table with two columns:

 - ID

 - Word

 - Language

 

I've read that SQLite is supported, but I don't want to use a database to store three lists of words (maybe, this is the best and easiest solution).

 

How can I do this?

 

Thank you.

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Storing data with my mobile app.

You can save xml to a file or use SharedObjects.  Lots of threads on both of these objects.  Look at the adobe flex docs for:

  • SharedObjects
  • File
  • FileStream
  • XML

Good luck.

Developer
Posts: 166
Registered: ‎03-04-2011
My Device: Playbook

Re: Storing data with my mobile app.

Thanks for your answer.

 

I'm using Adobe Flash Builder "burrito". Where I have to save my XML file inside project structure?

 

I have an SRC folder, and nothing else.

 

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Storing data with my mobile app.

[ Edited ]

Need to store the file at runtime.  "src" is at compile time.

 

Store it in the app-storage directory.

 

See File class API at:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/File.html

 

 

Developer
Posts: 166
Registered: ‎03-04-2011
My Device: Playbook

Re: Storing data with my mobile app.

[ Edited ]

No, I have to store it before compilation.

 

I suppose I have to save my file on SRC folder, and I have to use the following code to retreive the file:

 

 

var prefsFile:File = File.applicationStorageDirectory;
prefsFile = prefsFile.resolvePath("english.xml");

Is this correct?

 

How can I parse the following file:

 

 

<?xml version="1.0" encoding="iso-8859-1"?>
<words>
	<word>
		<id>1</id>
		<name>Orange</name>
	</word>
	<word>
		<id>2</id>
		<name>Lemon</name>
	</word>
</words>

 

I don't know how to open a file to parse it with XML class.

 

Thanks!

 

 

 

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Storing data with my mobile app.

var config : XML = null;
var file : File = File.applicationStorageDirectory.resolvePath( 'english.xml' );
if( file.exists )
{
	var file_stream : FileStream = new FileStream();
	file_stream.open( file, FileMode.READ );
	config = new XML( file_stream.readUTFBytes( file_stream.bytesAvailable ) );
	file_stream.close();
}

 

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Storing data with my mobile app.

From the config file, you can use standard XML class to traverse it.  For example:

 

var nbr_words : int = config.word.length();

var i  : int;

for( i=0; i < nbr_words; i++ )

{

  trace( 'word ' + config.word[i].id + ' ' + config.word[i].name );

}

 

Developer
Posts: 166
Registered: ‎03-04-2011
My Device: Playbook

Re: Storing data with my mobile app.

I have saved my files in SRC folder, but I can't access it at runtime using the following code:

 

 

package com.company.name
{
	import flash.display.Sprite;
	import flash.filesystem.File;
	import flash.filesystem.FileStream;
	import flash.filesystem.FileMode;
	
	import qnx.ui.buttons.LabelButton;

	public class GamePage extends Sprite
	{
		public function GamePage()
		{
			var label:LabelButton = new LabelButton();
			label.label = "Welcome to Second Page";
			addChild(label);

			var file : File = File.applicationStorageDirectory.resolvePath("english.xml");
			if( file.exists )
			{
				var config:XML = null;
				var file_stream : FileStream = new FileStream();
				file_stream.open( file, FileMode.READ );
				config = new XML( file_stream.readUTFBytes( file_stream.bytesAvailable ) );
				file_stream.close();
			
				var nbr_words : int = config.word.length();
				var i  : int;
				
				for( i=0; i < nbr_words; i++ )
				{
					trace( 'word ' + config.word[i].id + ' ' + config.word[i].name );
				}
			}
		}
	}
}

 

 

Is there a problem with package name?

 

Thanks.

Developer
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
My Carrier: Verizon

Re: Storing data with my mobile app.

How is the english.xml file being created?

If they are installed with your app, then you need to use File.applicationDirectory.resolvePath( 'assets/english.xml' ); or whatever.