Wednesday 22 April 2009

More flexing

Today I was just doing more work on my custom XMP metadata File Info panel. I needed to add a way to remove items from a list, but there doesn't seem to be a removeItem() method for the dataProvider. Googling (which is what I spend most of time doing it seems) for it, the suggested solution seemed to be to use removeItemAt(theList.selectedIndex).

However, my list allowed the user to select multiple items, and selectedIndex just seemed to give the last selected item, rather than an arry of all selected items like I would of expected it to. So what I did was to remove the item at selectedIndex while selectedIndex was a number (you can't just check whether it's true, as if the selectedIndex is 0 then it would evaluate to false, even though it's actually the first item in the list.

This worked, but also gave an error about an item with Index -1 not existing. So I just modified my if statement to also check the selectedIndex was 0 or more:
private function removeFilter(event:Event):void
{
try{
while( !isNaN(filtersUsed.selectedIndex) && filtersUsed.selectedIndex >= 0 )
{filtersUsed.dataProvider.removeItemAt(filtersUsed.selectedIndex);}
}
catch(e:Error)
{Alert.show(e.message);}
}


After getting that working I wanted change one of my List items so it would get its dataProvider info from an external file. I could get the script to see the file when I used the absolute path to the file, but I couldn't get it to work with a relative path. I thought the problem must be that the root of the document was not my panel, but somewhere else, and so the relative path was pointing to somewhere different than where I wanted it to point.

I did lots of googling on on this, and continued trying to work this out after lunch. While I didn't find any way of telling what the path of the document was from the actionscript in the panel, I did find the path just by looking around various directories and putting the file I wanted to refer to in them and see if it worked.

The root directory of the xmp panels (on my machine) was: C:\Program Files (x86)\Common Files\Adobe\XMP\Custom File Info Panels\2.0\bin

After getting the panel to load the file, I wanted the file to contain JSON for the panel to load. I found a nice tutorial on Using JSON with Flex 2 and ActionScript 3, however, when I added the as3corelib.swc to the build.xml file, and compiled the panel, all File Info panels in Bridge were blank.

So I tried the flickr.swc instead of as3corelib.swc, and the panels worked fine. So there must be something in as3corelib.swc that breaks it.

In the article, it said
You can link the project against either the source, or the SWC
So I thought I might be able to link to just the JSON package, and maybe that would work if something else in the as3corelib was breaking it. But the article doesn't say how to link to the source files, and I couldn't find this on google either. I did find how to include an actionscript file, but when I tried this I got a compile error saying "Packages cannot be nested".

So I thought that I should try and compile the JSON .as files into an swc package, and then include that and see if it works. I found a guide on creating an swc file: Adobe Flex - Packaging components, but when I tried to run compc I got a message saying
'compc' is not recognized as an internal or external command, operable program or batch file.


I found out how to add the location of compc to the PATH environment variable, but it still didn't work. Restarted my PC, and it still didn't work. Did lots of googling and couldn't see any reason why it shouldn't work. Then I read a post by someone saying that something had messed up their programs by adding itself to a PATH environment variable for the user, and this meant that the global PATH environment variable was no longer being used for that user.

So I looked at the environment variables again, and I had only added the location of compc under my user's PATH. I added it to the global PATH environment variable, restarted the PC, and now compc would run.

However, compc gave an error message saying
Error loading: C:\Program Files\Java\jdk1.6.0_11\jre\bin\server\jvm.dll
So I looked in C:\Program Files\Java\jdk1.6.0_11\jre\bin\ and couldn't see the jvm.dll file. So I googled for this, but most posts were about the file not being found, even though it existed. I thought I just didn't have the file, and only realised later that I had actually been looking in the wrong location, and did have the file, and the problem was that it wasn't being found even though it exists.

I went in the garden and took some photos for a bit, then it was dinner time.

After dinner I watched an episode of 'The Equalizer', then I went in the garden and took more photos. I had put some honey down earlier, in the hope of attracting some bees/wasps like John K has done, but when I had put it down, it didn't seem to attract anything. Now it was surrounded by ants, eating like pigs at a trough.

In an email from money morning, they had this good graph showing how when Gordon Brown urges the IMF to sell gold it makes the gold price go up:


The weather today was sunny nearly all day, and got a bit cloudy at the end of the day. There was hardly any wind as well.

Food
Breakfast: Pink grapefruit marmalade toast sandwich; cup o' tea.
Lunch: Cheddar cheese with purportedly sweet & crunchy salad but actually just iceberg lettuce sandwich; 2x smallish clementines; slice of Madeira cake; cup o' tea; caramel Rocky.
Dinner: Stir fried vegetables; bolognese sauce; bacon; spaghetti. Pudding was Chocolate mousse that Ben and Shaz made yesterday - very thick and chocolately, yum! Coffee; Flake.
Supper: Packet of prawn cocktail crisps; cup o' tea.

No comments: