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


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.