Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

JSON encoding support for __HTMLScriptObjects / __HTMLScriptArrays #182

Open
wants to merge 1 commit into from

1 participant

@brianreavis

Arrays and Objects coming from mx:HTML windows are of the __HTMLScriptObject & __HTMLScriptArray types—which behave slightly differently than traditional objects and arrays. Trying to JSON encode them without these changes produces an incorrect result.

@sangupta sangupta referenced this pull request from a commit in sangupta/as3corelib
@sangupta sangupta fix for issue #182 on original fork. 5ea2c58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 6 additions and 2 deletions.
  1. +6 −2 src/com/adobe/serialization/json/JSONEncoder.as
View
8 src/com/adobe/serialization/json/JSONEncoder.as
@@ -198,6 +198,10 @@ package com.adobe.serialization.json
*/
private function arrayToString( a:Array ):String
{
+ // arrays of the __HTMLScriptArray type use string keys rather than numeric keys
+ var typeName:String = describeType( a ).@name.toString();
+ var isScriptArray:Boolean = (typeName == "flash.html::__HTMLScriptArray" || typeName == "flash.html::__HTMLScriptObject");
+
// create a string to store the array's jsonstring value
var s:String = "";
@@ -215,7 +219,7 @@ package com.adobe.serialization.json
}
// convert the value to a string
- s += convertToString( a[ i ] );
+ s += convertToString( a[ isScriptArray ? i.toString() : i ] );
}
// KNOWN ISSUE: In ActionScript, Arrays can also be associative
@@ -251,7 +255,7 @@ package com.adobe.serialization.json
// determine if o is a class instance or a plain object
var classInfo:XML = describeType( o );
- if ( classInfo.@name.toString() == "Object" )
+ if ( classInfo.@name.toString() == "Object" || classInfo.@name.toString() == "flash.html::__HTMLScriptObject" )
{
// the value of o[key] in the loop below - store this
// as a variable so we don't have to keep looking up o[key]
Something went wrong with that request. Please try again.