I’m dragging from a TileList to a custom component. I want to know what is being dragged before I accept it. How do I set the “format” that is used for “event.dragSource.formats” in the DragEvent?
Edit for clarification:
When you set “dragEnabled=true” on the TileList, it takes care of the drag source stuff, but it uses “items” as the format for the DragEvent. I’m looking for a way to have the TileList use the correct format.
Hey, this is a great question, and quite complex. Because Flex is primarily developed by Adobe, they don’t have the power/resources/money to cover edge/customization cases like this. If only they decentralized Flex’s development!
I’ve had to deal with this problem too. It boils down to the fact Flex has hard-coded specific data source ‘types’ into the ListBase source, so you can’t change the types. That’s good and bad… Check out all the
drag[Type]Handlermethods in that ListBase class and see what’s going on.All we need to do is intercept the
DragEvent.DRAG_STARTevent and callevent.stopImmediatePropagation()(luckily flex will listen to that!). Here’s an example app:This gives you the base for checking if
dragSource.hasFormatreturns true/false. If you want to change what the dragSource’s format is, you’re going to have to extend TileList and override all of the drag methods :/. TheitemsandorderedItemsare hard-coded into ListBase, so you can’t change the format easily.The only way you can use your own formats is to not use any of the ListBase-extending classes, and implement your own drag/drop system. It’s not that bad. The reason is because, if you look into all the drag event handlers in ListBase, they have things like this:
So if they’re not that format, it won’t allow you to drag.
Hope that helps,
Lance