Interchange

Flex

Binding on Repeaters - a magic trick?

by hbomb on May.22, 2009, under Flex

The pledge: An ArrayCollection of ObjectProxy objects nested within another ArrayCollection. As the ObjectProxy objects are updated, the view should update accordingly.

The turn: However, this doesn’t seem to be the case. By watching the screen, we see that only the initial setup is run. We try to refresh the base ArrayCollection. Nothing happens.

The prestige: By moving the refresh to the inner ArrayCollection, we get the result we’re looking for: the repeater data updating appropriately.

Tada!

Unfortunately, this took far too long for me to figure out. I was investigating ObjectProxy as I thought that it might not be sending the propertyUpdated event (it was) and all manner of other things. Then it occurred to me: maybe the internal ArrayCollection is not updating.

They say a good magician never reveals his tricks, and that if he does, then the illusion is ruined for the audience. I think the relief of solving this bedeviling problem is worth the ruination of the illusion.

Leave a Comment :, , , , , more...

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.

Leave a Comment :, , more...

Flex DataGrid Date itemEditor

by hbomb on Mar.15, 2009, under Flex

A date editor is a terrible thing to waste

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.

Leave a Comment :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Archives

All entries, chronologically...