Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从外部XML文件中添加插入式组合框列表?_Xml_Actionscript 3_Flash_Combobox - Fatal编程技术网

如何从外部XML文件中添加插入式组合框列表?

如何从外部XML文件中添加插入式组合框列表?,xml,actionscript-3,flash,combobox,Xml,Actionscript 3,Flash,Combobox,我正在浏览一个datadic.xml文件来填充actionscript 3.0中的一个组合框,但我想在前11个属性的每个部分之间添加一个分隔符或标题,然后是分隔符,最后是26个属性。这是我的xml文件的一部分: <codeSet> <title>Census: population estimates for Northern Ireland </title> <subtitle>By country, region and local auth

我正在浏览一个datadic.xml文件来填充actionscript 3.0中的一个组合框,但我想在前11个属性的每个部分之间添加一个分隔符或标题,然后是分隔符,最后是26个属性。这是我的xml文件的一部分:

<codeSet> 
<title>Census: population estimates for Northern Ireland </title>
<subtitle>By country, region and local authority</subtitle>
<txtSource>2011 Census</txtSource>
<txtSource2>2001Census</txtSource2>
<dateStart>2001</dateStart>
<dateEnd>2011</dateEnd>
<code id='94NI'>NORTHERN IRELAND</code>
<code id='N09000001'>Antrim and Newtownabbey</code>

人口普查:北爱尔兰人口估计
按国家、地区和地方当局分列
2011年人口普查
2001年
2001
2011
北爱尔兰
安特里姆和纽顿修道院 然后actionscript加载xml并创建一个名为setLists的函数,这是一个简单的循环来填充combobox,但现在我想暂停,所以应该是北爱尔兰(break)Antrim和Newtownabbey,然后是10 Then(break),依此类推。ActionScript代码:

function setLists():void
{
    var menuLength:int = xmlCodes.code.length();
    for (var i:int=0; i<menuLength; i++)
        {
            myVarList1.addItem({label:xmlCodes.code[i].text(), data:xmlCodes.code[i].@id});
            myVarList2.addItem({label:xmlCodes.code[i].text(), data:xmlCodes.code[i].@id});

            if (

        }
函数集合列表():void
{
var menuleLength:int=xmlCodes.code.length();

对于(var i:int=0;i如果标题下的元素数始终相同,请尝试以下操作:

function setLists():void
{
    var menuLength:int = xmlCodes.code.length();

    // I'm basing the "breaks" variable on this flow: title, break, 11 items, break, title, break, 26 items
    // 
    var breaks:int = 3;
    var breakCount:int = 0;
    // Note we've added "breaks" to our menuLength
    //
    for (var i:int=0; i<menuLength + breaks; i++)
        {
            // 1, 12, and 14 are where we add breaks based on the flow mentioned above
            //
            if (i == 1 || i == 12 || i == 14) {
                myVarList1.addItem({label:' ', data:null);
                myVarList2.addItem({label:' ', data:null);
                breakCount++;
            } else {
                myVarList1.addItem({label:xmlCodes.code[i-breakCount].text(), data:xmlCodes.code[i].@id});
                myVarList2.addItem({label:xmlCodes.code[i-breakCount].text(), data:xmlCodes.code[i].@id});
            }
        }
函数集合列表():void
{
var menuleLength:int=xmlCodes.code.length();
//我将“breaks”变量基于这个流:title,break,11项,break,title,break,26项
// 
var中断:int=3;
var-breakCount:int=0;
//注意,我们在菜单长度中添加了“中断”
//

对于(var i:int=0;i我假设“类别”及其“子类别”之间的
id
格式存在差异?此外,XML提供了一个具有以下模式的排序列表

  • 类别1
  • 孩子1
  • 孩子2
  • [……]
  • 孩子3
  • 类别2
  • 孩子1
  • 孩子2
  • [……]
  • 孩子3
如果是这样的话,你可以试着找出ID在“类别”和“子类别”之间的区别。一种方法是创建一个只匹配ID所属类别的ID,并在匹配时采取不同的行动

例如:

var categoryIdPattern:RegExp = /^\d{2,3}\w{2,3}$/; // Matches only strings consisting of 2-3 numbers followed by 2-3 word characters

var menuLength:int = xmlCodes.code.length();
for (var i:int = 0; i < menuLength; i++) {
    myVarList1.addItem({label:xmlCodes.code[i].text(), data:xmlCodes.code[i].@id});
    if (categoryIdPattern.exec(xmlCodes.code[i].@id as String) != null) {
        //This is a category, add an empty row beneath the newly added value in the combobox
        myVarList1.addItem({label:"", data:null});
    }
}
var categoryIdPattern:RegExp=//^\d{2,3}\w{2,3}$//;//只匹配由2-3个数字后跟2-3个单词字符组成的字符串
var menuleLength:int=xmlCodes.code.length();
对于(变量i:int=0;i

编辑:我应该补充一点,上面的代码没有经过测试,只是说明了这个概念。

我最后做的是创建一个新类来覆盖数据设置器,这样我就可以在组合框中将值设置为“disabled:true”

var myVarList1:ComboBox = new ComboBox();
var myVarList2:ComboBox = new ComboBox();
myVarList1.dropdown.setStyle("cellRenderer", MyCustomCellRenderer); 
myVarList2.dropdown.setStyle("cellRenderer", MyCustomCellRenderer); 
然后调用我的setlists函数

function setLists():void
    {
        var menuLength:int = xmlCodes.code.length();
        var breaks:int = 3;
        var breaksCount:int = 0;

    for (var i:int=0; i<menuLength; i++)
        {

            if(i == 1){

                myVarList1.addItem({label: " ", disabled:true});
                myVarList2.addItem({label: " ", disabled:true});                
                breaksCount++;
            }
                else if (i == 11){
                myVarList1.addItem({label: " ", disabled:true});
                myVarList2.addItem({label: " ", disabled:true});                    
                breaksCount++;
                }

            else {

            myVarList1.addItem({label:xmlCodes.code[i].text(), data:xmlCodes.code[i].@id});
            myVarList2.addItem({label:xmlCodes.code[i].text(), data:xmlCodes.code[i].@id});
            }
        }

所以我知道在正确的位置有中断,但是当你点击一个空标签时,它期望数据在那里,并使flash应用程序崩溃。有没有任何方法可以让它这样你就不能点击中断。还有为什么breaks变量设置为3?想不出一种方法来停止点击中断,但是如果你修改你的函数来检查要检查空值的选定项数据或您选择的其他自定义数据(如断路器或其他)并让它抛出一条错误消息,指示用户确保他们选择了一个实际选项。我以为您需要3次中断;一次在第一个标题之后,一次在下一个标题之前,一次在该标题之后。根据需要进行调整。啊,是的,很抱歉,愚蠢的一刻,但感谢您的帮助,最终使其工作非常感谢。
package { 
    import fl.controls.listClasses.CellRenderer; 
    public class MyCustomCellRenderer extends CellRenderer
    {
        // override the data setter to set the enabled flag
        override public function set data(value:Object):void
        {
            super.data = value;    
            this.enabled = !(value['disabled']);
        }
    } 
}