Return-Path: Received: from homiemail-a100.g.dreamhost.com ([69.163.253.7] verified) by media-motion.tv (CommuniGate Pro SMTP 4.2.10) with ESMTP id 5451463 for AE-List@media-motion.tv; Wed, 23 Apr 2014 22:11:51 +0200 Received: from homiemail-a100.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a100.g.dreamhost.com (Postfix) with ESMTP id E5D1131A07D for ; Wed, 23 Apr 2014 13:11:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=aescripts.com; h= mime-version:in-reply-to:references:from:date:message-id:subject :to:content-type; s=aescripts.com; bh=tJ/1AFyDjd9dYqr5N2Rxe0rKIm c=; b=v6TEWlwtxYTSrzbA0Es6wLnK/FcikBZhW8bXlLHAaYZ9+UeWi6/MK+dk+Z 9oA2x3gJ+044SxPQIHR0uWt4gZNJdi6k8denAtd8i2x6B88U+uDHuNSFd11HA0/K hmDCxE9mtL6lSlcnBfTakT/aDBCXf4Fw5iOLmMLTsrWi+ioic= Received: from mail-vc0-f176.google.com (mail-vc0-f176.google.com [209.85.220.176]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: lists@aescripts.com) by homiemail-a100.g.dreamhost.com (Postfix) with ESMTPSA id A12BC31A078 for ; Wed, 23 Apr 2014 13:11:49 -0700 (PDT) Received: by mail-vc0-f176.google.com with SMTP id lc6so1768289vcb.7 for ; Wed, 23 Apr 2014 13:11:49 -0700 (PDT) X-Received: by 10.58.38.166 with SMTP id h6mr14975634vek.22.1398283909106; Wed, 23 Apr 2014 13:11:49 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.193.7 with HTTP; Wed, 23 Apr 2014 13:11:09 -0700 (PDT) In-Reply-To: References: From: Lloyd Alvarez Date: Wed, 23 Apr 2014 16:11:09 -0400 Message-ID: Subject: Re: [AE] Extendscript Question - Array length problem To: After Effects Mail List Content-Type: multipart/alternative; boundary=089e013a0d40b2967b04f7bb57a3 --089e013a0d40b2967b04f7bb57a3 Content-Type: text/plain; charset=UTF-8 You are confusing arrays with objects which are different things in Javascript. Objects do not have a length property which is why you are having issues. To loop through an object you use a different for loop: for (var prop in obj) { alert(prop + " = " + obj[prop]); } http://stackoverflow.com/questions/921789/how-to-loop-through-javascript-object-literal-with-objects-as-members Cheers, Lloyd On Wed, Apr 23, 2014 at 3:49 PM, Phil Bearman wrote: > 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 >> >> >> > --089e013a0d40b2967b04f7bb57a3 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
You are confusing arrays with objects which are different = things in Javascript. =C2=A0Objects do not have a length property which is = why you are having issues. =C2=A0To loop through an object you use a differ= ent for loop:

for (var prop in obj) {
=C2=A0 alert(prop + " =3D " = + obj[prop]);
}


Cheers,
Lloyd


On Wed, Apr 23, 2014 at 3:49 PM, Phil Be= arman <phil@philbearman.co.uk> wrote:
Hi David, thanks for the reply. =C2=A0Yes, it's p= opulating the array as expected. =C2=A0Here's a better example script. = =C2=A0This is a simplified version of the actual script I'm using, but = demonstrates the problem if you run it in ExtendScript Toolkit (it should p= op up an alert box giving the length of the array but instead says '= 9;undefined').

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

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

Can yo= u see any problems with this?

Phil

--

Ph= il Bearman

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

N= EW! =C2=A0Video DJ Toolkit Volume 2 - Occasions:=C2=A0http://philbearman.co= .uk/shop/vdj-toolkit-2/

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++){
=C2=A0 =C2= =A0 =C2=A0myObjectAry.push({'width': ary.width, 'height': a= ry.height});
}

David Torno
Technical Director
http://www.gh= osttownmedia.com
--------------------=

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

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

Hi all,=C2=A0
I'm doing some scripting in AE, and need to iterate thr= ough an Array of Objects, so need to find out the number of items in the ar= ray 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=C2=A0


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




--089e013a0d40b2967b04f7bb57a3--