开发者

Putting an XML query inside a drop down list control

I have this project for school where i have to populate a drop down list control from an xml file. I mange to do that for a label/text input control, but i can't seem to do that on a drop down. I get this error any time i tell him 开发者_如何学编程to "additem" with an xml query (not getting it with simple text): "#1009 Cannot access a property or method of a null object reference"

This is the function that getting the xml file:

private function myFunc(event:ResultEvent):void
{
   myXml=event.result as XML;
}

This is the function that launch after the control got build:

protected function ActivityDropDown_creationCompleteHandler(event:FlexEvent):void
{

    droplistdb=new ArrayList();
    ActivityDropDown.dataProvider=droplistdb;
    droplistdb.addItem({label:myXml.Activity.(attribute("publish")=="true").ActivityName});
} 


Here are a couple tweaks that should make debugging this a bit easier.

First don't create a new ArrayList just for the DropDown's dataprovider. Just set the XMLList of Actitivies as the dataProvider and use a labelFunction to grab the ActivityName out of the XML.

Here's your debug labelFunction:

//set a breakpoint on each line
function(obj:XML):String{
  var activityName:XML = obj.ActivityName;
  return activityName.toString();
}

If you don't get to the label function then this E4X query is wrong -> myXml.Activity.(attribute("publish")=="true"). You'll want to break that down piece by piece. Try to get a proper XMLList out of myXml.Activity nodes?

trace(myXml.Activity.length());//should show the number of Activity nodes

Try that out and let us know how it turns out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