Re: [Flashcoders] E4X question: counting number of subnodes

2010-08-26 Thread Alexander Farber
Hello fellow flashcoders,

I'm still struggling with my e4x problem. With Kenneth's
help I've got it partly working for the cases
where each game has at least 1 user node:

  var games:XML =
   games

 game
   user/
   user/
   user/
 /game

 game
   user/
   user/
 /game

 game
   user/
   user/
 /game

   /games;

  trace(All games:  + games.game.length());
  trace(Full games:  + games.game.user.(length() == 3).length());
  trace(Vacant games:  + games.game.user.(length()  3).length());

This works well. But once I have a game with no user's,
i.e. game/game or just game/ it fails with runtime error:

  ReferenceError: Error #1065: Variable user is not defined.

I know, that when using e4x you're first supposed to test
for a game.user.length()!=0 before referencing a user node.

But how do you do it in this case, when I'm trying to count total numbers?

Thank you
Alex
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] E4X question: counting number of subnodes

2010-08-26 Thread Kenneth Kawamoto
You can use elements() (and attributes()) to avoid getting the 
error, i.e.


trace(Full games:  + games.game.(elements(user).length() == 
3).length());


Kenneth Kawamoto
http://www.materiaprima.co.uk/

On 26/08/2010 11:00, Alexander Farber wrote:

Hello fellow flashcoders,

I'm still struggling with my e4x problem. With Kenneth's
help I've got it partly working for the cases
where each game has at least 1 user node:

   var games:XML =
games

  game
user/
user/
user/
  /game

  game
user/
user/
  /game

  game
user/
user/
  /game

/games;

   trace(All games:  + games.game.length());
   trace(Full games:  + games.game.user.(length() == 3).length());
   trace(Vacant games:  + games.game.user.(length()  3).length());

This works well. But once I have a game with no user's,
i.e.game/game  or justgame/  it fails with runtime error:

   ReferenceError: Error #1065: Variable user is not defined.

I know, that when using e4x you're first supposed to test
for a game.user.length()!=0 before referencing a user node.

But how do you do it in this case, when I'm trying to count total numbers?

Thank you
Alex

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] E4X question: counting number of subnodes

2010-08-26 Thread Kenneth Kawamoto
I meant attribute() - attribute() and attributes() are quite different 
things ;)


Kenneth Kawamoto
http://www.materiaprima.co.uk/

On 26/08/2010 11:41, Kenneth Kawamoto wrote:

You can use elements() (and attributes()) to avoid getting the
error, i.e.

trace(Full games:  + games.game.(elements(user).length() ==
3).length());

Kenneth Kawamoto
http://www.materiaprima.co.uk/

On 26/08/2010 11:00, Alexander Farber wrote:

Hello fellow flashcoders,

I'm still struggling with my e4x problem. With Kenneth's
help I've got it partly working for the cases
where each game has at least 1 user node:

var games:XML =
games

game
user/
user/
user/
/game

game
user/
user/
/game

game
user/
user/
/game

/games;

trace(All games:  + games.game.length());
trace(Full games:  + games.game.user.(length() == 3).length());
trace(Vacant games:  + games.game.user.(length() 3).length());

This works well. But once I have a game with no user's,
i.e.game/game or justgame/ it fails with runtime error:

ReferenceError: Error #1065: Variable user is not defined.

I know, that when using e4x you're first supposed to test
for a game.user.length()!=0 before referencing a user node.

But how do you do it in this case, when I'm trying to count total
numbers?

Thank you
Alex

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] E4X question: counting number of subnodes

2010-08-26 Thread Alexander Farber
Thank you for the pointers, I'll read up on child() and
attribute() - I've missed them in the docs somehow
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] E4X question: counting number of subnodes

2010-08-23 Thread Alexander Farber
Hello Kenneth and others,

On Thu, Aug 19, 2010 at 9:05 PM, Kenneth Kawamoto
kennethkawam...@gmail.com wrote:
 trace(Full games:  + games.game.(user.length() == 3).length());
 trace(Vacant games:  + games.game.(user.length()  3).length());

thank you - now my Flash code is working,
but my Flex code is still not working and
I've already spent several days on it. Here is
the test case (a copy and screenshot are at
http://stackoverflow.com/questions/3517298/flex-listening-for-collectionevent-in-custom-component
)

Games.mxml (my component, trying to use e4x):

?xml version=1.0 encoding=utf-8?
mx:VBox xmlns:mx=http://www.adobe.com/2006/mxml; xmlns:my=*

mx:Script
![CDATA[
private var _xlist:XMLList;

public function get xlist():XMLList {
return _xlist;
}

public function set xlist(x:XMLList):void {
_xlist = x;
trace(111:  + _xlist.toString());
trace(222:  + _xlist.game.toString());
list.dataProvider = x;
all.text = All games:  + _xlist.game.length();
full.text = Full games:  + 
_xlist.game.(user.length() == 3).length();
vacant.text = Vacant games:  + 
_xlist.game.(user.length()  3).length();
}

private function gameLabel(item:Object):String {
return game:  + it...@label;
}
]]
/mx:Script

mx:Label id=all text=All games/
mx:Label id=full text=Full games/
mx:Label id=vacant text=Vacant games/

mx:List id=list labelFunction=gameLabel/

/mx:VBox

MyTest.mxml:

?xml version=1.0 encoding=utf-8?
mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; xmlns:my=*
mx:Script
![CDATA[
import mx.events.*;

private function changeXML1():void {
games = games
game label=1
user/
user/
user/
/game
game label=2
user/
user/
/game
game label=3
user/
user/
user/
/game
/games;   

}

private function changeXML2():void {
games = games
game label=A
user/
user/
user/
/game
game label=B
user/
user/
/game
game label=C
/game
/games;   

}
]]
/mx:Script

mx:XML id=games
games
game label=X
user/
user/
/game
game label=Y
user/
user/
/game
/games
/mx:XML

mx:Button label=Change XML 1 click=changeXML1()/
mx:Button label=Change XML 2 click=changeXML2()/
my:Games xlist={games.game}/
/mx:Application

It prints empty list for the 

[Flashcoders] E4X question: counting number of subnodes

2010-08-19 Thread Alexander Farber
Hello,

my server delivers XML data over socket,
representing games, with up to 3 players in each.

In my custom component I'd like to display
a summary: total number of games,
number of full games (3 players)
number of vacant games (joinable, because less than 3 players).

I've prepared a reduced test case demonstrating my problem:

var games:XML =
  games
game
  user/
  user/
  user/
/game
game
  user/
  user/
/game
game
  user/
  user/
/game
  /games;

trace(All games:  + games.game.length());
trace(Full games:  + games.game.user.(length() == 3).length());
trace(Vacant games:  + games.game.user.(length()  3).length());

It prints wrong results for the 2 last calculations:

All games: 3
Full games: 0
Vacant games: 7

And a warning:

Warning: 1060: Migration issue: The method length is no longer
supported.  Use the length property of the argument instead..

Please advise me
Alex
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] E4X question: counting number of subnodes

2010-08-19 Thread Glen Pike

Hi,

   I am not sure you can count the sub-nodes without having some sort 
of differentiator between parent nodes.
  
   You might have to loop through the list of games to find how many 
users are in each one as your tests for 2  3 are returning the total 
number of user nodes in the tree.


   You can test your e4x stuff quite nicely here:

   http://www.linkwerk.com/pub/javascript/e4x/e4x-tester/

   Glen

Alexander Farber wrote:

Hello,

my server delivers XML data over socket,
representing games, with up to 3 players in each.

In my custom component I'd like to display
a summary: total number of games,
number of full games (3 players)
number of vacant games (joinable, because less than 3 players).

I've prepared a reduced test case demonstrating my problem:

var games:XML =
  games
game
  user/
  user/
  user/
/game
game
  user/
  user/
/game
game
  user/
  user/
/game
  /games;

trace(All games:  + games.game.length());
trace(Full games:  + games.game.user.(length() == 3).length());
trace(Vacant games:  + games.game.user.(length()  3).length());

It prints wrong results for the 2 last calculations:

All games: 3
Full games: 0
Vacant games: 7

And a warning:

Warning: 1060: Migration issue: The method length is no longer
supported.  Use the length property of the argument instead..

Please advise me
Alex
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

  

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] E4X question: counting number of subnodes

2010-08-19 Thread Nathan Mynarcik
Yeah you should add attributes to your game nodes to seperate them:

var games:XML =
 games
   game id=1
 user/
 user/
 user/
   /game
   game id=2
 user/
 user/
   /game
   game id=3
 user/
 user/
   /game
 /games;

then you can use E4X to find the actually amount of users in each game:

**Pseudo Code**
games.game(@id == 1).user.length();

Nathan Mynarcik
nat...@mynarcik.com
254.749.2525
www.mynarcik.com


On Thu, Aug 19, 2010 at 1:18 PM, Glen Pike postmas...@glenpike.co.ukwrote:

 Hi,

   I am not sure you can count the sub-nodes without having some sort of
 differentiator between parent nodes.
 You might have to loop through the list of games to find how many users
 are in each one as your tests for 2  3 are returning the total number of
 user nodes in the tree.

   You can test your e4x stuff quite nicely here:

   http://www.linkwerk.com/pub/javascript/e4x/e4x-tester/

   Glen


 Alexander Farber wrote:

 Hello,

 my server delivers XML data over socket,
 representing games, with up to 3 players in each.

 In my custom component I'd like to display
 a summary: total number of games,
 number of full games (3 players)
 number of vacant games (joinable, because less than 3 players).

 I've prepared a reduced test case demonstrating my problem:

 var games:XML =
  games
game
  user/
  user/
  user/
/game
game
  user/
  user/
/game
game
  user/
  user/
/game
  /games;

 trace(All games:  + games.game.length());
 trace(Full games:  + games.game.user.(length() == 3).length());
 trace(Vacant games:  + games.game.user.(length()  3).length());

 It prints wrong results for the 2 last calculations:

 All games: 3
 Full games: 0
 Vacant games: 7

 And a warning:

 Warning: 1060: Migration issue: The method length is no longer
 supported.  Use the length property of the argument instead..

 Please advise me
 Alex
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders



 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] E4X question: counting number of subnodes

2010-08-19 Thread Kenneth Kawamoto

May be this is what you after?

trace(Full games:  + games.game.(user.length() == 3).length());
trace(Vacant games:  + games.game.(user.length()  3).length());

// Trace
Full games: 1
Vacant games: 2

Kenneth Kawamoto
http://www.materiaprima.co.uk/

Alexander Farber wrote:

Hello,

my server delivers XML data over socket,
representing games, with up to 3 players in each.

In my custom component I'd like to display
a summary: total number of games,
number of full games (3 players)
number of vacant games (joinable, because less than 3 players).

I've prepared a reduced test case demonstrating my problem:

var games:XML =
  games
game
  user/
  user/
  user/
/game
game
  user/
  user/
/game
game
  user/
  user/
/game
  /games;

trace(All games:  + games.game.length());
trace(Full games:  + games.game.user.(length() == 3).length());
trace(Vacant games:  + games.game.user.(length()  3).length());

It prints wrong results for the 2 last calculations:

All games: 3
Full games: 0
Vacant games: 7

And a warning:

Warning: 1060: Migration issue: The method length is no longer
supported.  Use the length property of the argument instead..

Please advise me
Alex

___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders