Return-Path: Received: from mail-lb0-f177.google.com ([209.85.217.177] verified) by media-motion.tv (CommuniGate Pro SMTP 4.2.10) with ESMTP-TLS id 5451447 for AE-List@media-motion.tv; Wed, 23 Apr 2014 21:49:39 +0200 Received: by mail-lb0-f177.google.com with SMTP id z11so1186888lbi.36 for ; Wed, 23 Apr 2014 12:49:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=udr42O1xjN1WkApaTuiSOL3JGIR6QV6DsLxmRQbzRKo=; b=FiMBXsWtanB2r/8K4Tn0yQdcfAC9UYfbtmQ8g2NPKqB2/gYCFjXiiwmTnejUzNlE0h W0hSlrxETy9jMwQUMRe4okT4EiOyDIWWbMd7IALSpxBtmZIhrPqDOKQ1cemjSsi8cr5o ecynw18h7pKfFiE5djSIbb4Jt6441d8b9AGycRm7ZjgwCVX0lvAnzBY29HlK5iuSB+Tt KWktIRjb/HwCIGloZgOOSnyILEl7o2ZVF2Un4EodyrxJOmg0XTaxNZaLzcF8s/hPrOsy SvQUloMhEz5Ikc8k1Lcj1qmsBlPlQx/vrMDsFEXKiiRN0hEeR+bxdqKxr+xzqBQHfDlO sWvA== X-Gm-Message-State: ALoCoQlj3koNR3HF4cKo7/MhAFdk6SDFF27IQpyHFeRV/eo8p6lSzQisfYXztKwJsvy4YsHT8jZg MIME-Version: 1.0 X-Received: by 10.112.150.233 with SMTP id ul9mr33130621lbb.2.1398282578408; Wed, 23 Apr 2014 12:49:38 -0700 (PDT) Received: by 10.114.5.194 with HTTP; Wed, 23 Apr 2014 12:49:38 -0700 (PDT) In-Reply-To: References: Date: Wed, 23 Apr 2014 20:49:38 +0100 Message-ID: Subject: Re: [AE] Extendscript Question - Array length problem From: Phil Bearman To: After Effects Mail List Content-Type: multipart/alternative; boundary=047d7b342f6c61c7eb04f7bb08b7 --047d7b342f6c61c7eb04f7bb08b7 Content-Type: text/plain; charset=ISO-8859-1 Hi David, thanks for the reply. Yes, it's populating the array as expected. Here's a better example script. This is a simplified version of the actual script I'm using, but demonstrates the problem if you run it in ExtendScript Toolkit (it should pop up an alert box giving the length of the array but instead says ''undefined'). //~ Declare array (which will be populated with objects) var textLineObjectArray = {}; var textLine="Sample"; //~ Split string into array of characters var textLineArray = textLine.split(''); //~ Iterate through array and for each character, create an object for (var i = 0; i < textLineArray.length; i++){ //~ Add character name to object textLineObjectArray[i]={name:textLineArray[i]} } //~ output length of array of objects alert(textLine1ObjectArray.length); Can you see any problems with this? Phil -- *Phil Bearman* *Phil Bearman Creative Media Solutions* Motion Graphics Design *NEW! Video DJ Toolkit Volume 2 - Occasions: http://philbearman.co.uk/shop/vdj-toolkit-2/ * www.PhilBearman.co.uk : Nightclub & Bar ~ Production, Corporate & Events ~ DVD Products 0161 236 2581 - 9am-5pm, Monday-Friday This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this E-Mail. Please notify the sender immediately by E-Mail if you have received this E-Mail by mistake and delete the E-Mail from your system. E-Mail transmission cannot be guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain viruses. The sender therefore does not accept liability for any errors or omissions in the contents of this message or attached documents or for any damage suffered by your computer system caused by any errors or viruses contained in the E-Mail message or any attached documents. On 23 April 2014 18:39, David Torno wrote: > You should still be able to get the length of the array using length. > Object or item based. I would verify that the array keys (.width and > .height) are actually populated correctly within the array. I usually make > my object arrays a little different and more literal like this. Not that > it's right or wrong, just different option. > > for(var i=0; i myObjectAry.push({'width': ary.width, 'height': ary.height}); > } > > David Torno > Technical Director > http://www.ghosttownmedia.com > O: 213.739.2290 > C: 818.391.6060 > -------------------- > http://aeioweyou.blogspot.com > > "The most useless day is that in which we do not laugh" > -Charles Field > > On Apr 23, 2014, at 9:29 AM, Phil Bearman wrote: > > Hi all, > > I'm doing some scripting in AE, and need to iterate through an Array of > Objects, so need to find out the number of items in the array in order to > set up the loop. > > I had expected to be able to get the number of items using myArray.length, > but this gives an 'undefined' error in ExtendScript. > > The array has been populated with a loop in the following manner: > > for (var i=0; i < myWidthValues.length; i++) > { > myArray[i].width=myWidthValues[i]; > myArray[i].height=myHeightValues[i]; > } > > (this isn't the real code, just a simplified example) > > And the array is functioning as expected (so for example myArray[2].width > gives the result I expect). > > Is there a reason that an Array of Objects won't return a 'length' value? > > (I know this question would be better suited to a general javascript > forum, but I've trawled internet forums to no avail, and thought I'd ask > here first in case it's a quirk specific to ExtendScript). > > Any help much appreciated! > > Phil > > -- > > *Phil Bearman* > > *Phil Bearman Creative Media Solutions* > Motion Graphics Design > > www.PhilBearman.co.uk : Nightclub & Bar ~ Production, > Corporate & Events ~ DVD Products > > > > 0161 236 2581 - 9am-5pm, Monday-Friday > > > --047d7b342f6c61c7eb04f7bb08b7 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi David, thanks for the reply. =A0Yes, it's popu= lating the array as expected. =A0Here's a better example script. =A0Thi= s is a simplified version of the actual script I'm using, but demonstra= tes the problem if you run it in ExtendScript Toolkit (it should pop up an = alert box giving the length of the array but instead says ''undefin= ed').

//~ Declare array (which will be populated with objects= )=A0
var textLineObjectArray =3D {};

var= textLine=3D"Sample";
//~ Split string into array of ch= aracters
var textLineArray =3D textLine.split('');
//~ Iterat= e through array and for each character, create an object=A0
=A0fo= r (var i =3D 0; i < textLineArray.length; i++){
=A0 =A0 =A0//~= Add =A0character name to object
=A0 =A0 =A0 =A0 textLineObjectArray[i]=3D{name:textLineArray[i]}
=
=A0}
//~ output length of array of objects
alert(t= extLine1ObjectArray.length);

Can you see any probl= ems with this?

Phil

--

Ph= il Bearman

Phi= l Bearman Creative Media Solutions=20
Motion Graphics Design

NEW! = =A0Video DJ Toolkit Volume 2 - Occasions:=A0http://philbearman.co.uk/shop/v= dj-toolkit-2/

www.PhilBearman.co.uk = : Nightclub=20 & Bar ~ Production, Corporate=20 & Events ~ DVD Products=20

0161 236 2581 - 9am-5pm, Monday-Friday

This message=20 contains confidential information and is intended only for the individual= named.=20 If you are not the named addressee you should not disseminate, distribute= or=20 copy this E-Mail. Please notify the sender immediately by E-Mail if you h= ave=20 received this E-Mail by mistake and delete the E-Mail from your system. E= -Mail=20 transmission cannot be guaranteed to be secure or error-free as informati= on=20 could be intercepted, corrupted, lost, destroyed, arrive late or incomple= te,=20 or contain viruses. The sender therefore does not accept liability for an= y errors=20 or omissions in the contents of this message or attached documents or for= any=20 damage suffered by your computer system caused by any errors or viruses c= ontained=20 in the E-Mail message or any attached documents.



On 23 April 2014 18:39, David Torno <= torno@sydefxink.com> wrote:
You should still be able to get the length of the ar= ray using length. Object or item based. I would verify that the array keys = (.width and .height) are actually populated correctly within the array. I u= sually make my object arrays a little different and more literal like this.= Not that it's right or wrong, just different option.

for(var i=3D0; i<aryLen; i++){
=A0 =A0 =A0= myObjectAry.push({'width': ary.width, 'height': ary.height}= );
}

David Torno
Technical Director
--------------------=

"The most useless day is that in= which we do not laugh"
-Charles Field
<= div class=3D"h5">

On Apr 23, 2014, at 9:29 AM, Phil Bearman <phil@philbearman.c= o.uk> wrote:

Hi all,=A0
I'm doing some scripting in AE, and need to iterate throug= h an Array of Objects, so need to find out the number of items in the array= in order to set up the loop.

I had expected to be able to get the number of items using myArr= ay.length, but this gives an 'undefined' error in ExtendScript.

The array has been populated with a loop in the follo= wing manner:

for (var i=3D0; i < myWidthValues.length; i++)
=
{
myArray[i].width=3DmyWidthValues[i];
myArray[i].= height=3DmyHeightValues[i];
}

(this isn&= #39;t the real code, just a simplified example)

And the array is functioning as expected (so for exampl= e myArray[2].width gives the result I expect).

Is = there a reason that an Array of Objects won't return a 'length'= value?

(I know this question would be better suited to a gener= al javascript forum, but I've trawled internet forums to no avail, and = thought I'd ask here first in case it's a quirk specific to ExtendS= cript).

Any help much appreciated!

Phi= l

--

Ph= il Bearman

Phi= l Bearman Creative Media Solutions=20
Motion Graphics Design

www.PhilBearman.co.uk : Nightclub=20 & Bar ~ Production, C= orporate=20 & Events ~ DVD Product= s=A0


0161 236 2581 - 9am-5pm, Monday-Friday



--047d7b342f6c61c7eb04f7bb08b7--