package
{
import fl.controls.List;
import fl.data.DataProvider;
import flash.display.MovieClip;
public class ArrayFilterTest extends MovieClip
{
protected var original_ar:Array
protected var filtered_ar:Array
protected var mapped_ar:Array
public function ArrayFilterTest()
{
trace( "[ArrayFilterTest] - ArrayFilterTest() :: Constructed." )
original_ar = new Array()
filtered_ar = new Array()
mapped_ar = new Array()
for( var i:uint = 0; i < 10; i ++ )
{
original_ar.push( new ArrayTestItem() )
}
trace( "[ArrayFilterTest] - ArrayFilterTest() :: Original array: " )
original_ar.forEach( traceItem )
trace( "[ArrayFilterTest] - ArrayFilterTest() :: Filtered array: " )
filtered_ar = original_ar.filter( filterItems )
filtered_ar.forEach( traceItem )
trace( "[ArrayFilterTest] - ArrayFilterTest() :: Mapped array: " )
mapped_ar = original_ar.map( mapItems )
mapped_ar.forEach( traceItem )
}
private function traceItem( element:ArrayTestItem, index:int, arr:Array ):void
{
trace( index + "\t\t" + element.ID + "\t\t" + element.test )
}
private function filterItems( element:ArrayTestItem, index:int, arr:Array ):Boolean
{
return element.test
}
private function mapItems( element:ArrayTestItem, index:int, Array:Array ):ArrayTestItem
{
var e:ArrayTestItem = new ArrayTestItem()
e.ID = element.ID
e.test = false
return e
}
}
}
class ArrayTestItem
{
public var test:Boolean
public var ID:Number
public function ArrayTestItem()
{
test = Math.random() > 0.5
ID = Math.floor( Math.random() * 1000 )
}
}
http://eokyere.blogspot.com/
0 megjegyzés:
Megjegyzés küldése