Ummmmm actually my example is wrong, i was missing something, let me explain again:
I have 3 classes as a matter of fact, classes A and B are correct but i forgot to mention that inside B there is an object C: [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 testVar1:Number; public var testVar2:String; } A objectA = new A(); objectA.myMap = new HashMap(); B objectB1 = new B(); C objectC1 = new C(); objectB1.id = 1; objectB1.name = "Test"; objectC1.testVar1 = 2; objectC1.testVar2 = "Hello"; objectB1.myC = objectC1; myMap.put("key1", objectB1); Now here is the deal, the only property being reset is the C object, the id and name properties are not reset for each(var i:* in objectA.myMap) { if (i is B) { trace(i.id + " " + i.name); trace(i.myC.testVar1 + " " + i.myC.testVar2); } } The first trace works fine, but the second trace shows NaN and empty string. If i change the code to: for each(var i:* in objectA.myMap) { if (!(i is A)) { trace(i.id + " " + i.name); trace(i.myC.testVar1 + " " + i.myC.testVar2); } } Both traces work fine, prints 1 Test and 2 Hello. Like you said i have some logic inside the B constructor: public function B() { myC = new C(); } I commented the constructor and instead of getting the values reset i got an error saying i tried to access a null reference, since C is null (if i don't use an instance of B then it works fine). So i am kinda back where i started, when i use the B class the C object inside each B object is reset. --- In flexcoders@yahoogroups.com, "Josh McDonald" <[EMAIL PROTECTED]> wrote: > > Right, I see. I suppose you may be doing something funky in the constructor > for your actual impl of A or B. Try commenting out the constructor and see > if you have the same problem. > > -Josh > > On Tue, Sep 9, 2008 at 9:17 AM, dmiramontesval > <[EMAIL PROTECTED]>wrote: > > > They keys in the Java map are Strings and the values are B objects, > > you could say it is HashMap<String, B>. > > So suppose in Java i do this: > > > > A objectA = new A(); > > objectA.myMap = new HashMap(); > > B objectB1 = new B(); > > objectB1.id = 1; > > objectB1.name = "Test"; > > myMap.put("key1", objectB1); > > > > In Flex if i iterate over the myMap property: > > > > for each(var i:* in objectA.myMap) { > > if (i is B) { > > trace(i.id + " " + i.name); > > } > > } > > > > Doing this resets the B object inside myMap, so the trace prints NaN > > and empty string. > > > > If i dont use an instance of B: > > > > for each(var i:* in objectA.myMap) { > > if (!(i is A)) { > > trace(i.id + " " + i.name); > > } > > } > > > > The trace prints 1 Test. > > > > The main issue is that if i create an instance of B anywhere in my > > code, the B object inside myMap resets. > > > > The second issue is that inside the myMap property there are two > > objects instead of just one, this additional object is a reference to > > A and its key is "owner", so the myMap property looks like: > > > > var myMap:Object = {owner:the A object, key1: the B object}; > > > > > > I have no idea where this reference to the A object comes from, but i > > can live with that, the main issue is that i can't use the B class > > because if i do the B objects inside the map are reset. > > > > > > --- In flexcoders@yahoogroups.com, "Josh McDonald" <dznuts@> wrote: > > > > > > 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 > > > <dmiramontesval@>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 :: josh@ > > > > > > > > > > > ------------------------------------ > > > > -- > > 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] >