0

我编写了以下自定义组件 SubNavBar.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" height="100" width="300"
 creationComplete="init()">

 <mx:Script>
  <![CDATA[
   import mx.collections.XMLListCollection;

   [Bindable] public var menuItems:XMLListCollection;

   private function init():void
   {
    trace("SubNav: config = "+menuItems);
   }


  ]]>
 </mx:Script>

 <mx:HBox y="30" id="menu">
  <mx:List dataProvider="{menuItems}"/>
 </mx:HBox>

</mx:Canvas>

我使用以下代码在父自定义组件中设置此组件:

<com:SubNavBar id="subNavMenu" menuItems="{subNavConfig}"
 x="10" y="-15">
</com:SubNavBar>

每当trace函数运行时init(),该属性menuItems就会返回null。我似乎对其他变量类型没有这个问题,比如布尔或字符串。这是由于 XMLListCollection 对象的大小造成的吗?如何使用 XMLListCollection 属性设置此 SubNavBar 自定义组件并将其绑定到组件中的控件?

谢谢!

4

2 回答 2

0

也许我遗漏了一些东西,但你在哪里设置 {subNavConfig} ?

编辑:

这可能是因为它是如何被铸造的......尝试类似......

var listcol:XMLListCollection = new XMLListCollection(configXML.destination.(@mapID == mapID).subSections);
于 2009-12-11T23:10:21.287 回答
0

我测试了这段代码,一切似乎都对我有用。您确定您正确设置了 subNavConfig 变量吗?

这是我使用的客户端代码:

// Test.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="onInit()" xmlns:ns="comp.*">
  <mx:Script>
    <![CDATA[
      import mx.collections.XMLListCollection;

      [Bindable]
      public var bookCollection:XMLListCollection;

      public function onInit():void
      {
        var books:XML = <books>
                          <book publisher="Addison-Wesley" name="Design Patterns" />
                          <book publisher="Addison-Wesley" name="The Pragmatic Programmer" />
                          <book publisher="Addison-Wesley" name="Test Driven Development" />
                          <book publisher="Addison-Wesley" name="Refactoring to Patterns" />
                          <book publisher="O'Reilly Media" name="The Cathedral & the Bazaar" />
                          <book publisher="O'Reilly Media" name="Unit Test Frameworks" />
                        </books>;

        var booklist:XMLList = books.book;
        bookCollection = new XMLListCollection(booklist);
      }
    ]]>
  </mx:Script>

  <ns:SubNavBar id="fb" menuItems="{bookCollection}"/>
</mx:Application>

这是我得到的输出:

SubNav: config = <book publisher="Addison-Wesley" name="Design Patterns"/>
<book publisher="Addison-Wesley" name="The Pragmatic Programmer"/>
<book publisher="Addison-Wesley" name="Test Driven Development"/>
<book publisher="Addison-Wesley" name="Refactoring to Patterns"/>
<book publisher="O'Reilly Media" name="The Cathedral &amp; the Bazaar"/>
<book publisher="O'Reilly Media" name="Unit Test Frameworks"/>
于 2009-12-12T00:03:58.377 回答