Java ArrayList in AS extension

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
crickeys
Posts: 16
Joined: 29 May 2008, 17:23

Java ArrayList in AS extension

Post by crickeys »

I'm using a java ArrayList in an AS2 Extension (For those who don't know, yes you can do this). The instantiation for the arraylist is as follows:

Code: Select all

 var myList = new java.util.ArrayList();

Into the list I am putting userIDs as follows:

Code: Select all

myList .add(new java.lang.Integer(userID));

If I later loop through the list with the following code:

Code: Select all

for (var it = myList.iterator(); it.hasNext();)
{

		userID= it.next();
		
		// get the user
		tUser = _server.getUserById(userID);
}
then I get this error:

error in extension [ myExt.as ]: Wrapped java.lang.ClassCastException (roomSpill.as#507) Internal: -976 -- Line number: (MainLib line: 507)

I believe the error occurs at the _server.getUserById(userID); function. Why is this occurring? What am I missing?

Thanks,

Brian
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

probably it's no biggie, try to avoid this:

Code: Select all

myList .add(new java.lang.Integer(userID)); 
and use the number itself:

Code: Select all

myList .add(userID);
btw... is there a specific reason for not using a regular AS list?
Lapo
--
gotoAndPlay()
...addicted to flash games
crickeys
Posts: 16
Joined: 29 May 2008, 17:23

Post by crickeys »

Thanks Lapo! Sorry for my delay in response.

I am actually trying to solve the following problem:

I have a game in which people can form GROUPS and FOLLOW each other. So, if one the leader moves, then anyone following will go to the same place.

I was concerned about the speed and efficiency of the Actionscript Array vs java's ArrayLists, HashMap, etc. I wanted to ensure that if we get a large number of groups and need to update them quickly, search them, etc. this would not become a bottleneck.

Maybe there's a better way that I'm not seeing?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

I was concerned about the speed and efficiency of the Actionscript Array vs java's ArrayLists, HashMap, etc.
If you are concerned with performance I'd suggest to user Java instead of Actionscript. The performance gain is huge. Only using the Java collections in Actionscript won't do that much, although it might help
Lapo
--
gotoAndPlay()
...addicted to flash games
Post Reply