More control over the dataGrid component

When using the dataGrid component being lazy as me, you would just get the column names from your dataProvider

//name and rating are the field names in the dataProvider

and call it a day...
But that leaves you with evenly spaced columns and without any dynamic height of your grid, so you better resort to something like:

var nameCol:DataGridColumn=new DataGridColumn("name");

var ratingCol:DataGridColumn=new DataGridColumn("rating");

myGrid.columns = [nameCol, ratingCol];

myGrid.dataProvider=new DataProvider(dp);

which will let you size the columns at your will and have the component grow as you plug in more entries.

Dude, where's my DragOver?

Having it not used for a long time I found out today that AS3 has no DragOver in its MouseEvents. So after a bit of research dugged out several solutions with a custom Event Class but finally resorted to this little if.. statement in my Event Handler for MOUSE_OVER:

//pcont serves as a container for about 100 clips 
//inside that will react to dragOver 
//activate on Mousedown immediately

function onDragOver(e:MouseEvent):void
     //the Mouse is pressed, 
     //Do something here

the buttonDown Property of the MouseEvent makes sure that the Mouse is pressed while you hover your mc.
A more advanced solution can be found at Andre Michelle, he wrote some class files and stuff to adress this shortcoming of Events.

attachMovie in AS3

Today I wrote a little replacement snippet for the deprecated attachMovie. The snippet has 3 parameters for the linkage name in the library, the name of the displayObject you wish to attach the MC to and an optional name param to identify it by name on the display list later on:

function attachMovieClip(mcName:String,target:MovieClip,newName:String="")
var mc=new (getDefinitionByName(mcName) as Class); = newName;

along with Lee Brimelows very useful snippet panel for Flash CS4 attaching MovieClips from the Library at runtime is a bit less complicated especially for AS2 veterans ;-).

the xml snippet for the snippet panel is here for convenient copy/paste:

<title>attachMovie AS3</title>
<code><![CDATA[function attachMovieClip(mcName:String,target:MovieClip,newName:String="")
    var mc=new (getDefinitionByName(mcName) as Class);;

Have fun!