Flex / AIR / DataGrid / itemEditor bug?

16 04 2008

If you are using DataGrid in a Flex/AIR application, the chances are you will at some stage hit the following RunTime error…

TypeError: Error #1010: A term is undefined and has no properties.

.. with a traceback indicating the error occurred within DataGrid.as. At which point you will stare at your own code for a while and wonder why.

In my circumstance I pinned this down to clearing the contents of the data provider and repopulating when there is an item renderer active on the DataGrid. A use-case that probably doesn’t come up that often in web-based Flex apps, since if the user clicks another control to trigger an update, the item renderer is exited at that point and the edit committed prior to the dataprovider changing.

In an AIR app, we have native menus available to us. When the user employs native menu selection, the item editor remains active. If that menu option triggers a repolpulation of the data provider (use-case example File>Open), we then get the error.

The workaround is pretty simple. A call needs to be made to destroyItemEditor() on the DataGrid instance before repopulating it’s data. In a simple application this is no great problem. But if you’ve gone to the effort of using something like the PureMVC framework to separate Data Object from View Components, the data object isn’t supposed to have any knowledge of the view. So in my case thefix is quite crude - when issuing the open command, a notification to destory item editors will be issued so any view component that uses them may destroy their editor prior to the repopulation.

My contention is that it should be the responsibilty of the DataGrid to destroy the item editor if the dataprovider updates.

I have this logged as a bug with Adobe (SDK-15280), along with sample code demonstrating the issue. Feel free to review and vote for the bug if you are in agreement with my point and comment further therein if you disagree or have better suggestions to offer.



E4X delete… not so obvious… but easy

31 03 2008

I’ve just been trying to delete a node and all its descendants from an XML object selected on the value of an attribute. Having read the “ECMAScript for XML (E4X) Specification” (PDF) as linked to from the Flex documentation I expected to be able to write the following…

delete theXMLObject..*.(@id=="theIDtoDelete");

however the above code will generate the following Flash Player runtime error…

TypeError: Error #1119: Delete operator is not supported with operand of type XMLList

The solution is simple if not obvious. The above code should be rewritten to ensure a single node is returned rather than a list…

delete theXMLObject..*.(@id=="theIDtoDelete")[0];

Distilled from this actionscript.org thread.



finding documentation on implementing native menus in Flex/AIR applications

20 03 2008

When you come to build your first Flex/AIR application that needs a native menu (Application menu on a Mac, or Window menu on a Windows PC), you’ll probably find your way to the “Windows, menus, and taskbars” section within the documentation. From there you’ll navigate to “Working with native menus” and spend some time studying “Creating native menus” before going on to view the example code. At this point you’ll probably have a shock at how much AS3 code needs to be written to implement such a simple menu. Not at all what you are used to in Flex.

If you are thinking there must be a way to do this using a component. You’d be right, but it is documented in the “Using the Flex AIR components” “About the FlexNativeMenu control“section not the “Windows, menus and taskbars” section.



new SWFObject (2.0)

15 03 2008

The authors of SWFObject and UFO have been working hard on a new version released yesterday as SWFObject 2.0. The project is now on googlecode. Geoff’s announcement is here.

As stated in my earlier posts I consider use of SWFObject to be best practice for embedding SWFs in web pages.



what happened to my tweets?

11 03 2008

The dark bit of sky in this blog’s header contains a simple SWF generated from pure AS3 that uses the Twitter API to collect and display my history of twitter messages. Unfortunately there is now a cross-domain policy file preventing any SWF other than those hosted actually from the twitter.com domain from accessing the feed. Apparently due to a security issue. The current suggested work-around is for me to write a proxy php script to sit on my own server to relay the feed request. Which I might do if I can be arsed, but I’m feeling grumpy today so I’m more likely to abandon Twitter all together - not that I ever over used it.

Twitter development talk on google groups has a thread that reveals some of the thinking going into solving the issue.



thanks again for more poker

26 02 2008

Thanks to Sean for organising a second poker tournament and thanks to Adobe for sponsoring it once more. Last time I was a loser. Last night however I did a tad better. Still feeling a quite pleased with myself and slightly guilty for beating some far more seasoned players to get to the final table, then to be knocked out of the last six by the guy who went on to win the whole thing.

winner



DragManager workaround in final Flex3/AIR1

