views:

24

answers:

1

hi,

I have a syntax problem using Actionscript. Can I create new objects from inside an ArrayColletion ?

var tagsList:TagsListModel = new TagsListModel(new ArrayCollection([

    {new TagModel("News", 36, yearPopularity, false, true)},
    {new TagModel("Information", 18, yearPopularity, false, true)}

]);

This is the error I get:

1084: Syntax error: expecting colon before rightbrace.

thanks

+1  A: 

You don't need curly braces when creating objects with new keyword.

var tagsList:TagsListModel = new TagsListModel(new ArrayCollection([ 
    new TagModel("News", 36, yearPopularity, false, true), 
    new TagModel("Information", 18, yearPopularity, false, true) 
]); 

Curly braces are for creating objects of type Object

var tagsList:TagsListModel = new TagsListModel(new ArrayCollection([ 
    {tag:"News", x:36, yp:yearPopularity}, 
    {tag:"Information", x:18, yp:yearPopularity} 
]); 

The following are one and the same:

var a:Object = {value:10};
trace(a.value);//10

var b:Object = new Object();
b.value = 10;
trace(b.value);//10
Amarghosh