Archive for March, 2009
Drag and Drop custom actions with DragEvent.preventDefault()
by hbomb on Mar.18, 2009, under Flex
Dragging and dropping items within Flex is in general pretty simple, especially for components which already have the drag and drop bits already added to them. However, I was running into some problems with adding my own custom actions to the dragDrop event. My actions would add fine, but Flex has some actions which it will also run automatically… unless you call preventDefault() on the DragEvent. What this allows you to do is to have your own actions run without worrying about whether or not the default actions run, which actions run first, etc.
So if you, for instance, wanted to make sure whatever you were dropping did not already exist, your dragDrop event handler would look something like this:
protected function dragDropEventHandler(event:DragEvent):void{
event.preventDefault();
if(!checkExists(event)){
(event.target.dataProvider as ArrayCollection).addItem(event.draggedItem);
}
}
And it’s as simple as that. This could also be used for customizing what gets added - perhaps by building an object which contains which object the draggedItem came from, or having custom text entered into a list, or any of a number of things which could work out better than having the default action performed. I hadn’t really seen this little gem talked about much, but I found it very useful and hopefully someone else will, as well.
Flex DataGrid Date itemEditor
by hbomb on Mar.15, 2009, under Flex

A date editor is a terrible thing to waste
I’ve been working with DataGrids for some time now, but have never had the… pleasure(?) of dealing with editing a Date object within a data grid. I generally feel it’s more appropriate to edit a data record in a customized form, but sometimes it just makes sense to edit it right then and there. This time I ran into a situation where I had to deal with editing a date within the dataGrid. Adding the DateChooser as an itemEditor was simple, but getting it back from a text string to a date object after editing was finished was a bit of a pain. However, once you extended a DateField, it becomes much easier. The heavy lifting is done below.
package com.binaryexposure.editors{
import mx.controls.DateField;
import mx.controls.listClasses.IListItemRenderer;
public class DateEditor extends DateField implements IListItemRenderer{
public function DateEditor(){
super();
}
override public function set data(value:Object):void{
if(listData){
var date:Date;
if(incomingVal is String){
date = new Date(Date.parse(data as String));
super.data = date;
}
else if (incomingVal is Date){
super.data = incominVal as Date;
}
}
}
}
}
At any rate, I found it to be extremely easy and an interesting take on the processing of the data post-edit.
An all new interchange.
by hbomb on Mar.14, 2009, under Uncategorized
This will be my new blog about all things interesting to me at the time. In general, I’ll be writing about Flex and Flash, as well as some Java, graphics design, and usability, but I’m sure there will be other posts devoted to alt energy (in particular setting yourself up to live off grid). So thanks for stopping by, and I hope I’m at least moderately interesting.