Categories
Programming

When your flex test build suddenly no longer works

When I’m using Adobe Flex to run a test build of my application, often for testing a change I just made, I sometimes get an error, on which I click continue, and then instead of continuing, nothing else happens. This usually happens because of a run-time error.

Subsequently, Flex builder still works, but any release builds you want to create no longer get made; nothing shows up as an error.

I’ve found out that the probable culprit is the adl compiler, which is stuck, most probably waiting for input which you cannot supply.

The easiest way to get out of this situation is to use taskmanager to kill the adl process. This allows flex builder to run test builds again. However, the source that causes the problem is in the programming change you made, so you need to solve that first otherwise it will again create the same situation, and then you need to kill adl again…

Categories
Programming

Aarghl! Error #1034 Type Coercion failed: Cannot convert something to something

The error “Type Coercion failed: cannot convert [#78F6AA, #CAF2DA] to Array” has stared me in the face for the past few days or so.

The error actually has useful information in it (but at the moment I got it, ofcourse I never properly read it…). It states that whatever you are doing, you are passing the wrong type of variable to the function/variable. It expects it to be in another type.

This blog entry helped me to understand the error message.

I wanted to implement a function so the user can select his own gradient colors and save them as a preference for my AIR app. cp1 and cp2 are 2 flex colorpicker functions.




[Bindable] private var colors_selected:Array = [cp1.selectedColor, cp2.selectedColor];

However, everytime I ran the program I got the Type Coercion error.

Finally I found out what’s wrong. I made an array out of both colorpicker selected colors, and then passed it to backgroundGradientColors in another array.
Duh (Smacks head) !
Of course it doesn’t like it ! Below is the corrected code. The mx:SetStyle now does not specify an array, as this is constructed in the variable colors_selected.




[Bindable] private var colors_selected:Array = [cp1.selectedColor, cp2.selectedColor];

Categories
Programming

When is the next train leaving ? (Flex application)

I’ve created a smallish new AIR program called “TrainDeparture”, but as it currently uses no database except an xml file, it was fairly easy to recompile it for the web. It has ‘view code’ enabled, by the way.

The program does one thing only : based on the current time it checks the xml file for trains (that you will, for now, need to create yourself or edit the one I supply via a text editor) and will show you the time of the next train leaving.

You can see the results by clicking here:Train Departure

By clicking on the “Prefs” button you will see a resize of the application with a datagrid showing the current entries in the file (it’s there for reference, and in the future I want to add additional stations and more preferences in there).

The “Next” button shows you the train after that, and the one after that, etc. There’s a timer event running so after 30 seconds (or less) the time shown by the next button will be reset to the current next train.

The next thing I want to change is to show not the time the train leaves, but the minutes remaining before the train leaves – I think it will be far more useful for me to see how many minutes remain.

Should you wish to use it, I’ve described the structure of the XML file below.

It’s basically functional, but there is quite a lot of amelioration that can be made to the program. One of them is coding to show the trains on weekdays or in the weekends based on the current date. Another one is to show the remaining minutes before the train leaves.

Also a quick nod to the StackOverFlow website, where a kind person helped me solve a problem with the ‘states’ setting that was driving me crazy. It’s a website for programmers by programmers !

Categories
Programming

How to access your xml in flex

I’ve had a request to explain how I access the XML (using Flex) once I created the XML file out of the csv file using my csv2xml python script.

To access the XML in Flex, I’ve defined an XML variable in Flex :

private var content:XML;

And I then load the XML file into the content file.

fileStream.open(file, FileMode.READ);
content = XML(fileStream.readUTFBytes(fileStream.bytesAvailable));
fileStream.close();

If you are using my csv2xml.py script, the xml file was written with ‘root’ in the top and then for each row in the csv file an ‘element’ tag was used.

Between the element tags the content of one row of the csv is written, using the header of the csv file as the tag name for each item.

In order to access one of these tags below the element, for example the content of the tag ‘assigned’ you would specify the following :

var result:XMLList = content.element.assigned

As you can see, you do *not* mention ‘root’. This was a Gotcha for me for a while… This will store all the assigned in the result variable, which you can then
further manipulate.

BTW, I use the trace command a lot to check on the content of my vars…

In a variation on the previous, say you want to only get the unique values out of a tag, to store in a combobox so the user can use these for filtering the data :

// Function called from each filter to extract the unique values
private function addUniqueValue(alllist:XMLList):XMLList{
var list:XMLList = new XMLList;
//trace("*** Setting up unique values.");
for each ( var property:XML in alllist){
//trace("*** Property : " + property.toXMLString());
if(!list.contains(property)){
list += property;
}
}
return list;
}

You would get the unique values by calling the function in the following way :

var filterStatus:XMLList = addUniqueValue(filtercontent.element.Status);

This will get you a unique list of all the statuses in the xml file.

I hope this helps you get the goods out of your xml file !

Categories
Programming

Showing a popup image in flex and passing variables to a mxml module

I already show a thumbnail image in my Quickwins application, but I wanted to show the full image when one clicked on the thumbnail. The image should open in a window on top of the current application window, and can be closed again.

I had to google for a while (I got a lot of help from reading “Web Development Central” ) and search the Flex built-in help before I figured it out, but I think it’s because it’s so damn easy to do this in just a few lines of code !  Here’s how you do this :

Say you want to show an image – the image’s path is “c:\windows\test.jpg” and that path is stored in a string variable screenshot_path

  1. Create a new mxml module in your project, for example call it ‘ViewWindow.mxml’ – Make it a TitleWindow
  2. In your main program, call the module via the PopUpManager  (you’ll need to import it via “import mx.managers.PopUpManager;”):
    PopUpManager.createPopUp(this, ViewWindow, false);
  3. In your ViewWindow module you create a mx:image – let’s say we give it the id “Image2View”. This image will be loaded upon initialisation of the window via the init() function which is automatically executed when the module is called. We wil use the screenshot_path variable from the main application. To do that, we need to tell ViewWindow from where the variable is coming from: from the parent application. Appropriately, you can use the referrer ‘parentApplication’ :
    Image2View.load(parentApplication.screenshot_path);
  4. Upon closing the window (notice that we have activated the close button) we tell the popupmanager to remove this window.

See the full code for the ViewWindow.mxml below.

Categories
Programming

Using Adobe Flex to Show CSV to XML converted data

After having converted all your enormous spreadsheet data to xml using my python script csv2xml, what do you do with it ? Why, you display it using Adobe Flex of course ! Well, at least that’s what I did with my data (YMMV).

The following AIR tool displays issues that have been identified for a website. It uses an XML file on a windows file system as a source and a screenshot directory that shows screenshots linked to the issue description.

Here’s how my user interface looks like after a few iterations; the goal is to show the key facts in the lines in the datagrid, with the issue description and other more detail fields to be filled in below the datagrid when a line is selected in the datagrid.

(click once to see more info, click then again for original large size picture – WordPress has changed how you publish pictures, and it’s annoying me a lot, but not enough to fix it)

The above shows a TabNavigator with in it

  • an Overview tab : this is the main pane that has an overview of the xml data in a layout that makes sense (at least sense for the data)
  • an Overall stats tab : this is based on the most important key field, being the status of implementation and the priority assigned to each item
  • a Stats – Filtered tab : this shows the same graphs as above but filtered based on the dropdown filters in the overview tab
  • and an About tab that gives you an explanation of how it works and incidently, where the free icons come from (Axialis).

Inside the overview tab I have identified the main fields I want to filter on and put them in drop-down buttons. The filters are cumulative, meaning once you use a filter, you can use another filter again on the remaining list of items. Once you are done filtering, you hit the reset button to restore the full list. This has the advantage of just using one filter function to call, each time giving it the previously filtered XML. The disadvantage is that you can’t easily select a different field from the same filter once used, and need to hit the reset button to restart (I keep a copy of the original xml list when starting out).

The data is shown in a datagrid, with the website field having a custom icon renderer that shows an icon for the url link. Clicking on a line in the datagrid shows you the relevant info fields below. If a screenshot of the page exists, the screenshot is shown dynamically on the bottom right.

The stats graphics are draggable. With the inclusion of a simple action script class, found here, and specifying which graphic you want to make draggable, my graphics can be dragged over to the desktop, and are saved as jpegs.

On the bottom of the pane you find 3 buttons : one to select the source xml file, one to select the directory that contains the referenced screenshots and one that lets you exit the application.

What’s still missing that I would like to implement ?

  • a search box : for that I need to figure out how to search inside xml nodes and which ones are important.
  • filters that can be reset individually (lots of work, I will probably keep it as-is)
  • so far this is read-only stuff, the most made comment is that writing back changes would be a great thing. Since excel is the masterfile, this is currently not possible without a major rewrite, however I have some ideas of connecting to databases using Cheetah and pyamf and pydobc !
  • a lightbox style overlay when you click on the thumbnail to see the original picture : I’m trying to get this programmed in, but it’s hard going for the moment as I’m just about done with this app for the moment.

What’s still not working as it should be ?

  • If the preferences file does not exist I get plenty of errors; these disappear once the screenshot path and xml file have been selected once. I think this means that my error checking for empty preferences files is not yet up to a good standard. Plus I cobbled the preferences programming together from different sources; a major review would be needed to fix this.
  • If a screenshot related to a quickwin does not exist, I want it to give a message instead of a broken image icon.
  • Sorting the data in the graphs; haven’t figured that out yet.
  • Exporting your selection to pdf. Printing it.
  • Must be a lot of others, but those are the most glaring ones.

Frankly, as this is the first major flex AIR application that I wrote, and the first time I worked with XML code, I hope you’ll excuse me for stating that the code is in a bit of a mess, and could use some cleanup.

For example, there’s a function that I could reuse a lot that I couldn’t be bothered about at the time to find out how to pass it the right variable in just the right way, so I just hit copy/paste of the same function five times with different starting variables (Yes – it’s blasphemy. Yes, I know. I still cringe when I look at it). As I said, I was a bit drained of getting Flex to work (or adapting myself to Flex).

However, I also found out by writing this that Flex can do some pretty nice stuff with just a few lines of code. Linking the graphics to the numbers was not so a big task as I feared. So in the end I’m pretty proud of it, and I learned a lot about xml and how to massage it and show it in Flex.

Should somebody be interested in parts of the code to have a look at, I’m willing to publish it and/or go over it, just drop me a comment. I just don’t think it’s very high quality code…

Categories
Programming

Version 1.8 of CSV2XML is out

Thanks to a comment from a user of the program who had problems getting the script to process csv files on the mac, I’ve updated the script to version 1.8 so it will now open them without first needing to save the file in unix format when exporting to csv from Office for Mac.

For those of you who noted the version skip, version 1.7 has not been released, but just includes a simple test to see if the first field is empty or not. If empty the line is dropped. It’s been commented out in the latest version. Since my hosting provider also does python, I have renamed the file to .txt. Simply rename it to .py to have it working.

csv2xml_v18

[For the Pythonistas : I’ve set the csv module to now open the files in read ‘universal’ mode]

Categories
Blog News Programming

Revoking a Flex 3 License Activation is not easy.

This is a bit of a weird story, which most people probably won’t have happened to them. Still for those out there in the same situation, this is what happened.

Previously I had bought the “Flex builder Standard edition”, which comes without graphic elements (bars, charts, pies, whatnot). In order to show the results of filtering in my flex program I found it didn’t do all I needed. So I purchased the Flex Builder Pro edition (the full build, not an upgrade).

When you register your products on the Adobe website, you can see on your adobe.com profile page that each flex builder product can be installed two times – typically used for installing once on Windows and once on Mac, so you can test your products on both environments. This suited me fine, as I have a windows XP laptop and an iMac.

Each time you install Flex builder, you can see in your profile page on Adobe.com that the license count for the registered product decrements by one. My standard edition was installed on both my Mac and my XP, so I had zero licenses left to install (which it showed on my Adobe profile page).

After buying the full Flex Builder, I no longer needed the Standard edition. So I wanted to uninstall and if possible sell the standard edition. So I searched for a deactivation routine inside of the Flex builder Standard edition. Most recent Adobe products like Photoshop and so on have online activation, but I did not find one, so I uninstalled my standard Flex Builder 3 completely, thinking that uninstalling would also revoke the used Flex license with the Adobe server. This does not appear to be the case, as the license count does not increase again.

Erasing the license key from your machine and replacing it with the full flex license also does nothing for the used-up licenses on adobe.com.

So in the end I asked for help at Adobe (Benelux). They too asked me if I could not start the deactivation routing, but admitted they did not have much training in supporting Flex builder. After some more mails and phone calls, the technicians could not help me further, and had no further information to give me, as Flex Builder is a server product, only used in big corporations ( I told them I had bought it in via the Adobe.be online shop as a retail customer, so it’s not only just for big corporations) . After inquiring internally, they told me the only support for Flex on the issue I was experiencing was in America, which I could try to call, but probably would not get in as I would need a support contract.

I reopened the by-now closed support case and wrote quite a lengthy mail explaining that I was not satisfied with the solution. An extremely helpful (dutch) lady has since then tried to help me and has herself contacted the Flex support guys.

It seems Flex is considered an enterprise product, so it is not supported by retail support people and you need an enterprise support contract.

However, the upshot of it seems to be that a normal uninstall should be sufficient. There should be no penalty or license deactivation apparently needed, you can reinstall the Standard edition elsewhere. However, I have not yet tried to sell my license, and probably will not for some time. I’m a bit scared of trying it, and not everybody around me is so deep into programming as I am…

All in all, I have mixed feelings about the support I’m getting for this issue. On the positive side, I was always courteously treated by the support people, and all of them were helpful (but in particular Helene was helpful above and beyond her duty, for which I thank her). On the negative side, it seems that Flex is not considered a retail product, although there are scores of people out there using it to create lots and lots of cool things with it in flex/flash.

Categories
Programming

Flexing my programming muscles

After writing the python program to convert the data to xml format, I started out to make a flex program that could display it in a neat way, with the hope of ultimately adding dynamic filtering and charting to it as well. I settled on some tabs and no menubar, so far.

One thing is for sure – the Adobe help system is quite good. That, coupled with lots of examples found on other peoples websites helped me make a program that did a lot of what I wanted (more on the final product in a later post). Originally, I started out in absolute mode, laying down my elements to the pixel perfect, specifying x and y. However, you soon enter into the hell of overlapping content coupled with multiple scrollbars that is set in stone on the users computer screen.That’s not what I want.

In the end I went back to drawing out my User-Interface with a combination of HBox and Vboxes (boxes that arrange content respectively horizontally or vertically), and specifying percentages that each element could take of the screen estate. This has the added advantage that when a user has a wider screen than 1024 pixels (which is my start requirement), the graphical elements rearrange themselves quite well.

One of the things that has bothered me the most to adapt to is how strongly each Actionscript variable is ‘typed’ to it’s element base. I lost count of how many times Flex complained to me that I was coercing some poor ‘exemelly variable’ to accept data from another variable from another ‘exemelly list’ type, and that this just wasn’t allowed… For example, if you create an XML list variable, you can’t assign an XML object to it (or part of it). Well, you can, but it’s not simple and you need to program extra code.
[Please feel free to correct me if you know better ways of doing this, I’m still a newbie at this]

In Python you assign a variable something, and Python takes care of it, the so called loosely-coupled binding. When I assign variable X the number 5 and later on add the fifth element from an array and that’s a number or something like a number, Python will happely convert the content of the fifth array element to numerical and add it to the 5.

In Actionscript this is much, much more rigid, and it’s a big pain in the behind to figure out what I am doing wrong and trying umpteen versions of the code before finally, at 0:30 at night getting it to work and *understanding* why Flex was complaining and fixing it. I do get the hang of it though, but it’s a different, more rigourous way of thinking.

Once the code works however, I’m astonished how fast I can set up new graphical elements and set dataproviders to them – in general mxml is just plain fun, actionscript is fun-hard, and they both deliver something that I wish Python had – a genuinely easy way of creating user interfaces.

I’ll post some more about the progress I’m making with creating this application soonish.

Categories
Programming

Converting xls to xml via csv using Python

The title says it all, really. I wanted to learn flex mxml and actionscript, and at the same time at work I was looking to access todo data kept in an excel sheet that is used by a bunch of people in different departments and represent it in a way that helped one make sense of it. Using Python, I wrote a script that converted the exported csv file to xml, using the header line in the csv file to construct the xml elements.

Rant : Flex 3 in the current version really is *not* good at connecting to databases directly – it always needs an intermediary solution like a server (cold fusion, php, pyamf) to connect to the data. When developing AIR applications, which are local flex applications, at least you have access to the local filesystem.

So, to get *something* into flex without a server, I wrote the following Python program. It’s for version 2.5 but I reckon it will work on other versions as well. It’s command line only, you run it with as input the csv file to be converted, and it writes it out to the screen. If you want to capture it to a file, just do a redirect to a new file like this :

csv2xml.py input.csv > output.xml

The xml is actually E4X, Ecmascript for XML. The csv file must have ; as a seperator, which is standard when you export to csv from Excel 2003.

I programmed in a few prettifiers, like replacing spaces with underscores and removing ( and ) from the xml elements, but if you use accents (é) in your headers or slashes (/) it will most likely bork on that – either that or you get a malformed xml file.

Click to see the attachment : csv2xml_v18. Since my provider also provides python server-side, I’ve renamed the .py file to .txt. Simply rename it to .py again. The previous version ( csv2xml_v16 ) is still here as well.

Of course, after writing this, I discovered that somebody had already had the same need, and has written a swc for flex to access excel files directly ! Still, it was a useful programming exercise for me, keeping me skills alive… and in case you were needing this, feel free to use this.