blog.programFlex.com is now on twitter under the user programflex. Still working out multiple posting issues - but some progress has been made
Ok - so we all need this one from time to time. I have had 3 projects to date that have needed it and I’m sure many of you have too.
This functions sole purpose is to grab everything out of a datagrid and place the contents into the clipboard so that you could paste it into say excel or anything else for that matter.
public function clipData( dg:DataGrid ):void
{
var totalExport:String = new String();
var colList:Array = new Array();
for(var i:int = 0; i < dg.columnCount; i++)
{
colList.push(dg.columns[i].dataField);
totalExport += dg.columns[i].headerText + “\t”;
}
totalExport += “\r”;
for(var yp:int = 0; yp < dg.dataProvider.length; yp++)
{
for(var xp:int = 0; xp < colList.length; xp++)
{
totalExport += dg.dataProvider[yp][colList[xp]] + “\t”;
}
totalExport += “\r”;
}
Clipboard.generalClipboard.clear();
Clipboard.generalClipboard.setData( ClipboardFormats.TEXT_FORMAT, totalExport );
}
So again this function will simply grab everything - the headers and data and create a string that separates column names and data values with tabs and place carriage returns at the end. The string is then copied to the clipboardthat can be pasted into anything. Hope it helps
One of things I find myself doing is trying to “pretty” things up by changing the styles and colors of various things on the screen. Something I found a need for is a function that would allow me to control the color of a canvas with a gradient of some sort. I wrote a pretty simplistic function to accomplish this for me:
public function gradientCanvas (cnv:Canvas, color1:uint, color2:uint, angle:int) : void
{
var w:Number = cnv.width;
var h:Number = cnv.height;
var g:Graphics = cnv.graphics;
g.clear();
g.lineStyle(1,0×000000,0.0);
var fill:LinearGradient = new LinearGradient();
var g1:GradientEntry = new GradientEntry(color1,0,1);
var g2:GradientEntry = new GradientEntry(color2,1,1);
fill.entries = [g1,g2];
fill.angle = angle;
g.moveTo(0,0);
fill.begin(g,new Rectangle(0,0,w,h));
g.lineTo(w,0);
g.lineTo(w,h);
g.lineTo(0,h);
g.lineTo(0,0);
fill.end(g);
}
The following imports will be needed:
import mx.graphics.GradientEntry;
import mx.graphics.LinearGradient;
import mx.containers.Canvas;
So now that you have the code an example call would look like this:
gradientCanvas(myCanvas,0×445566,0×223344,45);
Thats it
I am going to attempt to put up flex tips and tricks I have learned since installing Flex. I would like to thank other contributers in the Flex community such as:
Ely Greenfield from http://www.quietlyscheming.com/blog/
Doug McCune from http://dougmccune.com/blog/
Peter deHaan from http://blog.flexexamples.com
In truth I have no idea who the hell any of these people are but their examples have helped me from time to time and thought they should get some recognition.
Rock on!