corelib in flash cs3

Skip to first unread message


Sep 21, 2007, 5:31:38 PM9/21/07
to ActionScript 3 Core Library
how do i use the core library in flash cs3? particularly the md5




Sep 27, 2007, 6:00:52 PM9/27/07
to ActionScript 3 Core Library
Yes, I am having a problem as well. When I do:

// var json contains valid JSON
var json:String = JSON.decode(json) as Array;

It always returns null.

I am looking for an alternate JSON decoder for Flash CS 3....


Darron Schall

Sep 27, 2007, 6:13:40 PM9/27/07
I think you're using it incorrectly. Try this:

var json:String = "[ 'hello', 'world' ]";
var results:Array = JSON.docde( json ) as Array;

trace( results[ 0 ] ); // hello
trace( results[ 1 ] ); // world

If you're still getting null results, I'd be interested to see what your
json string looks like before it's passed to the decoder.



Sep 28, 2007, 1:07:20 AM9/28/07
to ActionScript 3 Core Library
I am not using it wrong at all. I've been using corelib in Flex
Builder 2 with no problems. Today I spent a whole 10 hours tearing my
hair out to no avail, to try to decode JSON within Flash CS3. It just
simply doesn't work.

I've uploaded a file to this group here:

Unzip it, and open (Document class for test.fla). It simply
imports com.adobe.....JSON, and tries to use it as simply as possible.

The encode function seems to work, and it cannot even decode a string
it encoded.

Your example above doesn't even work, however it works rudimentarily
by switching your single for double quotes / vice versa. (The
commented out line in

I greatly appreciate any help you can give my wrecked and tortured


Sep 28, 2007, 6:07:56 PM9/28/07
to ActionScript 3 Core Library
Hey people,

Problem is resolved! Thank God. The problem was in Flex, I could cast
the return value of JSON.decode() to an Array. This wasn't working in
Flash, but I cast to Object and it seems to work.


Darron Schall

Sep 28, 2007, 10:15:41 PM9/28/07
That's correct. In the example code you posted, you're encoding an
Object into a JSON string, and then decoding that JSON string and trying
to make an array out of it. You get a null result because decode
returns an Object in that case, and the cast from Object to Array fails.

The result from JSON.decode can be either Object, Array, String, Number,
Boolean or null. If you don't know what the expected return type from
decode is going to be, you can simply say:

var result:* = JSON.decode( jsonString ); // could return any type

// Test to see what the return type is
if ( result is String )
// ...
else if ( result is Number )
// ...
// .. etc.

Additionally, the "it works by swapping single quotes with double
quotes" is as expected as well. The JSON decoder is pertty strict
strict -- i.e. it only accepts a 100% valid JSON string as input (and
it's not very forgiving). If you take a look at the spec on, a
string needs to be wrapped in double quotes and not single quotes. My
apologies for typing incorrect code in an email. It's on my list to
make the decoder a little more forgiving, but I haven't had the time to
devote to it lately.

I'm glad you got it working after all.


Reply all
Reply to author
0 new messages