Alex, many thanks for your responses. I'd like to use the array's 'push'
method, but I'm loading the objects from a file, while the filestream has
bytesavailable, like this: 

 

while(stream.bytesAvailable){

_whatshouldIuseHere = stream.readObject() as DocumentFile;//

var aDoc:DocumentFile = stream.readObject() as DocumentFile;//only stores
the last saved DocumentFile, no matter if I have other objects stored


}

The question should be: given a file, that stores some objects saved in AMF
format. What can I do to retrieve each object, filter? 

____________________________________

Claudio M. E. Bastos Iorio

 <http://www.blumer.com.ar/> http://www.blumer.com.ar

 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Alex Harui
Sent: Thursday, August 14, 2008 4:46 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: writeObject() and readObject()

 

I think I don't understand your problem.  Normally, if you know how many you
are going to write, you would do:

 

arr.push(someDocumentFile);

arr.push(someOtherDocumentFile);

var numFiles:int = arr.length;

writeObject(numFiles);

for (var i:int = 0; I < numFiles, i++)

            writeObject(arr[i]);

 

And read it back like this:

 

Arr = [];

Var numFiles;

numFiles = readObject();

for (var i:int = 0; I < numFiles, i++)

arr.push(readObject());

 

 

If you don't know, how many, you might want to use a tagged file format

 

  _____  

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Claudio M. E. Bastos Iorio
Sent: Wednesday, August 13, 2008 10:12 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: writeObject() and readObject()

 

Could be. But forgive If I don't realize: how could I read the fileStream in
that way?

Right now I read it this way:

 

while(stream.bytesAvailable){

arr = stream.readObject() as DocumentFile;//bad cast


}

 

 

I also tried this:

 arr[0] = stream.readObject() as DocumentFile;//assigns the last
DocumentFile saved in the file..

 

 

____________________________________

Claudio M. E. Bastos Iorio

 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Alex Harui
Sent: Thursday, August 14, 2008 1:21 AM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: writeObject() and readObject()

 

I would write out the number of DocumentFiles before writing them out, then
when reading, I'd read that number and know how many to expect

 

  _____  

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Claudio M. E. Bastos Iorio
Sent: Wednesday, August 13, 2008 9:13 PM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: writeObject() and readObject()

 

Thanks for answer.

But what can I do if I have many DocumentFile objects written in the file?
Is there any way to retrieve all objects or filter by value name/id..? just
like a database o e4x..

 

____________________________________

Claudio M. E. Bastos Iorio

 

 

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Alex Harui
Sent: Thursday, August 14, 2008 12:20 AM
To: flexcoders@yahoogroups.com
Subject: RE: [flexcoders] Re: writeObject() and readObject()

 

If you wrote an instance of DocumentFIle, you need to read back an instance
of DocumentFIle

 

  _____  

From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of slackware2142
Sent: Wednesday, August 13, 2008 5:57 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: writeObject() and readObject()

 

I forgot to mention that I'm using FLEX3 and my class (DocumentFile) 
is already registered:

[RemoteClass(alias="com.DocumentFile")]
public class DocumentFile extends EventDispatcher
{
...
)

____________________________________
Claudio M. E. Bastos Iorio

--- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> ,
"slackware2142" <[EMAIL PROTECTED]> 
wrote:
>
> Hi! I'm trying to create a simple 'file database' in AIR.
> I know I can save and restore objects in AMF format using the 
methods 
> write/restoreObject.
> 
> here is my code to save:
> 
> var DocumentToSave:DocumentFile = new DocumentFile
(); //DocumentFile 
> is a custom class
> DocumentToSave.Name = 'some name';
> var file:File = File.applicationStorageDirectory.resolvePath
> ('myApp.data');
> var stream:FileStream = new FileStream();
> stream.open(file, FileMode.APPEND);
> stream.writeObject(DocumentToSave);
> 
> That code is working and stores the DocumentFile objects and 
values. 
> But, what can I do to retrieve that objects (or any particular 
> object).
> 
> I tried this to retrieve:
> 
> var file:File = File.applicationStorageDirectory.resolvePath
> ('myApp.data');
> var stream:FileStream = new FileStream();
> stream.open(file, FileMode.READ);
> var arr:Array = new Array();
> while(stream.bytesAvailable){
> //what can I use here to create an array of DocumentFiles stored 
> in 'myApp.data'?
> arr = stream.readObject() as Array; //seems to work
> }
> 
> trace('new arr length: ' + arr.length);//doesn't work, why??
> 
> Any help?
> 
> Thanks in advance!
> 
> 
> ____________________________________
> Claudio M. E. Bastos Iorio
>

 

Reply via email to