Monday, 28 June 2010

Flexing my patience

Today I was mainly working on my XMP File Info panel.

For the last couple of days, whenever I have added a dataProvider to an mxml XMPComponent in my project, e.g.
 <fi:XMPFormItem label="$$$/xmp/Iptc4xmpExt/WorldRegion=World Region" labelTooltip="$$$/xmp/Iptc4xmpExt/WorldRegion_tooltip=The name of a world region of a location. This element is at the first (topI) level of a top-down geographical hierarchy." >
<fi:XMPComboBox id="LocationCreatedWorldRegion1" xmpPath="Iptc4xmpExt:LocationCreated[1]/Iptc4xmpExt:WorldRegion" width="300" dataProvider="{worldRegions}" />
</fi:XMPFormItem>
It has made the panel blank when viewing it in Photoshop or Bridge.

After trying many different things, I gave up and decided to just try and get my panel working without dataProviders for the moment - I could think more about how to add the dataProviders when the rest of the panel was finished.

So today I slowly built my panel up, copying code over from my old panel (which just appears blank in CS5), and testing after each addition to make sure the panel was still appearing and hadn't turned blank.

As part of the process I had to check one of the sample panels that Adobe includes with the XMP File Info SDK 5.0.0, and I noticed that in there they were using a dataProvider on one of the XMPComponents.

So after copying that and slowly modifying it into my own code, testing after each time, I found that I could add dataProviders in my own panel. Very strangely, I added back dataProviders that I had removed due to them making the panel appear blank in PS and Bridge, and yet now the panel would appear okay?!

I really don't understand how it can not work one day, and then work the next?

Anyway, I also had a couple of times when Flash Builder crashed on me, and a couple of times when it said it couldn't build the project and to build it using ant to see what the error message is. But building using ant built the project successfully. To get Flex Builder to build the project I'd have to close it and open it again, and then it would be able build the project instead of saying there was a problem.

When building with ant, I found that it output the compiled project to the project's bin folder, instead of outputting it to the destination folder. So I'd have to manually copy the panel file to the correct place if I wanted to test the output when built directly using ant.

A problem I spent a very long time debugging was that I was getting Error # 1086 when trying to append some XML. My test code looked like:
var itemName:String = "Lenses";
prefs.appendChild( '<'+itemName+'></'+itemName+'>' );
Alert.show(typeof(prefs["Lenses"])); prefs["Lenses"].appendChild('<Lens></Lens>');
It took me quite a long time to out what the problem was, the alert showed that prefs["Lenses"] was xml, but when I did Alert.show(prefs.toXMLString()); I got
<prefs>&lt;Lenses&gt;&lt;/Lenses&gt;</prefs>
So clearly the string was being converted to text/entities instead of XML.

I tried lots of different things to try and get the string to be added as an XML node, and eventually found that all I needed to do was to change
prefs.appendChild( '<'+itemName+'></'+itemName+'>' );
to
prefs.appendChild( new XML('<'+itemName+'></'+itemName+'>') );


Another thing I found was that when I added an inline XMP_WRITE event handler xmpwrite="eventHandler()" the handler would be triggered before the XMP was written. But if I added the XMP_WRITE event handler dynamically using actionscript addEventListener(XMPEvent.XMP_WRITE, createArray);, then the handler would be called after the XMP had already been written. So to fix this, when adding the event handler dynamically with actionscript, you need to specify a higher priority. I found a priority of 1 (the larger the number the higher the priority, default is 0), meant the handler would be called before the XMP was written: addEventListener(XMPEvent.XMP_WRITE, createArray, false, 1);

In the evening I watched part of a webinar about niche websites, most of an episode of Life (BBC nature documentary), and most of the Brazil vs. Chile match. I also spent quite a while watering the garden.

No comments: