Reputation: 4750
This won't work, throwing Error #1056:
m_cdictDeadConnections = new Dictionary();
m_cdictDeadConnections[1] = "f";
Huh? What's wrong with the syntax here? Thanks!
EDIT: A couple of answers kind of refer to the lack of syntax; I was getting the variable out of a class definition. Sorry about the confusion.
EDIT: For further clarity, Error #1056 is being thrown on this line of code:
m_cdictDeadConnections[1] = "f";
That doesn't seem like something that should be able to happen, aside from some really obscure language rules or something.
Upvotes: 0
Views: 89
Reputation: 895
I think your code is no problem.
just as you said: "I was getting the variable out of a class definition"
I suggest you trace the object after you insert value.
m_cdictDeadConnections = new Dictionary();
m_cdictDeadConnections[1] = "f";
trace....
because m_cdictDeadConnections is a variable, so it may be changed or cleared by other codes. Hope this can help you.
Upvotes: 0
Reputation: 1054
You're just missing out the var
keyword:
var m_cdictDeadConnections:Dictionary = new Dictionary();
m_cdictDeadConnections[1] = "f";
(I also gave the var a type, :Dictionary
- a very good habit to get into!)
Upvotes: 1
Reputation: 576
As described by the documentation here http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/utils/Dictionary.html
The Dictionary class lets you create a dynamic collection of properties
So dynamically, the dictionary creates property on an object and uses what you specify into brackets as identifier.
If you want to create objects indexed by int, prefer the use of an Array.
var myArray:Array = new Array();
myArray[0] = ""
myArray[1] = "f";
If you want a hash use an Object. The object will be indexed by Strings:
var myObject:Object = new Object();
myObject["1"] = "f";
You can find more info on how to create these data structures here http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7eea.html
EDIT: It works fine on my laptop so dynamically it should be able to instantiate a property named 1.
Upvotes: 1
Reputation: 116
I can't see anything wrong with the logic. Just make sure that the syntax is correct.
var dictionary:Dictionary = new Dictionary();
Upvotes: 1