The problem I think is you're using the wrong data structures. If your Java map looks like this:
HashMap<int, String> myMap; What you'll get in Flex isn't what you've got below, it's an object like this: var mymap : Object = { 1: "String 1", 2: "String 2", 79: "Blue" } Not the structure that you're trying to coerce it to based on the code you posted. But since this is clearly just "example" Flex code and I have no idea about what your Java looks like, I'm just guessing. -Josh On Tue, Sep 9, 2008 at 8:46 AM, dmiramontesval <[EMAIL PROTECTED]>wrote: > I have this weird issue and i can't figure it out, let me explain: > > I have a java object A which has a HashMap variable myMap, this map > will hold objects of class B. In ActionScript i have the corresponding > class A which has a variable myMap but since there is no HashMap in > ActionScript its type is Object and i also have the corresponding class B. > > [RemoteClass(alias="com.test.A")] > public class A { > public var myMap:Object; // this is the HashMap in Java > } > > [RemoteClass(alias="com.test.B")] > public class B { > public var id:Number; > public var name:String; > } > > I need to put the objects B contained in the map inside a DataGrid so > i am obtaining the object of class A using a RemoteObject and then i > iterate over the myMap property using a for each in loop, like this: > > for each(var i:* in objectA.myMap) { > someArrayCollection.add(i); > } > > The first issue appears here, suppose the java HashMap contains 3 > elements, in the ActionScript loop i get 4 elements, the fourth one > being a reference to the A object (its key appears as "owner"). In > order to avoid this i use the "is" operator like this: > > for each(var i:* in objectA.myMap) { > if (i is B) { > someArrayCollection.add(i); > } > } > > Now here is the real issue, when i do this the B objects contained in > the myMap property are reset to their initial values (NaN and empty > string according to the B class). I changed the if condition to this > and worked: > > for each(var i:* in objectA.myMap) { > if (!(i is A)) { > someArrayCollection.add(i); > } > } > When i did this the DataGrid shows the elements in the > someArrayCollection perfectly fine. I did a little more testing and i > "figured" out the issue, if i use an instance of class B anywhere in > my application, the values of the B objects inside the myMap property > are reset, for example: > > for each(var i:* in objectA.myMap) { > if (i is B) { > someArrayCollection.add(i); > } > } > var test:B = new B(); > > This resets the B objects inside the myMap property of the A object > which makes no absolute sense, this is why when i used the B class in > the if condition the objects reset their values. > > So the thing is whenever i use the B class, which is the class of the > objects inside myMap, the B objects are reset!!!! Does anyone know how > to fix this????? > > I am using Flex 2.01 hotfix 3, i wonder if this is some kind of bug > that was solved in a later release. > > Any help would be appreciated. > > > ------------------------------------ > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Search Archives: > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups > Links > > > > -- "Therefore, send not to know For whom the bell tolls. It tolls for thee." http://flex.joshmcdonald.info/ :: Josh 'G-Funk' McDonald :: 0437 221 380 :: [EMAIL PROTECTED]