Return-Path: Received: from mail-la0-f42.google.com ([209.85.215.42] verified) by media-motion.tv (CommuniGate Pro SMTP 4.2.10) with ESMTP-TLS id 5451689 for AE-List@media-motion.tv; Thu, 24 Apr 2014 10:14:32 +0200 Received: by mail-la0-f42.google.com with SMTP id mc6so556586lab.15 for ; Thu, 24 Apr 2014 01:14:32 -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=3BzPnWcbrT6VehxeGyxgFRteXsLyYc6BI21TdOmd0lA=; b=mk18Mw+RrK476DJwXiBAtP2g0KHbwbGZ0qxCY1pZAiQUIl5SAn4iBW38nrSUb9UaGz bDh0Ny9hKj9CEPrKuvsml6h1veXWw0AedGjHqwzXd8bNVLUvkbMSOPtE1RzH8qhkuqps Wg+a71f423Pwn0ESiowpA//DAyaWwevi5DAS97W6HPocPXM1YwcuDEmSzxBc1NFVStU8 74bl363srcd0tIx30DHX7HRZCxusxpbRQMwhaG4XqkfsVBSowM3VQo1+5kJGS2CjZa/m M3uUNSiMrC9P9Aux6excoq2zU2rSSpvc0JCugRJajWyJKQGM0OmQmXYxwyFCr1F/18iZ KPuA== X-Gm-Message-State: ALoCoQmEE2GRzJU70tMqXla7T2rILRXCkh9/7soagU9RynrNWAbAsKSOg4CBYcv3BpkiAtf1e5Cs MIME-Version: 1.0 X-Received: by 10.152.18.170 with SMTP id x10mr176173lad.55.1398327271830; Thu, 24 Apr 2014 01:14:31 -0700 (PDT) Received: by 10.114.5.194 with HTTP; Thu, 24 Apr 2014 01:14:31 -0700 (PDT) In-Reply-To: References: Date: Thu, 24 Apr 2014 09:14:31 +0100 Message-ID: Subject: Re: [AE] Extendscript Question - Array length problem From: Phil Bearman To: After Effects Mail List Content-Type: multipart/alternative; boundary=089e01493d9e514a3f04f7c570fa --089e01493d9e514a3f04f7c570fa Content-Type: text/plain; charset=ISO-8859-1 Ah no, this was an array of objects, so it was an array I needed the length of rather than an object (and the problem turned out to be that I had declared it as an object rather than an array), but thanks for your reply anyway Lloyd :-) Cheers, 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 21:11, Lloyd Alvarez wrote: > 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 >>> >>> >>> >> > --089e01493d9e514a3f04f7c570fa Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Ah no, this was an array of objects, so it was an array I = needed the length of rather than an object (and the problem turned out to b= e that I had declared it as an object rather than an array), but thanks for= your reply anyway Lloyd :-)

Cheers,
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 21:11, Lloyd Alvarez <lists@aescripts.com> wrote:
You are confusing arrays with objects which are different = things in Javascript. =A0Objects do not have a length property which is why= you are having issues. =A0To loop through an object you use a different fo= r loop:

for (var prop in obj) {
=A0 alert(prop + " =3D " + o= bj[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. =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

N= EW! =A0Video DJ Toolkit Volume 2 - Occasions:=A0http://philbearman.co.uk/sh= op/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++){
=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>

On Apr 23, 2014, at 9:29 AM, Phil Bearman <phil@philbearman.co.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





--089e01493d9e514a3f04f7c570fa--