syntax error: expecting rightparen before colon, don't know why?

why do I get the error: syntax error: expecting rightparen before colon on line 7???

var myXML:XML=new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(succes:Boolean):void{
    var colors:XML = this.firstChild;
    for (x=0;x<colors.childNodes.length;x++){
        var node:XMLNode = colors.childNodes[x];
        colors_cb.addItem{(label:node.attributes.label,data:node.attributes.data)};

    }
}
myXML.load("colors.xml");

Answers


you inverted { and ( in your function call addItem try:

colors_cb.addItem({label:node.attributes.label,data:node.attributes.data});

it seems you are using ActionScript2 methods for XML class. Try this:

// create a loader for your XML
var xmlLoader:URLLoader = new URLLoader();
// Lister for complete event
xmlLoader.addEventListener( Event.COMPLETE, _onLoadComplete );
// start loading
xmlLoader.load( 'colors.xml' );

// handle complete loading
function _onLoadComplete( e:Event ):void
{
    // remove event listener
    xmlLoader.removeEventListener( Event.COMPLETE, _onLoadComplete );
    // set XML to ignore white spaces
    XML.ignoreWhitespace = true;
    // create XML with the loaded data
    var colors:XML = new XML( e.target.data );

    // add your items to your color_cb
    for (var x:int=0; x<colors.childNodes.length; x++ )
    {
        var node:XMLNode = colors.childNodes[x];
        color_cb.addItem({label:node.attributes.label,data:node.attributes.data});
    }
}

Need Your Help

How to save a QStandardItemModel?

model-view-controller qt

I'm currently writing an application that plays podcasts. I'm representing all the feeds and the episodes within them as QStandardItem objects within a QStandardItemModel. Right now, I don't have a...

insert using custom api with azure services using swift

ios swift azure-mobile-services

I am new to Swift language. I am trying to use custom API to Azure service. I am not sure how to return the result back.