1 Reply Latest reply on Nov 2, 2007 3:48 PM by teufelsdroekh

    GWT integration: Calling FABridge from an iframe to set property

    teufelsdroekh
      Hi,

      I am currently writing a GWT library for the integration of FABridge. I use the simple example from Adobe as a test case, especially the creation of a dataGrid within app.swf. Everything works fine, as long as I do not try to set Actionscript properties. After many hours of testing I could isolate and reproduce the problem even without using GWT. The problem is this: Setting object properties or calling methods that expect objects as parameters does not work, if the FABridge is called from an iframe (everything else works).

      In Firefox "Error calling method on NPObject!" is thrown, when the FABridge tries to set the ASProperty (line 289). In my test case a "Too many recursion" error is thrown as well. This does not occur, if I use GWT.

      In the Adobe example a grid and two columns are created. In the next line the columns property of the grid is set:

      grid.setColumns( [col1, col2] );

      To use this in an iframe, we have to call the FABridge in the parent window, so the code looks slightly different, but the above line still looks the same. Everything works except for this last line, which causes Firefox to throw the Error.

      Please take a look at this. I have uploaded a demo with two javascript functions: One within the top window and one within an iframe. Both contain the same code, but only the former does work.

      regards,
      Christian Voigt
        • 1. GWT integration: Calling FABridge from an iframe to set property
          teufelsdroekh Level 1
          I have found the problem: Arrays from other windows (such as iframes) are not detected as Arrays in the serialize method of FABridge. Instead they are serialized as FABridge.TYPE_ANONYMOUS.

          The line that causes the problem ist line 516:
          else if (value instanceof Array)

          The solution to this problem can be found here.

          Arrays which have been created in a different window object have a different Array.prototype, so that "instanceof Array" fails if it is called in another window where it refers to this windows prototype. A simple but not very clean solution is to change the line to something like this:
          else if (value instanceof Array || typeof(value.sort) == "function")

          A more complicated solution is to write a custom "typeof" method which does not detect Arrays as "objects" but as "arrays".
          Such a solution can be found on Douglas Crockfords page.

          I have updated my example with the simple solution. It would be nice if this would be considered in the next version of FABridge to make it "frame-safe"

          regards,
          Christian