Title: problem with arrays
temp_arr is a pointer so all you're doing is assigning the same pointer to every index in testArray and simply incrementing the values with each iteration of the first look.  Try declaring temp_arr within the loop.
 

Carson

____________________________________________
 
Carson Hager
Cynergy Systems, Inc.
http://www.cynergysystems.com

 
Email:  [EMAIL PROTECTED]
Office:  866-CYNERGY
Mobile: 1.703.489.6466

 
 

 


From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Parekh, Shweta - BLS CTR
Sent: Wednesday, November 23, 2005 1:07 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] problem with arrays

Hi,

I have a piece of code like the following:

                var testArray:Array = new Array();
                var temp_arr:Array = new Array(2);             
       
                for(var num:Number = 0; num < 3; num++)
                {
                        temp_arr[0] = num; temp_arr[1] = num+5;
                        testArray.addItemAt(num, temp_arr);                    
                }
               
                trace("testArray ***");
                for(var i:Number = 0; i < testArray.length; i++)
                {              
                        trace(testArray[i]);
                }      

I am expecting it to print
0 5
1 6
2 7

instead the it prints out
2 7
2 7
2 7

Can anybody tell me why??? How can I fix it?

Thanks,
Shweta





--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to