views:

2396

answers:

3

Hi Guys,

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

A: 

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.

tlatourelle
Thanks for your help Tom, I added your code to the object tag as illustrated above and it still doesn't work, maybe I'm doing it wrong?cheers,Keith
Keith Donegan
A: 

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.

Eibx
Thanks Eibx, unfortunately the company only gave me the flash banner, it's quite strange alright
Keith Donegan
Oh. I see, but you're welcome.
Eibx
+2  A: 

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');\"&gt;&lt;/div&gt;").
                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.

David Hanak
I tried the solution and it worked fine with Firefox 3.0.14 but not with IE7. Clicking the flash object in IE doesn't do anything. Bummer!
tzup
Have you checked if the created div is positioned properly? Perhaps it is not, because of how IE treats the 'position' CSS style. Try setting the position style of your body element to relative and see if that helps.
David Hanak