Hi Jason,

 

This is a mistake in the documentation. Thanks for pointing it out. I’ll file a documentation bug to ensure that it gets fixed.

 

Thanks,

 

Francis Cheng | Senior Technical Writer | Adobe Systems, Inc.

 


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

 

As Ralf said, I'm not sure what documentation you are referring to.  Let me be more specific and say the Flex Builder 2.0 documentation (as well as the LiveDocs at http://livedocs.macromedia.com/flex/2/langref/Array.html).

Does that help clear things up?

On 9/26/06, John Grden < [EMAIL PROTECTED]com> wrote:

I read the help, and it pretty well spells out that you send optional arguments in the sample, but I could see where it states "[, value:Object]  that someone could find that confusing.

 

The sample at the bottom of the help file shows exactly what you ended up finaly doing:

var myFurniture_array:Array = new Array("couch", "bed", "desk", "lamp");
trace( myFurniture_array.splice(1,0, "chair" ) ); // Displays empty array.


trace( myFurniture_array ); // displays couch,chair,bed,desk,lamp

hth,

 

On 9/26/06, Pan Troglodytes <chimpathetic@gmail.com > wrote:

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





--
[  JPG  ]




--
Jason

__._,_.___

--
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