25 02 2008

With today’s availability of release versions of Flex 3 and AIR 1, I’ve finally had a chance to apply the DragManager workaround that I had a moan about last month.

The flex documentation presents three configuration options for DragManager in AIR projects

[Extract]

  1. Your main application file uses the <mx:Application> tag. In this scenario, you use the Flex drag-and-drop manager, and cannot drag and drop items from outside of AIR.
  2. Your main application file uses the <mx:WindowedApplication> tag. In this scenario, you use the AIR drag-and-drop manager, and can drag and drop items from outside of AIR.
  3. Your main application file uses the <mx:Application> tag, but loads the AIR drag-and-drop manager as represented by the mx.managers.NativeDragManagerImpl class. In this scenario, you use the AIR drag-and-drop manager, and can drag and drop items from outside of AIR.

Sounds all well and good. Except to use <mx:Application> within AIR, you lose functionality. For instance in my case while the window was re-sizeable, the content remained at the default size. What I really need is to use <mx:WindowedApplication>, but with the Flex DragDrop manager. A scenario not represented in the documentation.

Fortunately the workaround with files described in bug SDK-13983 so-far appears to work. However it is worth noting that in using it, a number of mxml tags change their namespace from mx to comps. In my case this affects

  • <mx:states>
  • <mx:transitions>

which then become

  • <comps:states>
  • <comps:transitions>

Possibly my reliance on this approach is due to the now legacy nature of the project - it was written in advance of the Apollo 1 alpha. However apart from this issue, very little has had to be re-written through the beta cycle of AIR.



A flurry of events : Adobe/Flash/Flex

21 02 2008

A busy few weeks starting tonight:

  1. [Thurs 21-Feb-2008] LFPUG - Thermo Special presentation from Adobe
  2. [Mon 25-Feb-2008] Adobe sponsored Pokercoder Tournament II  - you need to be a professional user of Adobe products to join in
  3. [Thurs 28-Feb-2008] LFPUG - presentations on ‘Successful Flash Games’ and ‘Practical Particle Effects with Flint’
  4. [Wed 5th March] FLUG - Beer, presentations and chat about Flex


losing access to Gemini

27 01 2008

Slightly off-topic for this site, but I am constantly amazed by the UK Government’s ability to waste money within it’s own operations and withdraw comparatively small amounts from really useful projects thus crippling them and the benefits about to be reaped from the investments so-far made. The UK’s funding cut is about to exclude us from the multinational Gemini project as reported on the bbc news site. This I think is particularly short-sighted (excuse the pun) and it feels like the rug being pulled from under us. Particularly after projects such as Galaxy Zoo have done such a good job of increasing awareness and participation in this science.

If you are UK based and wish to stand against this decision, there is a Downing Street petition you can sign. There is more information and more actions you can take on the save astronomy site.

Save Astronomy

The Gemini UK office home page.



bitten by the beta 3 DragManager Bug

24 01 2008

I’ve just found myself caught out by this bug (SDK-13983) in Beta 3 (released December 2007), and the quite substantial change in behaviour.

My application which is only a prototype - but quite heavy, was essentially built from Oct 2006 through to April 2007 and  worked happily in Apollo and in all AIR and Flex 3 releases since, until Beta 3, when the DragManagers of AIR and FLEX implementations diverged. The API remains pretty much the same, but the behaviour is quite different (documented here), and while my existing code compiles, it generates run-time error “ArgumentError: Error #2004: One of the parameters is invalid.” if the user dare drag my UI components, rendering it useless.

That it has been accepted as a bug and a fix/workaround created, and that that is visible in the public bug system is a good thing. It removes a lot of potential worry. That the fix is not available to the public (AFAIK we’ve had our last public beta before the final release) isn’t great for me as I am now in a catch 22.

  • The fix isn’t available to me until the final version is released.
  • I can’t continue to use my application compiled against Beta 2 as the install process for AIR currently demands Beta 3 of AIR
  • Beta 3 AIR  demands Flex Beta 3 SDK.

It’s late, so this is going on hold until morning, at which point I need to assess the impact and time required to make the changes to adopt the AIR drag-and-drop manager, or hold on until I can force the switch to the Flex drag-and drop manager when the final release is available. Or beg Adobe for access to a build later than 191577.