The current behaviour of splice is the same as it ever was in flash, so probably it's a bug in the documentation.
Cheers,
Ralf.

On 9/26/06, Tracy Spratt <[EMAIL PROTECTED]> wrote:

The for each loop does not process the array in order.  The traversal order is documented as not reliable, but actually seems to always return elements in the order which they are added to the array.

 

Try this using a straight for loop.  (I haven't, so you could be correct about a bug)

 

Tracy

 


From: [email protected] [mailto:[email protected]] On Behalf Of Pan Troglodytes
Sent: Tuesday, September 26, 2006 11:38 AM
To: flexcoders
Subject: [flexcoders] bug in Array.splice?

 

Either there is a bug in Array.splice, or the documentation is off.

>From the help:

Example
The following code creates the Array object
vegetables with the elements [spinach, green pepper, cilantro, onion, avocado]. The splice() method is then called with the parameters 2 and 2, which assigns cilantro and onion to the spliced array. The vegetables array then contains [spinach,green pepper,avocado]. The splice() method is called a second time using the parameters 1, 0, and the spliced array to assign [spinach,cilantro,onion,green pepper,avocado] to vegetables.

var vegetables:Array = new Array("spinach",
                 "green pepper",
                 "cilantro",
                 "onion",
                 "avocado");


var spliced:Array = vegetables.splice(2, 2);
trace(vegetables); // spinach,green pepper,avocado
trace(spliced);    // cilantro,onion

vegetables.splice(1, 0, spliced);
trace(vegetables); // spinach,cilantro,onion,green pepper,avocado


However, this is not the case.  When you pass an array as the third argument to splice, it adds the target ARRAY to the original array.  It does not insert the VALUES in the target array.

if you add
for each (var o:Object in vegetables)
  trace(typeof(o), o.toString());


you will get:
string spinach
object cilantro,onion
string green pepper
string avocado

So, is this a bug or intended behavior?  I could see how it could go either way.  However, it seems the example in the documentation should be fixed.  I'm thinking it was intended that a passed-in array would be disassembled and its components added.  Otherwise, why say "one or more comma-separated values, or an array, to insert into the array"?  Singling out array makes no sense, as it would be treated like any other value passed in.


--
Jason




--
Ralf Bokelberg <[EMAIL PROTECTED]>
Flex & Flash Consultant based in Cologne/Germany __._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply via email to