Header Ad

Monday, May 5, 2014

How to apply filterFunction to Array Collection in Adobe Flex or Action Script ?

The following is an example that will show you how to apply a fiterFunction to array collection in action script.

var idsList:ArrayCollection=new ArrayCollection(["1","2","3"]);
var nodeId:Number = 2;

var filterByIdFilter:Function = function(item:Number):Boolean
{
    if(item == nodeId) return true;
    return false;
}
idsList.filterFunction = filterByIdFilter;
idsList.refresh();


If the provided nodeId matches with idsList array collection, after applying filterFunction the idsList will be truncated to size "1", otherwise size "0".

Scaling an image to match the content width

To scale an image, so that it should fit 100% of content width. The following is the sample code.



In the above scaleContent, width and maintainAspectRatio are important, we need to define them in order scale the image to 100% width of cotent width.