Hello,

I have 2 problems with my custom component (code below), which works ok 
otherwise. It represents a list of games, with up to 3 players. I feed it with 
XML data being pulled from server:

<game id="42">
  <user .....>
  <user .....>
  <user .....>
</game>
<game id="47">
  <user .....>
</game>
<game id="56">
</game>

I'd like to display summary at the top of my component - how many games are 
there in total, how many are full (with 3 users) and how many are vacant aka 
free (less than 3 users). Unfortunately:

1) the CollectionEvent is not fired for some reason. I have to call 
xlistChanged(null) - to at least test the 2)

2) When I call xlistChanged(null), the _full and _free are calculated wrong and 
both contain the string "Full/Free 0". I probably call e4x in a wrong way?

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"; 
  width="100%" height="100%" xmlns:my="*" 
  verticalScrollPolicy="off" horizontalScrollPolicy="off">

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

    [Bindable]
    private var _xlist:XMLListCollection;

    public function set xlist(x:XMLList):void {
        _xlist = new XMLListCollection(x);
        _xlist.addEventListener(CollectionEvent.COLLECTION_CHANGE, 
xlistChanged);

        xlistChanged(null);
    }

    private function xlistChanged(event:CollectionEvent):void {
        _all.label = 'All (' + _xlist.length + ')';

        var full:XMLList = _xlist.source.game.(user.length() == 3);
        _full.label = 'Full (' + full.length() + ')';

        var free:XMLList = _xlist.source.game.(user.length() < 3);
        _free.label = 'Free (' + free.length() + ')';
    }
    ]]>
    </mx:Script>

    <mx:HBox width="100%">
      <mx:Label text="Playing tables:"/>
      <mx:RadioButton groupName="_type" id="_free"/>
      <mx:RadioButton groupName="_type" id="_full"/>
      <mx:RadioButton groupName="_type" id="_all"/>
    </mx:HBox>
    <mx:List width="100%" height="100%" 
      dataProvider="{_xlist}" itemRenderer="Game"/>
</mx:VBox>

Thank you
Alex


Reply via email to