Reputation: 3263
Problem: it is needed to send notification of an occurred event from external pivot.html hosted in iFrame to a Flex app for event handling.
I have a Flex app hosted in main.html . I also have pivot.html that is displayed in iFrame inside Flex app. Due to security domains I can send callback to Flex app ONLY from main.html . The problem is that I need to handle events that I receive on the component inside pivot.html in Flex app. So I would need to call main.html from pivot.html, and main.html will in turn call a function inside Flex app.
But how can I do it if I cannot call functions in main.html from pivot.html?
What needs to be done in pic:
Thanks
Upvotes: 1
Views: 170
Reputation: 3263
Answer on my own question (finally figured this out, hopefully it will help someone):
Define function to be dynamically injected
Injecter.as
...
public static var getIFrameWindow : String =
"document.insertScript = function ()" +
"{ " +
"getIFrameWindow = function(iFrameId){ " +
" var iframeWin;" +
" var iframeRef = document.getElementById(iFrameId);" +
" if (iframeRef.contentWindow) {" +
" iframeWin = iframeRef.contentWindow;" +
" } else if (iframeRef.contentDocument) {" +
" iframeWin = iframeRef.contentDocument.window;" +
" } else if (iframeRef.window) {" +
" iframeWin = iframeRef.window;" +
" }" +
" return iframeWin;" +
"}"+
"}";
public static var SETUP_CALLBACKS:String =
"document.insertScript = function ()" +
"{ " +
"var flexApp;" +
"setObjectID = function(value, iFrameId){" +
" var iframeWin = getIFrameWindow(iFrameId);" +
" iframeWin.addEventListener('pagechange', function pagechange(evt) {" +
" var page = evt.pageNumber; " +
" flexApp.currentPageChange(page);" +
" },false);" +
" flexApp = document.getElementById(value);" +
"}" +
"}";
...
Viewer.mxml
...
ExternalInterface.call(Injecter.getIFrameWindow);
ExternalInterface.call("setObjectID", IFrame.applicationId, iFrame.getIFrameId());
ExternalInterface.addCallback("currentPageChange", currentPageChange);
...
pivot.html dispatch an event to get currentPageChange function called in Flex App
function SomeEventHandler()
{
var evt = document.createEvent("CustomEvent");
evt.initCustomEvent("pagechange", true, true, "some_data_to_be_passed_here");
window.dispatchEvent(evt);
}
Upvotes: 1
Reputation: 8699
I think you can use postmessage communication.Try this https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
Upvotes: 0