Expand my Community achievements bar.

Issue when converting java.util.HashMap into an ActionScript Object

Avatar

Level 2
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. Inside B there is an
instance of C class. 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
classes B and C.



[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;

public var myC:C

}



[RemoteClass(alias="com.test.C")]

public class C {

public var myId:Number;

public var myName:String;

}



I need to put the C objects of each B object of 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.myC);

}



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. 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.myC);

}

}



Now here is the real issue, when i do this the C objects
contained in the B objects of the myMap property are reset to their
initial values (myId is NaN and myName is empty string according to
the C class). I changed the if condition to this and worked:



for each(var i:* in objectA.myMap) {

if (!(i is A)) {

someArrayCollection.add(i.myC);

}

}

When i did this the DataGrid shows the values of the C
objects (myId and myName) 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 C object are
reset, for example:



for each(var i:* in objectA.myMap) {

if (i is B) {

someArrayCollection.add(i.myC);

}

}

var test:B = new B();



This resets the C object (myId and myName) of each B object
contained in the map of the A object which makes no absolute sense.



So the thing is whenever i use the B class, which is the
class of the objects inside myMap, the C 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.
0 Replies