Monday 20 April 2009

Getting confused by Flex 3/ActionScript 3

This morning I went on a nice walk with Clare, Brian and Shaz, it was really nice and warm and sunny, and there were quite a few flowers out, birds singing etc.

In the afternoon and evening I was working on my XMP panel.

The first trouble I had was I didn't know how access the value of the selected items in my <mx:List> element. The answer was to do listElement.selectedItems, which gives an array and then loop through it.

The second problem was how to add the selectedItems values to the XMP item, which was a bag array. After much messing around I found the answer in the source files for one of the example panels supplied with the XMP Toolkit SDK.

In the YahooSearchExamplePanel, they have the following function:

/**
* Adds the selected search result as a keyword entry to the XMP
*/
private function updateKeyword():void{
try{
//If no former dc:subject entry exists this call makes sure the property exists within the XMP
xmpAccess.setProperty("dc:subject", "", IXMPConst.ARRAY);
//Now one can set a value in a given position.
//Note: It is not possible to set values arbitrarily. If for example 2 Values exist it is only possible to
//set the first, second and third entry.
xmpAccess.setProperty("dc:subject["+(_dataGrid.selectedIndex + 1)+"]", _dataGrid.selectedItem.value);
}catch(e:Error){
Alert.show("A keyword needs to be selected");
}
}


So when dealing with arrays, you don't setProperty of the element, but rather the element[arrayIndexValue]. Also note this seems to start from 1, rather than 0.

Now in that code above, note they create the dc:subject element if it doesn't already exist. Only problem is, that this doesn't actually work. If you remove the third parameter of that method call, it will create a blank dc:subject element, and won't set any array elements for it. If you leave in the third parameter, it won't create the dc:subject element and so won't set any array elements for it either. I played around with this for quite a long time, but couldn't get it to work. I guess that it should work, but Adobe haven't actually implemented it. I tested using Adobe's YahooSearchSamplePanel panel, rather than just copy/pasting their code to my own panel, to make sure it wasn't just something in my panel that was breaking it.

So I decided to try and get my <mx:List> element so it would insert its values into a bag array field with the correct xmpPath in the form, then when you close the File Info dialog it will update the field correctly. It took me quite a while to figure out how to access the value of the XMPTextAreaMRU element (which is holding the bag array), but I did work it out eventually - you need to give it an id, then you can do theid.text to get and set its value.

In the evening I also went on Animal Crossing for a bit. Also today, I received some pogs from a Brazillian person that I did a swap with.

The weather today was a bit misty early on, then sunny the rest of the day.

Food
Breakfast: Pink grapefruit marmalade toast sandwich; cup o' tea.
Lunch: 1½ cheese on toasts; sweet & crunchy salad; clementine; Rocky; cup o' tea.
Dinner: Breaded chicken portion; chips; sweet & crunchy salad; tomato ketchup; salt; ground black pepper. Pudding was rhubarb crumble with cream - deelee!! Coffee; Flake.

No comments: