• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

AS3 call javascript limit?

Explorer ,
Jan 11, 2011 Jan 11, 2011

Copy link to clipboard

Copied

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

TOPICS
ActionScript

Views

2.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2011 Jan 12, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2011 Jan 12, 2011

Copy link to clipboard

Copied

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);

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 12, 2011 Jan 12, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 12, 2011 Jan 12, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 12, 2011 Jan 12, 2011

Copy link to clipboard

Copied

Is there another method to setHomePage in AS3?  Give me example code please,I have search Google for many days,but I don't find any answer for it.

Thanks in advance!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 12, 2011 Jan 12, 2011

Copy link to clipboard

Copied

I don't think it exists and I hope it doesn't because, again, it would be a big security violation if everyone were able to set my browser home page at will.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 12, 2011 Jan 12, 2011

Copy link to clipboard

Copied

Mr Andrei,

Thanks for your answer. During my working,customer ask me to design a function which click swf,it can set Home Page to Explorer. I'm puzzled with it for many days. Could you tell me how to do it or give me some example code?

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 12, 2011 Jan 12, 2011

Copy link to clipboard

Copied

Did you read my two previous posts?


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 12, 2011 Jan 12, 2011

Copy link to clipboard

Copied

>>I don't think it exists and I hope it doesn't because, again, it would be a big security violation if everyone were able to set my browser home page at will.

I know your mean. The reason why set  browser home page is customer wish when click setHomePage button in flash,it can set his page url into browser home page,next when open browser,it can visit the url.  I can't persuade customer to give up this function. Now I only want to know if there is a method can realize it in IE?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 12, 2011 Jan 12, 2011

Copy link to clipboard

Copied

The answer is still NO.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 13, 2011 Jan 13, 2011

Copy link to clipboard

Copied

LATEST

Looks like even if you call setHomePage() from DOM it fails. Even in IE6. This means you cannot do this any longer with or without Flash. I totally agree with Andrei - this is a bad practice some people used to do during the dark age of internet and thank god that's gone now.

Some consolations for you are that (A) you should still be able to do this from AIR by calling a BAT file, and (B) you cannot set an URL as homepage but you can as "favorite" (bookmark) - you can do this from Flash too.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines