for each in object FAIL…need help please

By scotchfaster | Jun 25, 2009

actionscript3

This is a wacky one. I have an ActionScript 3.0 project (not Flex), and I’m trying to iterate through an Object and extract all keys and values.

Fortunately, my trusted "ActionScript 3.0 Bible" has this example:

ActionScript Code:
var notes:Object = new Object(); notes[“Roger”] = “Likes games”; notes[“Mims”] = “Super organized”; notes[“Ashley”] = “Enjoys drawing”;             for each (var name:String in notes) {     trace (“Notes on “ + name + “: “ + notes[name]); } //Displays: Notes on Roger: Likes games… etc.

But incredibly, this is the actual output:
Notes on Super organized: undefined
Notes on Enjoys drawing: undefined
Notes on Likes games: undefined

Any insight here would be GREATLY appreciated. Thanks.

actionscript3

Please reply at our Forum

1 Comment so far
  1. sim July 1, 2009 9:33 pm

    you’re looking for a different iteration

    for (var name:String in notes)
    trace (“Notes on “ + name + “: “ + notes[name]);

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

© 2007 ActionScript 3.0