| m u s h i n |mu-shin.ca

 
June 12, 2009

Open Flash Chart container destruction bug

Category: Code, General — Tags: , , , , — Marc Trudel-Bélisle @ 10:23 PM

Open Flash Chart is a flash application that allows you to create graphs and chart by feeding data to it. Certain application, such as Piwik, are using it to display statistic in a quite nicer way than in an HTML table.

This week, Matthieu Aubry (the creator of Piwik) wrote me to ask for a hand to fix some wierd problem he had with errors popping on page changes (which are all AJAXified). Basically, same error popping a random amout of time on certain page changes.

The problem, which is in the way flash handles resize event, goes like this: OFC has an ExternalInterface that is called by the flash’s resize event handler to send back information data (basically coordinates) back to a javascript application (here is an example of such application). This implies that the embedded object has a relative width in percentage, so that you may resize the container (since you can’t resize the object itself).

But here is the technical problem that happens in Internet Explorer : if you destroy the container, it triggers a change size in the object (which is in pure logic terms correct – see it as passing from a fixed size to a null size), which triggers the event handler. Then the event handler calls the ExternalInterface, which creates a javascript segment on-the-fly which tries to access back to the object element and complete the javascript call… but at that point, the object is already gone.

Solution (in jQuery):

$("object").remove();
/* Then destroy the container afterwards */

Update : I talked with the main developer at OFC, and he should fix this issue directly in the AS code for the next release. A link to this page can be found in his help pages : http://teethgrinder.co.uk/open-flash-chart-2/jquery-resize.php

1 Comment »

  1. Here is the link for the fix in Piwik itself : http://dev.piwik.org/trac/ticket/798

    Comment by MT — June 13, 2009 @ 5:00 PM

RSS feed for comments on this post. TrackBack URL

Leave your comment

Powered by WordPress