Agh. How could I miss that. ive depended too much on IDE and its showing now that im using plain text editor :P. Thanks a bunch.
Alex Harui <[EMAIL PROTECTED]> wrote: From the source code: LAST_INDEX_MODE is the third param. /** * Finds the specified object within the specified array (or the insertion * point if asked for), returning the index if found or -1 if not. * The ListCollectionView class <code>find<i>xxx</i>()</code> methods use * this method to find the requested item; as a general rule, it is * easier to use these functions, and not <code>findItem()</code> to find * data in ListCollectionView-based objects. * You call the <code>findItem()</code> method directly when writing a class * that supports sorting, such as a new ICollectionView implementation. * * @param items the Array within which to search. * @param values Object containing the properties to look for (or * the object to search for, itself). * The object must consist of field name/value pairs, where * the field names are names of fields specified by the * <code>SortFields</code> property, in the same order they * are used in that property. * You do not have to specify all of the fields from the * <code>SortFields</code> property, but you * cannot skip any in the order. * Therefore, if the <code>SortFields</code> * properity lists three fields, you can specify its first * and second fields in this parameter, but you cannot specify * only the first and third fields. * @param mode String containing the type of find to perform. * Valid values are * <ul> * <li>ANY_INDEX_MODE</li> Return any position that * is valid for the values. * <li>FIRST_INDEX_MODE</li> Return the position * where the first occurrance of the values is found. * <li>LAST_INDEX_MODE</li> Return the position * where the * last ocurrance of the specified values is found. * </ul> * @param returnInsertionIndex If the method does not find an item identified * by the <code>values</code> parameter, and this parameter * is <code>true</code> the <code>findItem()</code> * method returns the insertion point for the values, * that is the point in the sorted order where you should * insert the item. * @param compareFunction a comparator function to use to find the item. If * you do not specify this parameter, the function uses * the function determined by the Sort instance's * <code>compareFunction</code> property, * passing in the array of fields determined * by the values object and the current SortFields. * @return int The index in the array of the found item. * If the <code>returnInsertionIndex</code> parameter is * <code>false</code> and the item is not found, returns -1. * If the <code>returnInsertionIndex</code> parameter is * <code>true</code> and the item is not found, returns * the index of the point in the sorted array where the values * would be inserted. */ public function findItem(items:Array, values:Object, mode:String, returnInsertionIndex:Boolean = false, compareFunction:Function = null):int { --------------------------------- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of ibo Sent: Wednesday, April 16, 2008 8:13 PM To: flexcoders@yahoogroups.com Subject: RE: [flexcoders] Sort - findItem - compareFunction prob second arg? sort.findItem(forAddition[i], Sort.LAST_INDEX_MODE, true, compareTitles); The 2nd argument is a constant provided in Sort class. I used whats available. The other 2 options are : Sort.LAST_INDEX_MODE Sort.ANY_INDEX_MODE Care to give a correct sample usage of Sort.findItem()? I cant find an example anywhere. Thanks. Alex Harui <[EMAIL PROTECTED]> wrote: Youre missing the second argument to findItem. --------------------------------- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of ibo Sent: Wednesday, April 16, 2008 2:10 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Sort - findItem -! compareFunction prob Hi I'm having problem with sorting, the compiler says : error: [mxmlc] C:\stephen\Main.mxml(51): Error: Implicit coercion of a value of type Boolean to an unrelated type String. [mxmlc] insertionIndex = sort.findItem(forAddition[i], Sort. LAST_INDEX_MODE, true, compareTitles); [mxmlc] compiler documentation says: * 1067 * Implicit coercion of a value of type _ to an unrelated type _. * You are attempting to cast an object to a type to which it cannot be converted. This can happen if the class you are casting to is not in the inheritance chain of the object being cast. This error appears only when the compiler is running in strict mode. code: -------------------------------------- private function compareTitles(itemA:MyObj, itemB:MyObj):int { var valueA:String = itemA.title; var valueB:String = itemB.title; return ObjectUtil.stringCompare(valueA, valueB); } --------------------------------------- // forAddition is pre-sorted from the backend var forAddition:ArrayCollection = ..some data..; ! // Check insertion index to maintain sorting order var sort:Sort = new Sort(); var insertionIndex:int = 0; for (var i:int=0; i<forAddition.length; i++) { insertionIndex = sort.findItem(forAddition[i], Sort.LAST_INDEX_MODE, true, compareTitles); items.addItemAt(forAddition[i], insertionIndex); } --------------------------------------- What changes do I need to do fix the error? I dont see any datatype mismatch at the method parameters. Regards, Stephen --------------------------------- Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. --------------------------------- Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. --------------------------------- Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.