SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to call a JavaScript function using the flash.external.ExternalInterface; class

    Hi

    Could someone please tell me the proper syntax to use to call
    a JavaScript function called "refresh()" from my Flash movie using
    the import flash.external.ExternalInterface; class

    This is the function I want to call.
    The function is designed to refresh the webpge containing my Flash movie.

    Code:
    <script language="JavaScript">
    <!--
    
    var sURL = unescape(window.location.pathname);
    
    function refresh()
    {
        window.location.href = sURL;
    }
    //-->
    </script>
    
    <script language="JavaScript1.1">
    <!--
    function refresh()
    {
        window.location.replace( sURL );
    }
    //-->
    </script>
    
    <script language="JavaScript1.2">
    <!--
    function refresh()
    {
        window.location.reload( false );
    }
    //-->
    </script>
    </head>
    
    <body>
    
    <script language="JavaScript">
    <!--
        // we put this here so we can see something change
        document.write('<b>' + (new Date).toLocaleString() + '</b>');
    //-->
    </script>

  2. #2
    SitePoint Wizard jim_morrison3's Avatar
    Join Date
    Apr 2004
    Location
    UK
    Posts
    2,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Which refresh function do you wanna call ? there more than one in the code you posted, anyways ExternalInterface API has a call() method in which you can pass the function name as the parameter, in your case it would be

    ExternalInterface.call("refresh");
    Good Luck!
    There are things known and Things unknown
    And in between are the Doors.
    I love hand Coding.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    What I am building is a Flash presentation who's main swf is embedded
    in an HTML web page.
    When the page is loaded the main swf has a menu with two options -
    load swf A or load swf B
    Once swf A or B is loaded the idea is to have a button called
    "Back To Main Menu" (within A and B) that when clicked will call
    the refresh() function in the head section of the web page.
    This will reload (refresh) the web page, thus reloading the main swf!

    This is the function on the HTML page I need to call

    <script language="JavaScript1.2">
    <!--
    function refresh()
    {
    window.location.reload( false );
    }
    //-->
    </script>

    Could you please tell me the sintax to add to the A or B swf files,
    remembering that I need to call the refresh() function by clicking
    on a button (Back To Main Menu) within the swf

    I think it is something like the following but I'm not sure how to make it
    work via a button -

    import flash.external.*;
    ExternalInterface.call("refresh");

  4. #4
    SitePoint Wizard jim_morrison3's Avatar
    Join Date
    Apr 2004
    Location
    UK
    Posts
    2,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    myBtn.onRelease=function(){
    ExternalInterface.call("refresh");
    }
    Good Luck!
    There are things known and Things unknown
    And in between are the Doors.
    I love hand Coding.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried placing the following actionscript if my Flash movie

    import flash.external.*;
    myBtn.onRelease=function(){
    ExternalInterface.call("refresh");
    }

    And placed the following javascript in the head section of my webpage

    </script>

    <script language="JavaScript1.2">
    <!--
    function refresh()
    {
    window.location.reload( false );
    }
    //-->
    </script>

    and still nothing happens, not even an error message.

    Your help is appreciated!

    Regards mydogmax

  6. #6
    SitePoint Wizard jim_morrison3's Avatar
    Join Date
    Apr 2004
    Location
    UK
    Posts
    2,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check if allowDomain param in the html file is set to "always".
    Good Luck!
    There are things known and Things unknown
    And in between are the Doors.
    I love hand Coding.

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the entire code for my exported swf file -

    <script type="text/javascript">
    AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','850','height','550','title','prospectus','src','flash/newGems','quality','high','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','flash/newGems' ); //end AC code
    </script>
    <noscript>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="850" height="550" title="prospectus">
    <param name="movie" value="flash/newGems.swf" />
    <param name="quality" value="high" />
    <embed src="flash/newGems.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="850" height="550"></embed>
    </object>
    </noscript>

    For some reason it does not have an allowDomain param.
    Would it be possible to add it manually? And if so, could you edit the above
    as needed?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •