Problem with GetBodyList()

I just downloaded the new version of Box2DFlash 2.1a (for Flash 10) - from BorisTheBrave's new web site. Great work btw 🙂
I created a world, and populated it with 2 walls, a floor, a ceiling, and 2 rectangles (which have a MovieClip assoc. with them via userData).
The two rectangles are bouncing around, and they both have their userData properties set, and it all works fine so far.
All in all there are 7 objects.
I was trying to get a mousejoint working, and in preparation I decided to use BodyCount() and see what bodies were around. This is the code I am using…

private var bodyList:b2Body;//created with all my other vars at the beginning of my class

private function getBodyList(e:Event):void
{
bodyList = thisWorld.GetBodyList();
for(var i:uint = 0; i< bCount;i++)
{
list.text+="\n";
list.text+=(bodyList +" " + bodyList.GetUserData());
bodyList.GetNext();
}
}

The above function is triggered off a button I have within my stage.

Looking at the documentation, GetBodyList() should return a list of all the bodies (I was expecting 7 b2Body objects to be output). Using…

bCount = thisWorld.GetBodyCount();

…which i set in my class's constructor, after I created all my world objects. I also output this number to a text box on my stage and it comes back as 7.

But what I get is…

[object b2Body] null
[object b2Body] null
[object b2Body] null
[object b2Body] null
[object b2Body] null
[object b2Body] null
[object b2Body] null

This made me suspicious as two of my objects have the userData set, so I changed bCount in the for loop to an arbitrary number above 7 - and I basically get back [object b2Body] null x whatever number I looped for.

So, my question is this - is it me? have I done something dumb? or is GetNext() not working? And what am I actually returning then?

Any help would be greatly appreciated

Thanx
This:
Code:
bodyList.GetNext();


Should be:
Code:
bodyList = bodyList.GetNext();


Also a better way to iterate over bodies is:
Code:
private function getBodyList(e:Event):void
{
for(var body:b2Body = thisWorld.GetBodyList(); body; body = body.GetNext())
{
list.text+="\n";
list.text+=(body +" " + body.GetUserData());
}
}


Hope this helps.
Thanx Wahooney, that worked perfectly!

regards

alex

Original thread: https://box2d.org/forum/viewtopic.php?t=4302