Adapting html onclick code to Flash button
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Adapting html onclick code to Flash button

  1. #1
    Member
    Join Date
    Mar 2000
    Posts
    76

    Adapting html onclick code to Flash button

    Hopefully there is a simple solution to this. I have the following onclick HTML code that I'd like to get working in a flash environment:

    <a href="#" onclick="jwplayer().load('movie.mp4')">Click Here</a>

    I am familiar with the following kind of button code for Flash, but am open to any ways if they work better:

    on (press) {
    getURL("index2.html");
    }

    I tried the following code, but it only works in Safari:

    on (press) {
    getURL("javascript:jwplayer().load('movie.mp4')");
    }

    If I have not gone in enough detail for the HTML code, here is some more code to put it into context:

    <div id="container"></div>

    <script type="text/javascript">
    jwplayer("container").setup({
    autostart: true,
    flashplayer: "/jwplayer/player.swf",
    height: 270,
    width: 480
    });
    </script>

    <a href="#" onclick="jwplayer().load('movie.mp4')">Click Here</a>

    Thanks!

  2. #2
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849
    The first thing to try would be to set allowScriptAccess on your Flash movie to "sameDomain", or "always". This goes in the HTML, either in your SWFObject setup, or in the HTML, depending on how you're embedding your .swf.

    If that alone doesn't work, try ExternalInterface (a way to call Javascript from Flash).

    Set up a function in your page, say something like:

    Code:
    function playMovie(movieURL){
      jwplayer().load(movieURL)
    }
    Then in your Flash...

    Code:
    on(press){
    ExternalInterface.call("playMovie", "movie.mp4")
    }

  3. #3
    Member
    Join Date
    Mar 2000
    Posts
    76
    Unfortunately, the code:

    on(press){
    ExternalInterface.call("playMovie", "movie.mp4")
    }

    ...does not seem to do anything.

    I put:
    function playMovie(movieURL){
    jwplayer().load(movieURL)
    }

    in the head tag of the html, inside a <script language="JavaScript"> tag.

    Any other ideas?

    Thanks.
    Last edited by DjBobo; 04-28-2011 at 01:46 PM.

  4. #4
    Senior Member
    Join Date
    Apr 2002
    Posts
    2,849
    Well I'd need a little more info than that...how bout posting your entire Actionscript? How about posting a url so we can look at the Javascript and see that you turned set allowScriptAccess?

  5. #5
    Member
    Join Date
    Mar 2000
    Posts
    76
    Ok, so I have on a button symbol in Flash:

    on(press){
    ExternalInterface.call("javascript:jwplayer().load ('dracula.mp4')");
    }

    .. and the full HTML Code is below:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>About the JW Player 5</title>
    <script src="Scripts/swfobject_modified.js" type="text/javascript"></script>

    <script language="JavaScript">
    function playMovie(dracula.mp4){
    jwplayer().load(dracula.mp4)
    }
    </script>

    </head>
    <body onUnload=fadeBack();>

    <script src="jwplayer.js" type="text/javascript"></script>

    <div id="container"></div>

    <object classid="clsid27CDB6E-AE6D-11cf-96B8-444553540000" width="738" height="271" id="FlashID" title="bottom">
    <param name="movie" value="bottom.swf">
    <param name="quality" value="high">
    <param name="wmode" value="opaque">
    <param name="swfversion" value="6.0.65.0">
    <param name="expressinstall" value="Scripts/expressInstall.swf">
    <object type="application/x-shockwave-flash" data="bottom.swf" width="738" height="271">
    <param name="quality" value="high">
    <param name="wmode" value="opaque">
    <param name="swfversion" value="6.0.65.0">
    <param name="expressinstall" value="Scripts/expressInstall.swf">
    <div>
    <h4>Content on this page requires a newer version of Adobe Flash Player.</h4>
    <p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
    </div>
    </object>
    </object>
    <br>
    <a href="#" onclick="jwplayer().load('dracula.mp4')">Load Dracula </a>

    <script type="text/javascript">
    jwplayer("container").setup({
    autostart: true,
    flashplayer: "player.swf",
    file: "ned.mp4",
    controlbar: "bottom",
    height: 548,
    width: 700
    });
    swfobject.registerObject("FlashID");
    </script>

    </body>
    </html>

    ned.mp4 is a movie that autostarts, and then I have a thumbnail button in Flash which loads dracula.mp4

    Hopefully that is enough detail.

    Thanks.

Posting Permissions

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




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com