Flex bug: Occasional empty popups and tooltips

30 06 2008

OK, this is by far the strangest bug I’ve yet to find in Flex.

Sometimes when I loaded my application, my tooltips and my popups refused to render any content. They were just empty. (See the images below, both the good and the bad). And when I went to debug the application, the properties were still there as they should be, just without the text being rendered.

The closest thing I could find on this out there, were people who were getting a runtime error in Flex 2 when their Modules had problems with the singleton classes such as PopUpManager and DragManager. But then I did some more research and I realised [finally] the problem was that my embedded fonts weren’t always rendering after I loaded in a module.

Ohhhhhh.

So when I removed the embedded fonts, and bobs-your-uncle.

Still, I’d love to know if anybody else has come into this and ways around it…





Flex: Keeping the sort on a datagrid when you change the dataProvider

26 06 2008

Well, there’s a few things you have to dig out a little when it comes to working with the more useful datagrid events.

Say you want to extend the DataGrid into your own component. You want to know when the dataProvider has been changed, and you’d like the new data to be sorted by the previous sort.

The events are as follows:

First, when a dataProvider is changed, the DataGrid instance will fire an mx.events.CollectionEvent.COLLECTION_CHANGE event.

EG:

dataGrid.addEventListener(mx.events.CollectionEvent.COLLECTION_CHANGE, onDataGridDataChange, false, 0, true);

NOTE: Those extra parameters in the attached listener create a “weak reference”. This is to prevent memory leaks.

This signifies that the dataProvider has been changed (should check the “kind” property to ensure it is equal to CollectionEventKind.RESET).

Second, the actual dataProvider itself will fire a COLLECTION_CHANGE itself after it is sorted. In the datagrid listener, you can attach the listener to the dataProvider. When a column heading is clicked, the datagrid will do the sort then call a “refresh()” which will dispatch a CollectionEvent of kind CollectionEventKind.REFRESH.

EG.

private var currentSort:mx.collections.Sort;
private function onDataGridDataChange(evt:CollectionEvent):void
{

                //get the new data collection
                var ac:ArrayCollection = dataGrid.dataProvider as ArrayCollection;
                //attach the collection change event
                ac.addEventListener(CollectionEvent.COLLECTION_CHANGE, onCollectionChanged,false,0,true);

                //if a sort was in place before the data was changed, make sure you apply the sort to this new data
                if (currentSort != null)
                {
                    ac.sort = currentSort;
                    ac.refresh();
                }

}

private function onCollectionChanged(evt:CollectionEvent):void
{

	if (evt.kind == CollectionEventKind.REFRESH)
	{
		var ac:ArrayCollection = evt.currentTarget as ArrayCollection;

		currentSort = ac.sort;

	}

}




The oohs, aahs and waahs of working with the new RIAs

13 06 2008

Just went to an Adobe AIR camp the other day in Sydney.

I must say, the free t-shirts were a great touch. As much as I abhor supporting any company by wearing their brand name,  the triangular AIR logo is pretty nifty.

But I digress.

Even though you can’t look a gift horse in the mouth (or complain about a free lunch), I confess I was more than a trifle disappointed with the whole day.

To summarise, it was a free one day conference put on by Adobe to showcase AIR and relevant technologies.

It was hardly a cheap affair, so I cannot fault Adobe there, and clearly they are trying to introduce AIR as much as possible. Problem is, converts (like me) would have found little to keep them on the edge of their seat. The Adobe evangelists might be great at gathering new sheep, but the rest of the flock are getting restless.

OK, so clearly I’m the one with the problem. But hey, I’m a pretty straight up, garden type variety developer. And I’ve got to some point with Flex and the whole Flash world and gone, hang on, wtf, I need to use Flash Remoting but I don’t understand anything about how it works. Where’s the complete documentation on it? Where are the other developers who know anything about this stuff? I’m crawling through a wasteland of irrelevant Google results.

Imagine if you will:

You’ve started from the ground up, learning Flex. You got a book on Flex, researched it’s capabilities.

You’ve researched various server techniques to enable Flex to handle to goods. Everything out there seems to conclude that flash remoting (using remote objects) is THE solution to remote procedure calls. You’ll end up with cleaner code, and faster service than using Web Services or HTTP Services.

You’ve spent six months developing a sexy little product in flex and using flash remoting to interface with .net. To do this, you’ve used either WebORB or FluorineFx as a solution to handle the remoting (as per the Adobe documentation Flex.NET).

Then you’re going to deploy to Production. Hang on, am I exposing my data here to malicious attacks? Is this a vulnerability? If I deploy as an AIR application, what are the implications then? I want answers, but can’t find them.

I was hoping I’d get some answers at the AIR camp, and maybe I approached it the wrong way – by walking up and hassling Andrew Spaulding whilst he was setting up for his next presentation.  Come to think of it, I couldn’t have done it any worse. But hey, I’m a developer aren’t I?

There was one tidbit that was very interesting from Matt Voermann about skinning up using Flash CS3 – and I will blog it next.





Flex: 1120: Access of undefined property com

2 06 2008

OK, so I’m getting a little tired of this error.

If you too are seeing the hateful “1120: Access of undefined property …” without a line number in Flex, maybe I can help.

I’ve noticed strange happenings when in an ActionScript class, I import MXML components of my own design (I oft for the com namespace). I can’t say why this causes an error, and I cannot easily replicate it, but needless to say, this issue has kept me up. Generally, in my main script file, I have to use a redundant import statement to remove it.

So I have

import com.justinjmoses.packagename.*;

import com.justinjmoses.packagename.SomeClass;

Whenever I modify the main script file, it removes this redundant second import and then throws up the cryptic 1120 error without a line number to help. Imagine the woes for the next developer to work on the product if I didn’t document this highly unusual behaviour.

Another thing I found was once, in a module, importing MXML components and then intiatialising them in actionscript, was causing all my tool tips to die. Weird, huh? Literally, every time you’d navigate to the SWF, no matter the browser, all the tooltip data was removed, leaving small blank boxes. However, if you refreshed, the issue would intermittently go away.

Eventually I traced it to importing MXML classes into my actionscript, though I couldn’t identify exactly what part of it was causing the issue.

Unfortunately, this isn’t one of those small things you can replicate and post to Adobe, but hopefully we can all help each other out with this one.

If you’ve had this issue yourself, please add a comment about it. (Otherwise I’ll get paranoid it’s just me 😉