Symmetri Developer Blog

November 4, 2009

Using a Flash symbol from an SWF as the background for a UIComponent using styles

Flash/Flex - By Shourov Bhattacharya

You can use a Flash movie clip from within an SWF as the background for a component in Flex. First, you must create the symbol in Flash and then be sure to create a linkage for the symbol (Export for Actionscript etc.) and give it a unique name; then publish the Flash movie as a SWF. Within Flex, the background can be set up as part of a style in the CSS stylesheet - but the part that had me stumped was that instead of using background-skin, you must use background-image. That is, the following code is correct and will work:

.bubble
{
    background-image: Embed(source=../swf/bubble_skins.swf, symbol=bubble);
    background-alpha: 1.0;
    background-size: 100%;
}

The following code will NOT work:

.bubble
{
    background-skin: Embed(source=../swf/bubble_skins.swf, symbol=bubble);
    background-alpha: 1.0;
    background-size: 100%;
}

Dividing the perimeter of an ellipse into equal segments

Flash/Flex, Algorithms - By Shourov Bhattacharya

Suppose we want to lay out N number of objects on the perimeter of a circle, equally spaced. Finding the position of each object is trivial; we simply divide the total angle 2*PI by N and then draw out a point at the constant radius at that angle. However, doing the same thing on an ellipse is surprisingly tricky. Using the same algorithm as the circle in polar form does not yield the right results; the points end up “bunching up” on the minor axis. To find the correct algorithm, we need to think parametrically - we parametrize the elliptical curve by a variable theta and then plot points at equadistant intervals projected on the linear axis of theta:

var theta:Number = (Math.PI*2)*(i/NUMBER_OF_SEGMENTS) - Math.PI/2;
var a:Number = 100;
var b:Number = 80;
var x:Number = a* Math.sin(theta);
var y:Number = b*Math.cos(theta);
var point:Point = new Point(x, y);

October 13, 2009

Duplicate event listeners in Flex?

General, Flash/Flex - By Shourov Bhattacharya

Does adding the same event listener multiple times to a Flex object cause multiple, duplicate postbacks? I didn’t know for sure, but I just tried it and the answer is (thankfully) no. Let the good times carry on, then.

October 8, 2009

Banking site that uses Flex

General - By Shourov Bhattacharya

We just joined UBank and I noticed that their secure online banking site uses Flex within the HTML page as the most important and functional part of the interface. You can’t see what I mean unless you are a customer and have a valid login … and I realize this is hardly exciting to anyone else but me. But having created a series of real-world Flex applications over the last year I was happy to see that the most”serious” type of online applications are now starting to move in the direction of becoming RIAs.

October 5, 2009

Adding same child to Container twice gives error “Error #2006: The supplied index is out of bounds.”

Flash/Flex - By Shourov Bhattacharya

I thought I would document this as I think the error message is rather unhelpful and even misleading. In Flex, say you add the same child DisplayObject to a Container:

// container is of type Container
// child is of type DisplayObject
container.addChild(child);
container.addChild(child);

you get the error message “Error #2006: The supplied index is out of bounds.” That’s not a particularly helpful message, because it’s a very general error that is generated inside the Container.addChildAt() method; even though you are not explicitly defining a child index, the error is related to indexing of the array that holds children of the container. You would get the same error if you tried to use container.addChildAt() and specified an invalid index.

A better error message for this case would be something like “Duplicate child object not allowed in single instance of Container”.

October 1, 2009

Flex CSS property font-family is case-sensitive!

General, Flash/Flex - By Shourov Bhattacharya

This is just a little thing, but I have noticed that it isn’t widely understood. When using CSS in Flex to style components, the font-family property can be case sensitive on some operating systems. For example, the following CSS will not work on my Safari browser with Flash Player 10:

.content{font-family: arial;}

but this will work:

.content{font-family: Arial;}

Flex Layout with draggable, resizable components

Flash/Flex - By Shourov Bhattacharya

I have been looking for a way to layout elements (child components) within a Flex container that is flexible, resizable, draggable and visually impressive. The main requirements are that a) the individual child elements can be reordered with drag-and-drop, b) elements can be maximized/minimized, c) elements can expand to fill the available space and d) elements can be given a default width and height.

Unfortunately, none of the native Flex components have layout algorithms that are suitable. They mostly implement absolute positioning or a simple vertical or horizontal “flow” layout which can fit elements into the parent container, but without any resizing.

Recently I have found a really nice implementation of layout within Flex called the Adobe Flex 3 Dashboard sample. It implements a “pod layout” which handles all my requirements EXCEPT for the fact that the individual elements (”pods”) cannot be given an initial/default width and height - they simply scale to each take up an equal amount of space within the parent container. The drag and drop functionality also has some nice animated effects.

September 22, 2009

SQL Server 2005 import from Excel can lose your data!

General, SQL Server - By Shourov Bhattacharya

I’ve been using SQL Server 2005 SSIS Import Wizard (the replacement for SQL Server 2000 Data Transformation Services (DTS)) lately to import data from Excel files, and I’ve come across a serious bug that should be documented. It appears that when importing data from a spreadsheet that is sparsely populated - having a lot of empty cells - the import process can fail to import some of your data. Specifically, if you have a column in your Excel spreadsheet that does not contain any data for the first 1000 rows (or even a few hundred - I have not been able to work out the exact threshold), then you may find that data in subsequent rows for that column is imported as NULL.

What is worse is that no error messages or warnings are shown, so you have no idea that anything has gone wrong. The only way to detect the problem is to manually compare the imported data row by row with the import data source spreadsheet.

This problem persists no matter what data type you might choose for the destination column.

