Технически все они содержат "se", поэтому вам не нужно сортировать:)
Если вы хотите удалить все элементы, которые не содержат "se", вы можете вызвать filter()
в вашем массиве до: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#filter()
тогда просто сортируйте по алфавиту как обычно. Возможно, вы захотите создать свой собственный фильтр, так как filter()
каждый раз создает новый массив.
Если вы хотите сохранить объекты в массиве, вам нужно реализовать собственную сортировку. Примерно так должно работать:
public function Test()
{
var a:Array = ['Ramsey', 'Sephora', 'seq', 'ser', 'user'];
trace( a ); // Ramsey,Sephora,seq,ser,user
a.sort( this._sort );
trace( a ); // Sephora,seq,ser,user,Ramsey
}
private function _sort( a:String, b:String ):int
{
// if they're the same we don't care
if ( a == b )
return 0;
// make them both lowercase
var aLower:String = a.toLowerCase();
var bLower:String = b.toLowerCase();
// see if they contain our string
var aIndex:int = aLower.indexOf( "se" );
var bIndex:int = bLower.indexOf( "se" );
// if one of them doesn't have it, set it afterwards
if ( aIndex == -1 && bIndex != -1 ) // a doesn't contain our string
return 1; // b before a
else if ( aIndex != -1 && bIndex == -1 ) // b doesn't contain our string
return -1; // a before b
else if ( aIndex == -1 && bIndex == -1 ) // neither contain our string
return ( aLower < bLower ) ? -1 : 1; // sort them alphabetically
else
{
// they both have "se"
// if a has "se" before b, set it in front
// otherwise if they're in the same place, sort alphabetically, or on
// length or any other way we want
if ( aIndex == bIndex )
return ( aLower < bLower ) ? -1 : 1;
return aIndex - bIndex;
}
}