Tuesday 21 April 2009

Still trying to do Flex/AS3 stuff without knowing Flex/AS3

This morning I was still working on my custom metadata file info panel for Adobe CS4 products.

I decided to try and make a list using a <mx:DataGrid> instead of a <mx:List> as I preferred the way the Datagrid looked (with its headertext for each column), and also its drag and drop functionality.

Unfortunately after getting it working, I found out that it was quite buggy and doesn't display the values correctlt if you have more values than rows:


I ran the CS4 updater, but after updating the DataGrid display was still buggy. I also tried the YahooSearchSamplePanel again, but it still wouldn't work where an image didn't already have a dc:subject element in its xmp block.

I got my lists working so I could copy items from the right list to the left list, but when doing this I also needed to update the XMP element that should hold the data, so the data will get saved when closing the panel.

However, despite searching a bit of the morning and a lit of the afternoon, I couldn't find info on what event fires when the dataProvider for the List element is updated. Most of the info I read was about DataGrids rather than Lists, and it seems the events are to do with when an indivdual item is changed, rather than the actual dataProvider.

I tried the following, none of which would trigger the saveFilters() function when adding an item to the filtersUsed List:

filtersUsed.addEventListener("modelChanged", saveFilters);
filtersUsed.dataProvider.addEventListener("modelChanged", saveFilters);

filtersUsed.addEventListener(CollectionEvent.COLLECTION_CHANGE, saveFilters,false,0,true);
filtersUsed.addEventListener(CollectionEvent.COLLECTION_CHANGE, saveFilters);
filtersUsed.addEventListener(Event.ADDED, saveFilters);
filtersUsed.addEventListener("added", saveFilters);
addEventListener(ListEvent.ITEM_EDIT_END, saveFilters, false, 0)

filtersUsed.addEventListener(DataChangeEvent.DATA_CHANGE, saveFilters);
addEventListener(DataChangeEvent.DATA_CHANGE, saveFilters);
filtersUsed.dataProvider.addEventListener(DataChangeEvent.DATA_CHANGE, saveFilters);
filtersUsed.addEventListener(DataChangeEvent.DATA_CHANGE, saveFilters,false,0,true);
addEventListener(DataChangeEvent.DATA_CHANGE, saveFilters,false,0,true);
filtersUsed.dataProvider.addEventListener(DataChangeEvent.DATA_CHANGE, saveFilters,false,0,true);

And also adding dataChange="saveFilters()" to the filtersUsed List element didn't work either.

I think I have worked a way round it for the moment, though. I have two ways of adding items from the right list to the left list: select the item in the right list and click a button - this fires a function that I can also tell to update the relevant XMP field; and drag and drop the item from the right list to the left list - I just found out there is a dragDrop event, so I can add this to the left column and get it to fire a function to update the relevant XMP field.

After discovering the above I went in the garden for a bit. There didn't seem to be many insects around, though there were quite a few ants on a dandelion. I took some photos of them, but they were constantly moving and also bits of dandelion kept being in front of them.

I did a bit more work on the custom metadata panel, and then found that I couldn't add any event Listeners. After some googling I found a comment at the bottom of this page: Flex Programming Elements / Using Events, which says that any functions called by an Event Listener must have the event as a parameter, otherwise they won't work. I wish I had known that earlier, unfortunately I didn't see it anywhere in Adobe's documentation, or mentioned anywhere else (probably most people assume you already know this), the only place I saw it was this comment.

So, with that in mind, I went back and retested those earlier eventListeners I had tried before to try and listen for when my List's dataProvider is changed. I didn't test all of them, just until I got one to work, which was filtersUsed.dataProvider.addEventListener(CollectionEvent.COLLECTION_CHANGE, saveFilters, false, 0, true);

I checked my email, then it was dinner time. After dinner I watched an episode of 'The Equalizer', then watched 'Omega Man' with Mac and Ben.

Something else I just discovered about making the custom metadata panel - after you update the element with the xmpPath that points to the element you want to write, you must set this.xmpModification = true;, or the modification won't actually be saved.

The weather today was slightly misty early on, and then sunny all day.

Food
Breakfast: Choco hoops; cup o' tea.
Lunch: Smoked peppered ham with mustard sandwich; banana; slice of Madeira cake; Rocky; cup o' tea.
Dinner: Chicken & Asparagus pie; potatoes; mixed veg; gravy. Pudding was 2x small (for a muffin) chocolate muffins. Coffee; A couple of bits of Green & Black's Maya chocolate; a piece of Cadbury's Dairy Milk.

No comments: