flash as3 - 在对象中声明 null 属性,或在对象声明中运行函数

发布于 2024-10-18 12:30:22 字数 1968 浏览 2 评论 0原文

我有一个分配了许多属性的对象:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

日记撕了你也走了 2024-10-25 12:30:22

我认为这样的事情应该有效:

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](", ")
        }

slideObject.project_type_array = sortTypes(slideObject.project_types); 

project_array.push(slideObject);

function sortTypes(orig_array:Array):Array
{

    var type_array:Array = [];

    for ( var i in orig_array)
    {

        switch (orig_array[i])
        {

            case "p":
                var clip_p = new type_p();
                type_array.push(clip_p);
                break;
            case "exp":
                var clip_exp = new type_exp();
                type_array.push(clip_exp);
                break;
            case "f":
                var clip_f = new type_f();
                type_array.push(clip_f);
                break;
            case "oi":
                var clip_oi = new type_oi();
                new_array.push(clip_oi);
                break;
            case "tv":
                var clip_tv = new type_tv();
                type_array.push(clip_tv);
                break;
        }
    }

    return type_array;
}

I think something like this should work:

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](", ")
        }

slideObject.project_type_array = sortTypes(slideObject.project_types); 

project_array.push(slideObject);

function sortTypes(orig_array:Array):Array
{

    var type_array:Array = [];

    for ( var i in orig_array)
    {

        switch (orig_array[i])
        {

            case "p":
                var clip_p = new type_p();
                type_array.push(clip_p);
                break;
            case "exp":
                var clip_exp = new type_exp();
                type_array.push(clip_exp);
                break;
            case "f":
                var clip_f = new type_f();
                type_array.push(clip_f);
                break;
            case "oi":
                var clip_oi = new type_oi();
                new_array.push(clip_oi);
                break;
            case "tv":
                var clip_tv = new type_tv();
                type_array.push(clip_tv);
                break;
        }
    }

    return type_array;
}
反目相谮 2024-10-25 12:30:22

我是这样设置的:

for (var i=0;i<tp;i++){
        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_type_clips : [],
        }


        for (var j in slideObject.project_types){
            //trace ("object" + i + " | type " + j)
            switch (slideObject.project_types[j]){

            case "p":
                var clip_p = new type_p();
                slideObject.project_type_clips.push(clip_p);
                break;
            case "exp":
                var clip_exp = new type_exp();
                slideObject.project_type_clips.push(clip_exp);
                break;
            case "f":
                var clip_f = new type_f();
                slideObject.project_type_clips.push(clip_f);
                break;
            case "oi":
                var clip_oi = new type_oi();
                slideObject.project_type_clips.push(clip_oi);
                break;
            case "tv":
                var clip_tv = new type_tv();
                slideObject.project_type_clips.push(clip_tv);
                break;
            }


        } //end project_types loop

        project_array.push(slideObject);
    } // end object creation loop

    loadProject();

}

I set it up like this:

for (var i=0;i<tp;i++){
        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_type_clips : [],
        }


        for (var j in slideObject.project_types){
            //trace ("object" + i + " | type " + j)
            switch (slideObject.project_types[j]){

            case "p":
                var clip_p = new type_p();
                slideObject.project_type_clips.push(clip_p);
                break;
            case "exp":
                var clip_exp = new type_exp();
                slideObject.project_type_clips.push(clip_exp);
                break;
            case "f":
                var clip_f = new type_f();
                slideObject.project_type_clips.push(clip_f);
                break;
            case "oi":
                var clip_oi = new type_oi();
                slideObject.project_type_clips.push(clip_oi);
                break;
            case "tv":
                var clip_tv = new type_tv();
                slideObject.project_type_clips.push(clip_tv);
                break;
            }


        } //end project_types loop

        project_array.push(slideObject);
    } // end object creation loop

    loadProject();

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文