VasylKorzhyk / as3corelib

Automatically exported from code.google.com/p/as3corelib
0 stars 0 forks source link

Serialization of dynamic class doesn't serialize correctly. #84

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a dynamic class
2. Add some objects to it.
3. Try to serialize it, they will not be in the output.

What version of the product are you using? On what operating system?
Flash 10, using Flex Builder, Windows XP

---------------

The problem is in this block of code

else // o is a class instance
{
    // Loop over all of the variables and accessors in the class and
    // serialize them along with their values.
    for each ( var v:XML in classInfo..*.( name() == "variable" || name()
== "accessor" ) )
    {
          // When the length is 0 we're adding the first item so
          // no comma is necessary
          if ( s.length > 0 ) {
              // We've already added an item, so add the comma separator
              s += ","
          }

          s += escapeString( v.@name.toString() ) + ":"
            + convertToString( o[ v.@name ] );
     }               
}

upon further investigation, I read that the classInfo  variable wasn't
populated correctly,

var classInfo:XML = describeType( o );

Note: it appears that describe type doesn't look at dynamic properties; the
documentation
(http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.h
tml#describeType())
doesn't say anything about not accessing dynamic types; in fact its type
has the property for dynamic..... This could be a flash 10 error or this
might not have worked all along.

The work around was relatively simple, inserting the following portion of
code above the for each in the portion above:

for (var y:String in o)
{                   
    s += escapeString(y) + ":"
          + convertToString (o[y]);
} 

The final block looks something like this:

else // o is a class instance
{

  for (var y:String in o)
  {
        s += escapeString(y) + ":"
        + convertToString (o[y]);
  }

  // Loop over all of the variables and accessors in the class and
  // serialize them along with their values.    
  for each ( var v:XML in classInfo..*.( name() == "variable" || name() ==
"accessor" ) )
  {
  // When the length is 0 we're adding the first item so
  // no comma is necessary
  if ( s.length > 0 ) {
   // We've already added an item, so add the comma separator
    s += ","
  }

  s += escapeString( v.@name.toString() ) + ":"
    + convertToString( o[ v.@name ] );
 }

}

Original issue reported on code.google.com by danthe...@gmail.com on 2 Jan 2009 at 10:16

GoogleCodeExporter commented 8 years ago
You can just remove the top level if statement, that begins with if ( 
classInfo.@name.toString() == "Object" );

Properties gathered by the for(var prop:String in object) loop are not exposed 
in the class definition xml. so you 
don't get a double up.

There is also a "IsDynamic" flag on the class definition xml if you really want 
to look into it.

Original comment by bung...@gmail.com on 26 Sep 2009 at 1:36