flash as3 - 在对象中声明 null 属性,或在对象声明中运行函数
我有一个分配了许多属性的对象:
var project_array:Array = [];
var slideObject:Object = {
project_title : myXML.projects.project[i].title.toUpperCase(),
project_desc : myXML.projects.project[i].description.toUpperCase(),
project_name : myXML.projects.project[i].name.toUpperCase(),
project_agency : myXML.projects.project[i].agency.toUpperCase(),
project_img : myXML.projects.project[i].@img,
project_types : myXML.projects.project[i][email protected](", ")
}
project_array.push(slideObject);
我想要做的是,根据slideObject.project_types中的值,在slideObject中创建另一个数组来跟踪project_clips - 像这样:
for ( var i in project_types_array) {
/*(var typeClass:Class = getDefinitionByName('type_' + project_types_array[i]);
(var typeClip:typeClass = new typeClass();
project_clips_array.push(typeClip);
trace (project_types_array[i]);*/
switch (project_types_array[i]){
case "p":
var clip_p = new type_p();
project_clips_array.push(clip_p);
break;
case "exp":
var clip_exp = new type_exp();
project_clips_array.push(clip_exp);
break;
case "f":
var clip_f = new type_f();
project_clips_array.push(clip_f);
break;
case "oi":
var clip_oi = new type_oi();
project_clips_array.push(clip_oi);
break;
case "tv":
var clip_tv = new type_tv();
project_clips_array.push(clip_tv);
break;
}
}
但我不是很确定该把它放在哪里。如果我将它放在对象构造函数之外,我会得到“术语未定义”,我猜是因为它不知道project_clips_array是什么 - 但如果我在构造函数中声明project_clips_array,它似乎需要定义,即我可以不要创建空白属性。但我也不能将它放在构造函数中,因为它似乎不允许我在对象构造函数中运行函数。执行此函数以获取对象内的数组的正确语法或代码排列是什么?
I have an object which is assigned a number of properties:
var project_array:Array = [];
var slideObject:Object = {
project_title : myXML.projects.project[i].title.toUpperCase(),
project_desc : myXML.projects.project[i].description.toUpperCase(),
project_name : myXML.projects.project[i].name.toUpperCase(),
project_agency : myXML.projects.project[i].agency.toUpperCase(),
project_img : myXML.projects.project[i].@img,
project_types : myXML.projects.project[i][email protected](", ")
}
project_array.push(slideObject);
What I want to be able to do is, based on the values within slideObject.project_types, create another array within slideObject that keeps track of project_clips - like this:
for ( var i in project_types_array) {
/*(var typeClass:Class = getDefinitionByName('type_' + project_types_array[i]);
(var typeClip:typeClass = new typeClass();
project_clips_array.push(typeClip);
trace (project_types_array[i]);*/
switch (project_types_array[i]){
case "p":
var clip_p = new type_p();
project_clips_array.push(clip_p);
break;
case "exp":
var clip_exp = new type_exp();
project_clips_array.push(clip_exp);
break;
case "f":
var clip_f = new type_f();
project_clips_array.push(clip_f);
break;
case "oi":
var clip_oi = new type_oi();
project_clips_array.push(clip_oi);
break;
case "tv":
var clip_tv = new type_tv();
project_clips_array.push(clip_tv);
break;
}
}
but I'm not quite sure where to place this. If I place it outside of the object constructor, I get "term is undefined", I guess because it doesn't know what project_clips_array is - but if I declare project_clips_array in the constructor, it appears to need to be defined, i.e. I can't create a blank property. But I can't place it in the constructor either, because it doesn't seem to allow me to run a function within an object constructor. What is the proper syntax or arrangement of code for executing this function to get the array within the object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这样的事情应该有效:
I think something like this should work:
我是这样设置的:
I set it up like this: