Open GoogleCodeExporter opened 8 years ago
"when the iframe is loaded from a different domain": can you tell how I can
reproduce
the issue ?
Original comment by Julien.N...@gmail.com
on 14 May 2010 at 3:53
I have an application hosted at http://www.mainApp.com/myApp.html. I have the
flex
app hosted on another appserver at http://www.reports.com/reports.swf. my
app.html
embeds the swf as below.
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="rpt_flexgui" width="100%" height="680"
codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
<param name="movie" value="http://www.reports.com/reports.swf?
hideHeader=true&dataURL=http://www.reports.com/data/" />
<param name="quality" value="high" />
<param name="wmode" value="opaque" />
<param name="bgcolor" value="#ffffff" />
<param name="allowScriptAccess" value="always" />
<embed src="http://www.reports.com/reports.swf?
hideHeader=true&dataURL=http://www.reports.com/data/"
quality="high"
width="100%"
height="100%"
wmode="opaque"
name="rpt_flexgui"
align="middle"
play="true"
loop="false"
quality="high"
allowScriptAccess="always"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
Flex seems to be able to add the functions to the DOM. But when the browser
tries to
call the swf back to set the id of the embedded object, it fails with a
crossdomain
fault.
you can replicate this by creating a html on your local desktop embedding a swf
from
another webserver.
Following are some changes I added, to get it to work ...
########IFrame.as###########
//
================================================================================
=====
====
// SWF embed object tracking
//
================================================================================
=====
====
/**
* The SWF embed object id.
*/
public static var applicationId:String = null;
/**
* The random string used to identify the right object.
*/
protected var randomIdentificationString:Number;
public function set htmlFrameId (id:String):void{
if (applicationId == null || applicationId == "") applicationId = id;
}
/**
* Get the embed object id.
*/
protected function resolveEmbedObjectId():void
{
if (applicationId == null)
{
try
{
randomIdentificationString = Math.ceil(Math.random() * 9999 *
1000);
ExternalInterface.addCallback('checkObjectId', checkObjectId);
ExternalInterface.addCallback('getMyObjectId', getMyObjectId);
var result:Object =
ExternalInterface.call(IFrameExternalCalls.FUNCTION_ASK_FOR_EMBED_OBJECT_ID,
randomIdentificationString.toString());
if (result != null)
{
applicationId = String(result);
logger.info("Resolved the SWF embed object id to '{0}'.",
applicationId);
}
else
{
logger.error('Could not resolve the SWF embed object Id.');
}
}
catch (error:Error)
{
logger.error(error.errorID + ": " + error.name + " - " +
error.message);
}
}
}
/**
* Receive information about a DOM object and test if this is this SWF
object.
*/
protected function checkObjectId(id:String, randomCode:Number):Boolean
{
trace(id + " - " + randomCode + " is being checked against " +
randomIdentificationString)
if (randomIdentificationString == randomCode)
{
return true;
}
return false;
}
/**
* Receive information about a DOM object and test if this is this SWF
object.
*/
protected function getMyObjectId():String
{
return randomIdentificationString +'';
}
########## IframeExternalCalls.as ############
/**
* The Javascript code to call to insert the function that prompts the DOM
objects
* to find the SWF object id.
*/
public static var INSERT_FUNCTION_ASK_FOR_EMBED_OBJECT_ID:String =
"document.insertScript = function ()" +
"{ " +
"if (document." + FUNCTION_ASK_FOR_EMBED_OBJECT_ID + "==null)" +
"{ " +
FUNCTION_ASK_FOR_EMBED_OBJECT_ID + " = function(randomString) " +
"{ " +
"try { " +
"var embeds = document.getElementsByTagName('embed'); " +
"for (var i = 0; i < embeds.length; i++) { " +
"var isTheGoodOne;" +
"try { " +
" isTheGoodOne = (embeds[i].getMyObjectId() ==
randomString); " +
"} catch(e){" +
//"alert('object check error: ' + err.message +'
:: ' + err.description);" +
"}" +
"if(isTheGoodOne) { " +
"return embeds[i].getAttribute('id'); " +
"} " +
"} " +
"var objects = document.getElementsByTagName('object'); "
+
"for(i = 0; i < objects.length; i++) { " +
"var isTheGoodOne; " +
"try{ " +
" isTheGoodOne = (objects[i].getMyObjectId() ==
randomString); " +
"} catch(e){" +
//"alert('object check error: ' + err.message +'
:: ' + err.description);" +
"}" +
"if(isTheGoodOne) { " +
"return objects[i].getAttribute('id'); " +
"} " +
"} " +
"} catch(err) {" +
//"alert('list check error: '+err.message +' :: ' +
err.description);" +
"} " +
"return null; " +
"} " +
"} " +
"}";
Original comment by vijai.fu...@gmail.com
on 4 Jun 2010 at 3:30
Attachments:
Also some of the fixes are to hanlde multiple embed tags on the same page....
Original comment by vijai.fu...@gmail.com
on 4 Jun 2010 at 3:33
Moved to https://github.com/nicoulaj/flex-iframe/issues/40
Original comment by Julien.N...@gmail.com
on 8 May 2011 at 1:15
Original issue reported on code.google.com by
vijai.fu...@gmail.com
on 17 Jan 2010 at 10:58