PDA

View Full Version : What happend to the Object Initializer "{}"?


burtonrider1983
09-01-2006, 01:36 AM
I used to always use this to initialize a class with certain variables.
var test:myClass = new myClass("test", {_x:20, _y:20});

When I try to do this in AS3.0, it tells me that only 1 parameter was expected...or however many that constructor expects.
I was wondering, did they completely get rid of the object initializer? Is there a slightly different syntax to achieve the same functionality? Yes I know I could use getter/setters functions to change the properties, or I could add parameters to the constructor to substitute this, but I would like to know if the object initializer is removed. I know that you can use ... to signify that you are accepting zero or more parameters more, I will try and get it working this way in the meantime. I assume that this was the replacement for the makeshift way the object initializer used to.

senocular
09-01-2006, 01:38 AM
the problem is not {}, its your class constructor that only accepts one parameter. If you want that object to come in, put it in the constructor parameter list.

burtonrider1983
09-01-2006, 11:03 PM
Thanks senocular. Oh, and thanks for your tutorial on the Flex 2 command line compiler. You did a great job and I am sure a ton of people are learning a good amount from it.

I guess I was so used to attachMovie() that I forgot I was not using the constructor directly with this. Well I feel stupid... :rolleyes:

senocular
09-02-2006, 12:34 AM
It happens ;)