The issue is that you’re attaching the event listener to the component or the 
element.

postMessage is always fired on a Window object and you need to listen to the 
Window you are posting the message to.

If you are in an iframe, window.parent is the immediate parent Window which 
holds the iframe. window.top is the top-most window in the heirarchy 
(significant when you have nested iframes).

As long as you post to and attach the event listener to the correct Window 
object, you should be fine with going both into and out of an iframe.

Assuming you have only a single level of nesting of your iframes, you would use

myIframe.element.contentWindow.parent["postMessage"]("foobaz",'*’); to send a 
message out and in your code you would use 
window.addEventListener(“message”,myHandler);

To go in, you’d use 
myIframe.element.contentWindow.["postMessage"]("foobaz",'*’); and 
myIframe.element.contentWindow.addEventListener(“message”,myOtherHandler); 
Although presumably, you’d be in the inner iframe code and it would just be 
“window”.

HTH,
Harbs

> On Feb 22, 2021, at 9:14 PM, Bilbosax <waspenc...@comcast.net> wrote:
> 
> @Harbs, thanks for responding.  Please be patient because I am very new to
> this.  I have a couple of questions about this approach because it does not
> make sense to me.  I am not trying to communicate between different iframes,
> I am trying to get simple data OUT of an iframe, and back into my
> actionscript.  On the asdocs for IFrame, there is no mention of the event
> "message" in IFrame, and I can't get it to work.  Inside of the IFrame html
> file, I have tried all three of these:
> 
>        window["top"]["postMessage"]("foobaz",'*');
>        window.parent["postMessage"]("foobaz", '*');
>        postMessage("foobaz", '*');
> 
> In Actionscript, I have the following:
> 
>        map.addEventListener("message", mapsEventHandler);
> 
>        public function mapsEventHandler(event:Event):void {
>            trace("I Heard The Message");
>        }
> 
>        <html:Iframe localId="map" width="100%" height="100%"/>
> 
> In it's simplest form, if the IFrame component was able to hear the
> postMessage from the actionscript side, it should have traced out "I Heard
> The Message".  I know you are good at this stuff, what am I missing?
> 
> 
> 
> --
> Sent from: http://apache-royale-users.20374.n8.nabble.com/

Reply via email to