Flex, IFrame and SWFObject

I know that there are quite a few associate problems with IFrames and Flex. Unfortunately it was a must for one application I was working on. My problem arose when I re-wrapped my swf up using SWFObject. As you can see from my post I had some good help but it overrode the logic laid out by flex-iframe by hardcoding in the CSS for the iframe in the html. But as Aran quite rightly pointed out, it was down to the method in the iframe to position it correctly. After some trial and error I found the blighter that was causing the issue with IFrames in Flex whilst using SWFObject in particular.

In the main html the main culprit is this, ensure the below DOCTYPE:

HTML:
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

In the IFrame.as change the FUNCTION_MOVEIFRAME string to the below to ensure correct positioning if your altering the position of the main html content or nested object i.e. html, body { height:100%; text-align: center;}:

Actionscript:
  1. // Thanks to http://code.google.com/p/flex-iframe/issues/detail?id=20
  2.         private static var FUNCTION_MOVEIFRAME:String =
  3.             "document.insertScript = function ()" +
  4.             "{ " +
  5.                 "if (document.moveIFrame==null)" +
  6.                 "{" +
  7.                     "moveIFrame = function(frameID, iframeID, x,y,w,h) " +
  8.                     "{" +
  9.                         "var frameRef=document.getElementById(frameID);" +
  10.                         "var flashMovie=document.getElementById
  11.                              ('"+Application.application.id + "');" +
  12.                         "frameRef.style.left=x + flashMovie.offsetLeft;" +
  13.                         "frameRef.style.top=y + flashMovie.offsetTop;" +
  14.                         "var iFrameRef=document.getElementById(iframeID);" +
  15.                         "iFrameRef.width=w;" +
  16.                         "iFrameRef.height=h;" +
  17.                     "}" +
  18.                 "}" +
  19.             "}";

I am yet to test on all browsers!

example + source

This entry was posted in Flex, SWF Object and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>