Question

I have this code:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="300" height="250">
  <param name="movie" value="Spotify_premium_300x250.swf" />
  <param name="quality" value="high" />
  <embed src="Spotify_premium_300x250.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="300" height="250"></embed>
</object>

EDIT: Code from Tom

<object onclick="javascript: window.open('http://www.stackoverflow.com', _blank, 'width=1024, height=600, menubar=no, resizable=yes');" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="300" height="250">
  <param name="movie" value="Spotify_premium_300x250.swf" />
  <param name="quality" value="high" />
  <embed src="Spotify_premium_300x250.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="300" height="250"></embed>
</object>

I would like it as when a user clicks the flash object, it's opens a URL in a new window. How would I go about doing this?

Cheers, Keith

Was it helpful?

Solution

You can position a DIV over your flash object to capture the mouse click. To do this, you need to set the wmode of the flash object to opaque, and use some javascript to position the div. Here's a full example:

<html>
<head>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
    var flashvars = {};
    var params = {
        menu: "false",
        scale: "noScale",
        wMode: "opaque"
    };
    swfobject.embedSWF("MyFlashApp.swf", "swf", "300", "300", "9.0.0",
                       "expressInstall.swf", flashvars, params);

    $(function() {
        var swf = $("#swf");
        $("body").append(
            $("<div onclick=\"window.open('http://www.google.com');\"></div>").
                css({
                    position: 'absolute',
                    top: swf.offset().top,
                    left: swf.offset().left,
                    width: swf.attr('width'),
                    height: swf.attr('height'),
                    zIndex: 1
                })
        );
    });
</script>
</head>
<body>
<div id="swf"></div>
</body>
</html>

Note the use of swf.attr('width') instead of swf.width(), the latter returns 0, probably because it's too early to get the flash object's dimensions. Later on, when called by hand, it does return the correct value.

OTHER TIPS

You need to do this in the flash with ActionScript

btnMovieClip.onRelease = function(){
    getURL("http://www.yoururl.com");
};

Make a MovieClip that fills the whole scene, and give it the name btnMovieClip. Put the above code in a frame in your timeline.

It depends (doesn't it always?).

If you want the flash object to always open the same site you can create an on-click event for the object tag and have it run a JavaScript pop-up:

javascript: window.open('http://www.stackoverflow.com', _blank, 'width=1024, 
                        height=600, menubar=no, resizable=yes');

to open another site.

If you want the FLASH movie to open a link, depending upon what's clicked on you need to add a GoToURL action within the flash. You will need to tell that action to open in a new window.

Something like GoToURL('www.yahoo.com', true) where true is referring to opening in a new window.

However, since I do not have flash open my syntax is probably off.

Hopefully this is enough to get you started.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top