Skip to main content
Inspiring
January 12, 2011
Question

AS3 call javascript limit?

  • January 12, 2011
  • 2 replies
  • 2166 views

I try to call Javascript in AS3,I want to setHomePage

--as3 code--

private function onMouseClick(event:MouseEvent):void{

ExternalInterface.call("fonk1");

}

--html code--

<LINK REL="stylesheet" HREF="/workshop/samples/samples.css" TYPE="text/css">
<STYLE>
@media all {
   IE\:HOMEPAGE {behavior:url(#default#homepage)}
}
</STYLE>
<SCRIPT Language="Javascript">
function fonk1(){
alert('1');
document.all.oHomePage.setHomePage(oHomeHref.value);
alert('2');
event.returnValue = false;
}
</SCRIPT>
</HEAD>
<BODY>
<DIV class="body">
<IE:HOMEPAGE ID="oHomePage" />

<label for="oHomeHref">Homepage URL:</label>

<input type=text id="oHomeHref" size="30" value="http://www.microsoft.com/">
<p>
<input type=button value="Set" onclick="fonk1();"> Set your homepage to the URL entered in the text field.
<P>

<P>

</DIV>
<div id="flashContent">
   <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" id="externalInterface" align="middle">
    <param name="movie" value="Demo.swf" />
    <param name="quality" value="high" />
    <param name="bgcolor" value="#ffffff" />
    <param name="play" value="true" />
    <param name="loop" value="true" />
    <param name="wmode" value="window" />
    <param name="scale" value="showall" />
    <param name="menu" value="true" />
    <param name="devicefont" value="false" />
    <param name="salign" value="" />
    <param name="allowScriptAccess" value="sameDomain" />
    <!--[if !IE]>-->
    <object type="application/x-shockwave-flash" data="externalInterface.swf" width="550" height="400">
     <param name="movie" value="Demo.swf" />
     <param name="quality" value="high" />
     <param name="bgcolor" value="#ffffff" />
     <param name="play" value="true" />
     <param name="loop" value="true" />
     <param name="wmode" value="window" />
     <param name="scale" value="showall" />
     <param name="menu" value="true" />
     <param name="devicefont" value="false" />
     <param name="salign" value="" />
     <param name="allowScriptAccess" value="sameDomain" />
    <!--<![endif]-->
     <a href="http://www.adobe.com/go/getflash">
      <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
     </a>
    <!--[if !IE]>-->
    </object>
    <!--<![endif]-->
   </object>
  </div>

above code which except swf code is from MIcrosoft MSDN, I run above code in IE8,when I click Set button,it can alert('1'),and set HomePage,and alert('2'). It runs well,but when I click swf,it also can alert('1'),but I don't see it set HomePage! and I don't see alert('2'). Where is wrong? Why Set button call call setHomePage and swf can't call setHomePage? Is there limits between HTML and SWF?  I am puzzled with HomePage for a very long time. How to correct above code?

Thanks

This topic has been closed for replies.

2 replies

Community Expert
January 12, 2011

Just pass the URL as an argument from SWF, i.e.:

ExternalInterface.call("fonk1", url);

Then in the JS:

function fonk1(url){

     document.all.oHomePage.setHomePage(url);

}

Inspiring
January 13, 2011

I have passed the URL as an argument from SWF, i.e.:

ExternalInterface.call("fonk1", url);

Then in the JS:

function fonk1(url){

     alert(url);      document.all.oHomePage.setHomePage(url); }

When I click the swf,it can pop alert information,but it don't execute document.all.oHomePage.setHomePage(url) ,where is wrong? How to correct my code? An example code is better.

Thanks

Inspiring
January 13, 2011

First of all, it looks like setHomePage is available in IE only.

Second, I would be extremely pissed off if it could be done the way you are trying to do it - it would be a huge security hole. I believe that this kind of functionality is available ONLY when user explicitly clicks on a DOM element.

kglad
Community Expert
Community Expert
January 12, 2011

oHomeHref.value is undefined unless your html button is clicked.