<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”vertical” horizontalAlign=”left”>
<mx:Script>
<![CDATA[
import mx.graphics.codec.JPEGEncoder;
private function copyImage():void
{
var bit:BitmapData=new BitmapData(116,116);
bit.draw(src);
var jp:JPEGEncoder=new JPEGEncoder(75);
var by:ByteArray=jp.encode(bit);
dest.source=by;
}
]]>
</mx:Script>
<mx:HBox width=”100%” height=”50%”>
<mx:Image id=”src” source=”noimage.JPG” height=”125″ width=”125″ />
<mx:HRule width=”5″/>
<mx:Image id=”dest” width=”125″ height=”125″ />
</mx:HBox>
<mx:Button label=”Copy” click=”copyImage()”/>
</mx:Application>
In this I have a source image (id=src) and a destination image.
On click of the copy button I am using a bitmapdata and drawing the
source component in to it and using a jpeg encoder to convert it to byte array and setting that byte array as source for second image,so that the image is copied to it.
Using the same concept you can take screen shots in flex applications and save as image.
I will be Posting that too keep checking in..
View http://www.box.net/shared/q7q67fyss7
Gridfilter.as
package com
{
import flash.events.Event;
import flash.events.MouseEvent;
import mx.collections.ArrayCollection;
import mx.containers.HBox;
import mx.controls.Alert;
import mx.controls.Button;
public class GridFilter extends HBox
{
public var uniqArray:ArrayCollection;
[Bindable]
public var resultArray:ArrayCollection;
public var filterString:String;
public function GridFilter()
{
uniqArray=new ArrayCollection();
resultArray=new ArrayCollection();
filterString=new String();
}
public function createUniqArray():void
{
uniqArray.removeAll();
for(var i:int=0;i<resultArray.length;i++)
{
uniqArray.addItem(resultArray.getItemAt(i).first_name.charAt(0).toUpperCase());
}
for(i=0;i<uniqArray.length-1;i++)
{
for(var j:int=i+1;j<uniqArray.length;j++)
{
if(uniqArray[i]==uniqArray[j])
{
uniqArray.removeItemAt(j);
j–;
}
}
}
createSortBtns();
}
public function sortItems(e:Event):void
{
filterString=e.currentTarget.label;
resultArray.filterFunction=sortFilter;
resultArray.refresh();
}
public function sortFilter(e:Object):Boolean
{
return e.first_name.charAt(0).toUpperCase()==filterString;
}
public function createSortBtns():void
{
var allBtn:Button=new Button();
allBtn.label=”All”;
allBtn.width=40;
allBtn.addEventListener(MouseEvent.CLICK,allClick);
this.removeAllChildren();
this.addChild(allBtn);
for(var i:int=0;i<uniqArray.length;i++)
{
var btn:Button=new Button();
btn.width=40;
this.addChild(btn);
btn.label=uniqArray[i].toUpperCase();
btn.addEventListener(MouseEvent.CLICK,sortItems);
}
}
private function allClick(e:Event):void
{
resultArray.filterFunction=null;
resultArray.refresh();
}
}
}
Application
<?xml version=”1.0″ encoding=”utf-8″?>
<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”vertical” xmlns:ns1=”com.*” creationComplete=”init()”>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var resultArr:ArrayCollection=new ArrayCollection();
private function init():void
{
resultArr.addItem({first_name:”Admin”,last_name:”Admin”,email:”admin@mail.com”});
resultArr.addItem({first_name:”Boom”,last_name:”Boom”,email:”boom@mail.com”});
resultArr.addItem({first_name:”com”,last_name:”com”,email:”coom@mail.com”});
filter.resultArray=resultArr;
filter.createUniqArray();
}
]]>
</mx:Script>
<ns1:GridFilter id=”filter” height=”10%” width=”100%”>
</ns1:GridFilter>
<mx:AdvancedDataGrid id=”adg1″ designViewDataType=”flat” dataProvider=”{resultArr}” width=”100%”>
<mx:columns>
<mx:AdvancedDataGridColumn headerText=”Firstname” dataField=”first_name”/>
<mx:AdvancedDataGridColumn headerText=”LastName” dataField=”last_name”/>
<mx:AdvancedDataGridColumn headerText=”Email” dataField=”email”/>
</mx:columns>
</mx:AdvancedDataGrid>
</mx:Application>
In this i have a result array in grid filter component in which i am creating
a unique array of starting letters from the result’s first name and then adding the buttons with that letters on clicking on that button iam using a filter function for filtering
View :http://www.box.net/shared/2jppqahf5h
feedback