Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 919133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:29:31+00:00 2026-05-15T18:29:31+00:00

I’m trying to use the native flex serialization/deserialization process to save/load state of a

  • 0

I’m trying to use the native flex serialization/deserialization process to save/load state of a workspace in flex. In order to save or load a file I have to use my servlet, which just bounces back the bytes from the input stream to the output stream. Here’s a basic outline of my Flex code:

Serialized Object Container:

public class MyWorkspace {
    public var id : String;
    public var url : String;
    public var objectCollection : ArrayCollection; // Contains MySubObjects
}

Serialized sub object:

public class MySubObject
{
    public var name:String;
    public var csv:String;
}

Visual Element Constructor:

public function VisualSandbox(){
    registerClassAlias("MyWorkspaceAlias", MyWorkspace);
    registerClassAlias("MySubObjectAlias", MySubObject);
}

Visual Element Event Handlers:

public function onSaveButtonClick(event : MouseEvent) : void
{
    var ws : MyWorkspace = new MyWorkspace();
    ws.id = "ID";
    ws.url = "URL";
    ws.objectCollection = new ArrayCollection(veObjCollectionAC.source.slice());

    var ba : ByteArray = new ByteArray();
    ba.writeObject(ws);
    ba.position = 0;

    var fr : FileReference = new FileReference();
    // There's no need for me to put the rest so 
    ...
    fr.download(urlRequest, "workspace.ws");
}

public function onLoadButtonClick(event : MouseEvent) : void
{
    veFileReference = new FileReference();
    veFileReference.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, loadCompleteHandler);
    // This part works as well so I'm skipping it.

}

public function loadCompleteHandler(event : DataEvent) : void
{
    // Pretend I loaded "workspace.ws" by bouncing it off of my servlet byte for byte.
    var ba : ByteArray = new ByteArray();
    ba.writeObject(event.data);
    ba.position = 0;
    var obj : * = ba.readObject();
    trace(obj is MyWorkspace); // Prints false
}

So my problem here is not with the saving of the workspace. That works great. My problem is with the loading of a workspace. The event.data that I write to the byte array is not reconstituted into a MyWorkspace object even though it is exactly what I wrote to the file.

There has to be a way of making a MyWorkspace object from the data, but I can’t figure it out. Has anyone tried to do this before?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:29:32+00:00Added an answer on May 15, 2026 at 6:29 pm

    I’ve figured out what the problem here is. It specifically has to do with the line:

    ba.writeObject(event.data);
    

    The data field of the event, being a DataEvent, is specifically of type String. ByteArray.writeObject() puts a type code at the beginning of the byte array. This took me many hours of looking at Hexplorer to figure out why, exactly, the byte array had 2-3 extra characters at its beginning.

    My current best solution for this is to change that line as follows:

    for (var i : int = 0; i < event.data.length; ++i)
    {
        ba.writeByte(event.data.charCodeAt(i));
    }
    

    This ensures that the byte array is exactly the same as what was saved to my local drive and bounced off my servlet.

    After doing this, trace(obj is MyWorkspace) prints true.

    Hope this helps someone else in the future!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I am trying to loop through a bunch of documents I have to put
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.