我使用Actionscript时遇到语法问题。我可以在ArrayColletion中创建新对象吗?
var tagsList:TagsListModel = new TagsListModel(new ArrayCollection([
{new TagModel("News", 36, yearPopularity, false, true)},
{new TagModel("Information", 18, yearPopularity, false, true)}
]);
这是我得到的错误:
1084: Syntax error: expecting colon before rightbrace.
感谢
答案 0 :(得分:3)
使用new
关键字创建对象时,您不需要花括号。
var tagsList:TagsListModel = new TagsListModel(new ArrayCollection([
new TagModel("News", 36, yearPopularity, false, true),
new TagModel("Information", 18, yearPopularity, false, true)
]);
大括号用于创建Object
var tagsList:TagsListModel = new TagsListModel(new ArrayCollection([
{tag:"News", x:36, yp:yearPopularity},
{tag:"Information", x:18, yp:yearPopularity}
]);
以下是同一个:
var a:Object = {value:10};
trace(a.value);//10
var b:Object = new Object();
b.value = 10;
trace(b.value);//10