Return-Path: Received: from qmta07.emeryville.ca.mail.comcast.net ([76.96.30.64] verified) by media-motion.tv (CommuniGate Pro SMTP 4.2.10) with ESMTP id 5451454 for ae-list@media-motion.tv; Wed, 23 Apr 2014 22:00:25 +0200 Received: from omta09.emeryville.ca.mail.comcast.net ([76.96.30.20]) by qmta07.emeryville.ca.mail.comcast.net with comcast id tTyv1n0030S2fkCA7Y0QC1; Wed, 23 Apr 2014 20:00:24 +0000 Received: from HPZ200 ([24.10.59.135]) by omta09.emeryville.ca.mail.comcast.net with comcast id tXyP1n0052v3gNo8VXyPX7; Wed, 23 Apr 2014 19:58:23 +0000 Message-ID: <06642885D41A492CB18F9AF2FB47CEEC@HPZ200> From: "Dan Ebberts" To: "After Effects Mail List" References: In-Reply-To: Subject: Re: [AE] Extendscript Question - Array length problem Date: Wed, 23 Apr 2014 12:58:26 -0700 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_00B6_01CF5EF3.B76A61E0" X-Priority: 3 X-MSMail-Priority: Normal Importance: Normal X-Mailer: Microsoft Windows Live Mail 15.4.3555.308 X-MimeOLE: Produced By Microsoft MimeOLE V15.4.3555.308 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1398283224; bh=Lohr85aMqmq3lHsbpebaX7UcP/cb9nIQbnnQdKE+VfE=; h=Received:Received:Message-ID:From:To:Subject:Date:MIME-Version: Content-Type; b=TbFU3RfZc2uyrBz/mUV4N84SmYgtfSwXqtnsX2652KtvMrfmeoA7Gc8VEP9ETndi6 sGhhCRXqSgTfo+H+gOFlNGVx+UvsRktCIMvkwFABXw2HI+W3rw4+m5k6hibUlb02e8 ojujHjkxEkKbZYK8l56dW0R8hd0QimxRVQSws2RQp3U4q6SshKRLIZSXFLDmGw8w9E bMlEyx3OLTV4a3ZuImeDetnna2yoZJW88Yqu1r3bxXyTLnHofyPX9Op5hYro8BMOF2 7JtcO5nfdT6/WD05AAJnv3RgOHf+ip5+Uzyg3VQ4eLeZhSSpDuRoIS+jrSFDTXclot L64B40/PBAE7A== This is a multi-part message in MIME format. ------=_NextPart_000_00B6_01CF5EF3.B76A61E0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable You=E2=80=99re defining textLineObjectArray as an object. Try defining = it as an array: var textLineObjectArray =3D []; Dan From: Phil Bearman=20 Sent: Wednesday, April 23, 2014 12:49 PM To: After Effects Mail List=20 Subject: Re: [AE] Extendscript Question - Array length problem 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)=20 var textLineObjectArray =3D {}; var textLine=3D"Sample"; //~ Split string into array of characters var textLineArray =3D textLine.split(''); //~ Iterate through array and for each character, create an object=20 for (var i =3D 0; i < textLineArray.length; i++){ //~ Add character name to object textLineObjectArray[i]=3D{name:textLineArray[i]} } //~ output length of array of objects alert(textLine1ObjectArray.length); Can you see any problems with this? Phil --=20 Phil Bearman Phil Bearman Creative Media Solutions=20 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=20 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=3D0; i = wrote: Hi all, =20 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=3D0; i < myWidthValues.length; i++) { myArray[i].width=3DmyWidthValues[i]; myArray[i].height=3DmyHeightValues[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 --=20 Phil Bearman Phil Bearman Creative Media Solutions=20 Motion Graphics Design www.PhilBearman.co.uk : Nightclub & Bar ~ Production, Corporate & = Events ~ DVD Products=20 0161 236 2581 - 9am-5pm, Monday-Friday ------=_NextPart_000_00B6_01CF5EF3.B76A61E0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
You=E2=80=99re defining textLineObjectArray as an object. Try = defining it as an=20 array:
 
var textLineObjectArray =3D [];
 
 
Dan
 
Sent: Wednesday, April 23, 2014 12:49 PM
Subject: Re: [AE] Extendscript Question - Array length=20 problem
 
Hi David, thanks for the reply.  Yes, it's populating the = array as=20 expected.  Here's a better example script.  This is a = simplified=20 version of the actual script I'm using, but demonstrates the problem if = you run=20 it in ExtendScript Toolkit (it should pop up an alert box giving the = length of=20 the array but instead says ''undefined').
 
//~ Declare array (which will be populated with objects)
var textLineObjectArray =3D {};
 
var textLine=3D"Sample";
//~ Split string into array of characters
var textLineArray =3D textLine.split('');
//~ Iterate through array and for each character, create an object =
for (var i =3D 0; i < textLineArray.length; i++){
     //~ Add  character name to = object
       =20 textLineObjectArray[i]=3D{name:textLineArray[i]}
}
//~ output length of array of objects
alert(textLine1ObjectArray.length);
 
Can you see any problems with this?
 
Phil
 
--

Phil=20 Bearman

Phil Bearman Creative Media=20 Solutions
Motion Graphics = Design

NEW!  Video=20 DJ Toolkit Volume 2 - Occasions: http://philbearman.co.uk/shop/vdj-toolkit-2/

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

0161 236 2581 - 9am-5pm,=20 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 = have=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 = information=20 could be intercepted, corrupted, lost, destroyed, arrive late or = incomplete, or=20 contain viruses. The sender therefore does not accept liability for any = 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=20 contained in the E-Mail message or any attached=20 documents.



On 23 April 2014 18:39, David Torno <torno@sydefxink.com> wrote:
You should still be able to get the length of the array using = length.=20 Object or item based. I would verify that the array keys (.width and = .height)=20 are actually populated correctly within the array. I usually make my = object=20 arrays a little different and more literal like this. Not that it's = right or=20 wrong, just different option.
 
for(var i=3D0; i<aryLen; i++){
     myObjectAry.push({'width': ary.width, = 'height':=20 ary.height});
}

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

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

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

Hi all, =20
 
I'm doing some scripting in AE, and need to iterate through an = Array of=20 Objects, so need to find out the number of items in the array in = order to=20 set up the loop.
 
I had expected to be able to get the number of items using=20 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=3D0; i < myWidthValues.length; i++)
{
myArray[i].width=3DmyWidthValues[i];
myArray[i].height=3DmyHeightValues[i];
}
 
(this isn't the real code, just a simplified example)
 
And the array is functioning as expected (so for example=20 myArray[2].width gives the result I expect).
 
Is there a reason that an Array of Objects won't return a = 'length'=20 value?
 
(I know this question would be better suited to a general = javascript=20 forum, but I've trawled internet forums to no avail, and thought I'd = ask=20 here first in case it's a quirk specific to ExtendScript).
 
Any help much appreciated!
 
Phil
 
--

Phil=20 Bearman

Phil Bearman Creative Media=20 Solutions
Motion Graphics = Design

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


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

=

 

 
------=_NextPart_000_00B6_01CF5EF3.B76A61E0--