Searching around in the forums for this issue, I have come across some talk of changing the connection string used to the OLEDB connection to include “IMEX=1″. That works fine if you are building a SSIS Integration Services package in the full version of SQL Server 2005. But there is no way to do anything like that in the SSIS Import Wizard - no access to connection strings and no way to choosing different providers for importing Excel files.

So I have found my own workaround which is quite simple. What I do now before importing any Excel sheet is to check the first few rows. If there are columns that have empty values in the first few rows, I check further down the sheet. If the same column has data further down, I know that I am in danger of losing it during the import. So I create a dummy first row of data that has all columns filled out with representative data. For example, if a column contains integers, I might put a 1 in the dummy row; if it is string data, just a few characters. This seems to make the import process less cavalier about ignoring data, and I find that all columns now import correctly for all rows.

After the import, I run a query to delete the dummy row of data.

The workaround is fairly simple, but I must say this is a horrendous bug. Not only is it a high impact bug but the user has no feedback that anything has gone wrong. This is on top of the problems I have had with arcane error messages when an import fails because of bad data; and problems with row delimiters when importing CSV files. I have lost confidence in the SQL Server SSIS import now. The old SQL Server 2000 DTS seemed much more stable and reliable. SQL Server 2005 has been generally good to use, but not having a reliable way to import data is a severe handicap and makes me less likely to continue using it.

By the way, you can find an excellent tutorial on how to use the new SSIS Import/Export Wizard in SQL Server 2005 here.

September 21, 2009

Download SQL Server 2005 DTS Wizard

General, SQL Server - By Shourov Bhattacharya

The Microsoft SQL Server 2005 Express Edition install does not automatically include the Data Transfer Services (DTS) package that allows you - for example - to easily import data from spreadsheets. That’s a surprise to those of us who are used to using DTS in the SQL Server 2000 Enterprise Manager. It turns out you can get a newer version of the DTS by downloading the Microsoft SQL Server 2005 Express Edition Toolkit from http://go.microsoft.com/fwlink/?LinkId=65111. - it’s a fairly big file of over 200MB.

After installation, the DTS Wizard is found at C:\Program Files\Microsoft SQL Server\90\DTS\Binn\DTSWizard.EXE. Unfortunately you can’t get full integration into Management Studio Express as we are used to in Enterprise Manager (right-click database->Import Data etc.) but you can create a shortcut to the wizard within MSE by going to Tools->External Tools->Add.

September 16, 2009

Flex AdvancedDataGrid issues and code quality

General, Flash/Flex - By Shourov Bhattacharya

There is a fair bit of chatter over at Adobe’s Flex blog about the Data Visualization Components and the AdvancedDataGrid in particular. Some developers have complained to Adobe about the number of bugs in AdvancedDataGrid and the slow pace of bug fixing; many have said that the ADG is basically unsuitable for production.

Here is another popular post that makes the point that the ADG (and the Flex framework codebase in general) is ill-designed and bloated.

I’ve just completed a commercial project which used the AdvancedDataGrid and Charting components from the Data Visualization libraries, and would like to share my view. Generally speaking, I felt that the experience was a positive one. There were bugs that I encountered and had to work around (such as this one and this one). I did have my share of WTF moments. But in the end I was able to get a complex visualization product out the door on schedule without hitting any real roadblocks. Some workarounds required creativity, but I never found myself stuck for a solution; I was always able to overload a method, extend a class or find an alternative way to get things working. Given the specifications for the project - delivering rich, interactive reports through the browser for a variety of client OSes and platforms - and the very tight timelines, I have to say that I was happy in the end that I chose to use Flex.

Here’s another point I want to make. Adobe has open-sourced the code for the Flex framework, and that is a positive development. Any negative comment about Flex framework code quality is offset by the benefit of transparency - for a .NET developer, the fact that we can read the framework code at all is a novelty. The big picture here is that we have a commercially developed codebase that is being poked and prodded to death by the developer community. Many of the concerns about code quality are valid, but I think Adobe has done the smart thing by throwing its baby to the wolves, as it were. In the long term, the Flex framework will be improved, and the engagement with the developer community - albeit negative in parts - will be a genuine differentiation between their RIA platform and the Microsoft competition*.

Also, I think the developer community as whole should has a collective personality that is hard to please. We software developers love to take other people’s code and tear it apart. What we see are the logical and design flaws, the shortcuts, the omissions and the lack of documentation. What we don’t see is the context within which the code was written in the first place - the deadlines, the commercial pressures, the collaborative environment, office politics and the whole zero-sum game of allocating finite resources between new development and support. That stuff can be mitigated but it can’t be eliminated. In the real world, code is never written in a vacuum, and no one has the luxury of getting their code exactly right.

Of course the Flex framework has flaws, and Adobe has a responsibility to the development community to listen to feedback and address issues in good faith. If they fail to do that, they deserve the bad reputation that would follow. But the real test of software is whether it gets the job done, not whether it violates the latest popular design principles or whether it conforms to one’s personal taste. By that yardstick, I give Flex a (qualified) thumbs-up based on the experience of taking two-and-a-half real-world Flex projects through to production.

One final point. I have done RIA projects in both Flex and Silverlight/WPF over the last year. Each experience has had its share of ups and downs, but neither has come out clearly better for me. As developers, we can’t write our own frameworks and SDKs - we have to work with the available alternatives. The Flex SDK may be flawed in absolute terms, but what is more important is its relative quality as compared to the competition. And that we can’t compare right now, because the .NET framework is a black box. I wonder, after Adobe’s move, would Microsoft consider making it transparent?

*UPDATE: Microsoft is indeed planning to release the codebase for the .NET Framework libraries. That’s great news, and an important step forward for the whole concept of open-source. It will generate a lot of goodwill for Microsoft.

Get free blog up and running in minutes with Blogsome
Theme designed by Janis Joseph