Skip to main content
Inspiring
March 24, 2012
Answered

ExternalInterface.call

  • March 24, 2012
  • 1 reply
  • 2698 views

this is not working what is the wrong in this code.

if i trace(urlPath) showing - null.

var urlPath = ExternalInterface.call("window.location.href.toString");

if(urlPath != "http://www.domainname.com/demo/test/welcome.swf")

{

          trace("Yes");

          pageMsg.text = "this is html"

 

}

else

{

          trace("no");

          pageMsg.text = "This is swf"

}

This topic has been closed for replies.
Correct answer Ned Murphy

this is my html code.

i put down. but i'm not working.

exactly i do't know. where put that code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

          <head>

                    <title>welcome</title>

                    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

                    <style type="text/css" media="screen">

                    html, body { height:100%; background-color: #ffffff;}

                    body { margin:0; padding:0; overflow:hidden; }

                    #flashContent { width:100%; height:100%; }

                    </style>

          </head>

          <body>

                    <div id="flashContent">

                              <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="360" id="welcome" align="middle">

                                        <param name="movie" value="welcome.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="welcome.swf" width="480" height="360">

                                                  <param name="movie" value="welcome.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>

<script type="text/javascript">

function windowhref()

{

    return window.location.href;

}

</script>

          </body>

</html>


I tested that html page code and it works fine.  I created a test document if you want to check it out.  Just click the green rectangle to have the url appear...

http://www.nedwebs.com/Flash/welcome.html

The swf contains a button mc named "btn" and a textfield named "url".  The code in the swf file is as follows...

btn.addEventListener(MouseEvent.CLICK, traceURL);

function traceURL(evt:MouseEvent):void {
    var urlPath = ExternalInterface.call("windowhref");
    url.text = urlPath;
}

You should be testing on a server using the html page if you are not already doing that.

1 reply

Ned Murphy
Legend
March 24, 2012

As far as I can tell, the call method is supposed to call a javascript function, an dthat function in turn should return a value.  So maybe you need to create a function in the javascript code that returns the window.location.href string and call that function.

Inspiring
March 24, 2012

i put this code in HTML but not working

<script type="text/javascript">

function window.location.href.toString()

{

window.alert(window.location.toString);

}

</script>

Inspiring
March 26, 2012

I tested that html page code and it works fine.  I created a test document if you want to check it out.  Just click the green rectangle to have the url appear...

http://www.nedwebs.com/Flash/welcome.html

The swf contains a button mc named "btn" and a textfield named "url".  The code in the swf file is as follows...

btn.addEventListener(MouseEvent.CLICK, traceURL);

function traceURL(evt:MouseEvent):void {
    var urlPath = ExternalInterface.call("windowhref");
    url.text = urlPath;
}

You should be testing on a server using the html page if you are not already doing that.


Thank you. its woking...but...

actually  i'm doing like domain chekker.

i'm calling original swf into dummy swf through using urlLoader.

so my dummy swf file should run in html or aspx page, but if any one copy that original swf path & enter that path in browser when original swf redirect to my homepage like www.mydomain.com.

how to do that..