[flexcoders] ARGH shared object array -- getting data

2008-10-22 Thread grimmwerks
This is driving me nuts -- an onSync of a shared object where  
'history'  is an array -- I can the listing of the array, and I get  
the length of the arraly, but I can't get each object in the array --  
what am I doing wrong?!??



private function chatSync(event:SyncEvent):void{
var arr:Array = new Array();
arr = so_Chat.data.history;
Alert.show('array ' + arr);
var ln:Number = arr.length;
Alert.show(length:  + ln);
var ob:Object = arr[Number(ln)];
Alert.show(ob.message);
Alert.show('message  ' + arr[ln].message);
}





Re: [flexcoders] ARGH shared object array -- getting data

2008-10-22 Thread Paul Andrews
var ob:Object = arr[Number(ln)] should be var ob:Object = arr[ln-1] 

You don't need to cast the ln variable and arrays are indexed from 0 so the 
last value is at length -1.

paul
  - Original Message - 
  From: grimmwerks 
  To: flexcoders@yahoogroups.com 
  Sent: Thursday, October 23, 2008 12:38 AM
  Subject: [flexcoders] ARGH shared object array -- getting data


  This is driving me nuts -- an onSync of a shared object where 'history'  is 
an array -- I can the listing of the array, and I get the length of the arraly, 
but I can't get each object in the array -- what am I doing wrong?!??




  private function chatSync(event:SyncEvent):void{
  var arr:Array = new Array();
  arr = so_Chat.data.history;
  Alert.show('array ' + arr);
  var ln:Number = arr.length;
  Alert.show(length:  + ln);
  var ob:Object = arr[Number(ln)];
  Alert.show(ob.message);
  Alert.show('message  ' + arr[ln].message);
  }






   

RE: [flexcoders] ARGH shared object array -- getting data

2008-10-22 Thread Tracy Spratt
The .length of an array is always one grater than the last element
because arrays are zero based.  Try:

var ob:Object = arr[ln-1];  //returns the last element in the array

Tracy



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of grimmwerks
Sent: Wednesday, October 22, 2008 7:39 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] ARGH shared object array -- getting data

 

This is driving me nuts -- an onSync of a shared object where 'history'
is an array -- I can the listing of the array, and I get the length of
the arraly, but I can't get each object in the array -- what am I doing
wrong?!??

 

 

private function chatSync(event:SyncEvent):void{

var arr:Array = new Array();

arr = so_Chat.data.history;

Alert.show('array ' + arr);

var ln:Number = arr.length;

Alert.show(length:  + ln);

var ob:Object = arr[Number(ln)];

Alert.show(ob.message);

Alert.show('message  ' +
arr[ln].message);

}

 

 

 

 



Re: [flexcoders] ARGH shared object array -- getting data

2008-10-22 Thread Maciek Sakrejda
And if you think zero-based array indexing is crazy, consider Edsger
Dijkstra's short essay in favor of it:

http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html

-- 
Maciek Sakrejda
Truviso, Inc.
http://www.truviso.com

On Thu, 2008-10-23 at 00:50 +0100, Paul Andrews wrote:
 var ob:Object = arr[Number(ln)] should be var ob:Object = arr[ln-1] 
  
 You don't need to cast the ln variable and arrays are indexed from 0
 so the last value is at length -1.
  
 paul
 - Original Message - 
 From: grimmwerks 
 To: flexcoders@yahoogroups.com 
 Sent: Thursday, October 23, 2008 12:38 AM
 Subject: [flexcoders] ARGH shared object array -- getting data
 
 
 This is driving me nuts -- an onSync of a shared object where
 'history'  is an array -- I can the listing of the array, and
 I get the length of the arraly, but I can't get each object in
 the array -- what am I doing wrong?!?? 
 
 
 
 
 private function chatSync(event:SyncEvent):void{
 var arr:Array = new Array();
 arr = so_Chat.data.history;
 Alert.show('array ' + arr);
 var ln:Number = arr.length;
 Alert.show(length:  + ln);
 var ob:Object = arr[Number(ln)];
 Alert.show(ob.message);
 Alert.show('message  ' + arr[ln].message);
 }