开发者

Variable Object Property Names in As3 flex?

开发者 https://www.devze.com 2023-01-28 11:57 出处:网络
I need to create variable object property names for use with the data grid component. This works: data = new Object();

I need to create variable object property names for use with the data grid component.

This works:

 data = new Object();
 data.some_name = "the data";

But this does not:

 data = new Object();
 colName = "some_name";
 data[colName] = "the data";

Can anyone help me? Can object property names be variable?开发者_开发知识库


var colName:String = "Column Title";
var colNameNoSpace:String = "ColumnTitle"

var dataObject:Object = new Object();
dataObject[colName] = "What's the problem?";
dataObject[colNameNoSpace] = "There's no problem!"

trace(dataObject["Column Title"]);  //What's the problem?
trace(dataObject[colName]);         //What's the problem?
trace(dataObject.ColumnTitle);      //There's no problem!
trace(dataObject[colNameNoSpace]);  //There's no problem!


Maybe you forgot to assign the some_name property! the following should work...

 var data:Object = new Object();
 data.some_name = "the data";
 colName = "some_name";
 data[colName] = "the data";


It does not work because:

colName is a variable, which means is a pointer to the address where the string "some_name" is placed

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号