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.

12 Responses to “DataGrid Transparent Background in Flash 8”

  1. daniel Says:

    thank you.

  2. Qualified Says:

    Thanks kindly for your post.

    Much easier to integrate with XFactorStudio than flashgamer solution.

    Works like a charm.

    Regards,

    Qualified

  3. Christy Says:

    Thanks for your post.

  4. Tom Says:

    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?

  5. Rich Hauck Says:

    Sorry, don’t know offhand. :(

  6. Tom Says:

    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…

  7. t2kien Says:

    Great, thanks alot

  8. Gabe Garza Says:

    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.

  9. Tom Wallace Says:

    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….?

  10. Gabe Garza Says:

    can you create a simple FLA file and give me a link where I can download it.
    what version of Flash are you using?

  11. Gabe Garza Says:

    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;

    }

  12. Tom Wallace Says:

    Works like a champ now….thanks for sharing.

Leave a Reply


Bad Behavior has blocked 451 access attempts in the last 7 days.