将容器动态添加到动态容器中

时间:2011-09-21 23:25:53

标签: flex actionscript

我有一个循环,可以查看书中的数据并显示它。这本书的布局并不一致,所以我试图以两种不同的方式展示它。第一种方法(工作正常)是将该部分的文本加载到面板中并显示它。第二种方法是创建一个新面板(面板创建正常),然后将可折叠面板(嵌套)添加到该面板。这是来自else循环的代码。

else if (newPanel == false){
                    // simpleData is just for  the title bar of the new panel
                    // otherwise the panel has no content
                    var simpleData:Section = new Section;
                    simpleData.section_letter = item.section_letter;
                    simpleData.letter_title = item.letter_title;
                    simpleData.section_id = item.section_id;
                    simpleData.title = item.title;
                    simpleData.bookmark = item.bookmark;
                    simpleData.read_section = item.read_section;

                    var display2:readPanel02 = new readPanel02;
                    //item is all the data for the new text
                    display2.id = "panel"+item.section_id;
                    //trace(display2.name);//trace works fine
                    // set vars is how I pass in the data to the panel
                    display2.setVars(simpleData);
                    studyArea.addElement(display2); // displays fine
                    newPanel = true;

                    //this is where it fails
                    var ssPanel:subSectionPanel = new subSectionPanel;
                    //function to pass in the vars to the new panel
                    ssPanel.setSSVars(item);
                    //this.studyArea[newPanelName].addElement(ssPanel);
                    this["panel"+item.section_id].addElement(ssPanel);

我得到的错误是:ReferenceError:错误#1069:在components.readTest上找不到属性panel4.4并且没有默认值。

我尝试过设置“name”属性而不是“id”属性。任何帮助将不胜感激。我很难过。谢谢。

1 个答案:

答案 0 :(得分:0)

所以这是我提出的解决方案。我让新的readPanel创建了子面板。我添加了else语句来帮助它更有意义。 readPanel创建第一个子面板,并且对于子面板的每个后续需求,它按名称引用另一个面板,并在创建新子面板的面板中调用公共函数。这是创建主面板的代码:

else if (newPanel == false){
                    var display2:readPanel02 = new readPanel02;
                    studyArea.addElement(display2);
                    display2.name = "panel"+item.section_id;
                    display2.setVars(item);

                    newPanel = true;

                }
                else{
                    var myPanel:readPanel02 = studyArea.getChildByName("panel"+item.section_id) as readPanel02;
                    myPanel.addSubSection(item);

                }

这是面板中的功能:

public function setVars(data:Section):void
        {
            myS = data;
            textLetter = myS.section_letter;
            textLetterTitle = myS.letter_title;
            textSection = myS.section_id;
            textTitle = myS.title;
            myS.bookmark == 0 ? bookmarked = false : bookmarked = true;
            myS.read_section == 0 ? doneRead = false : doneRead = true;
            showTagIcon();
            showReadIcon();
            addSubSection(myS);

        }

        public function addSubSection(data:Section):void{
            var ssPanel:subSectionPanel = new subSectionPanel;
            ssPanel.setSSVars(data);
            myContentGroup.addElementAt(ssPanel, i);
            i++;
        }