DataGrid Transparent Background in Flash 8
I feel like I’m really behind in the loop here using Flash 8 components over the new, supposedly easy-to-use Flex components, but I figured I’d share this little tidbit, since it was nearly impossible to find online.
If you’ve ever worked with Flash’s built-in DataGrid component, you’ll quickly discover how difficult it is to customize: there’s theme files to edit, there’s styling, and there’s classes (such as RectBorder). Unfortunately, none of them helped me to set the background of the DataGrid component to transparent.
The closest solution I found was on FlashGamer, but I soon found that any buttons or MovieClips being placed into my DataGrid via the cellRenderer API were being set to transparent as well. So, I spent some time figuring out how FlashGamer apparently figured it out:
I went through the class files in the Flash 8 Application/First Run/classes/mx/controls/DataGrid.as to discover that Flash was using the drawing API to generate the background (I could have fixed it here, but didn’t want to do anything questionable in the eyes of the license agreement).
Then, I published an SWF and checked out Debug > List Objects to see the MovieClip structure of the DataGrid. What I found I wanted to hide was my _dg.content_mc["listRow"+i].bG_mc. Like FlashGamer, I discovered that it takes about half a second to render the DataGrid (I’d test based on amount of data, though), and, oddly enough, the rows started at 10. So, I reused the while() loop generously offered, but rather than use a custom frame-based timer class, I used the undocumented global setTimeout() method (for documentation, check out FlashGuru’s setTimeout() post).
So, to set your DataGrid background to transparent, pull a DataGrid component onto the stage and name it “my_dg” and place this code on frame 1 of the _root:
import mx.controls.DataGrid;
//Create a dataProvider to add some data to the Datagrid
var data_array:Array = new Array();
data_array.push({Model:"Ford", Year:0});
data_array.push({Model:"Dodge", Year:1});
data_array.push({Model:"BMW", Year:2});
my_dg.dataProvider = data_array;
// set border_mc to transparent
my_dg.border_mc._alpha = 0;
/**
* Hides background of DataGrid.
*/
function hideBgd():Void {
trace("hideBgd")
var i:Number = 10;
while (my_dg.content_mc["listRow"+i] != undefined) {
my_dg.content_mc["listRow"+i].bG_mc._alpha = 0;
i++;
}
}
// call hideBgd in half a second
setTimeout(hideBgd, 500);
Hopefully, this’ll save someone the time I took looking around.

May 15th, 2007 at 3:53 pm
thank you.
July 16th, 2007 at 3:49 pm
Thanks kindly for your post.
Much easier to integrate with XFactorStudio than flashgamer solution.
Works like a charm.
Regards,
Qualified
September 12th, 2007 at 11:51 pm
Thanks for your post.
September 27th, 2007 at 6:49 pm
I have applied this to a list and it works very well, thank you. Do you know the path to set the alpha of the border that shows up when the list has focus?
September 29th, 2007 at 3:25 pm
Sorry, don’t know offhand.
September 30th, 2007 at 4:56 pm
I was not importing the class and it caused a funny boarder around it for some reason.
Thank you for this, it works great I’m using a transparent list as a sub menu…
October 7th, 2007 at 1:30 pm
Great, thanks alot
December 10th, 2007 at 8:46 pm
Rich,
You’re code jumpstarted me and I finally figured out how to set DataGrid to transparent without the call to the SetTimeout()
In Flash 8, drag a DataGrid to your project then click on the DataGrid and go the the Actions Window and put in the following:
on(load)
{
this["header_mc"]._alpha = 0;
this["listContent"]._alpha = 0;
}
on(draw)
{
this.vScroller._alpha = 20;
this.hScroller._alpha = 20;
}
Go to my website http://www.digimixstudios.net and click on “Music” and check out my Flash MP3 player.
The list of songs are in a DataGrid that has the background set to transparent.
December 11th, 2007 at 11:03 am
I tried this:
on(load)
{
this[â€header_mcâ€]._alpha = 0;
this[â€listContentâ€]._alpha = 0;
}
on(draw)
{
this.vScroller._alpha = 20;
this.hScroller._alpha = 20;
}
didn’t work for me….?
December 11th, 2007 at 1:14 pm
can you create a simple FLA file and give me a link where I can download it.
what version of Flash are you using?
December 11th, 2007 at 1:29 pm
Tom,
Sorry about that.
I had additional lines within my on(load) code that were related to setting color that didn’t have anything to do with transparent, but within those lines I forgot about another line that had to do with transparent.
Add the additional line and you should be fine.
on(load)
{
this["header_mc"]._alpha = 0;
this["listContent"]._alpha = 0;
this["border_mc"]._alpha = 20;
}
December 12th, 2007 at 10:53 am
Works like a champ now….thanks for sharing.