I'm trying to hard-code a .swf file into page.tpl, but I keep running into a swfobject error.

I have the following code in the head of my page:

And I have the following code further down in page.tpl:

var so = new SWFObject("http://websitehere.com/themes/flash/mid-banner.swf", "mid-banner", "894", "132", "8"); so.addParam("quality", "high"); so.addParam("wmode", "transparent"); so.write("flashcontent");

I'm getting the following error:
Line: 81
Char: 1
Code: 0
URI: http://websitehere.com/themes/miramwebs/flash/swfobject.js

Please help! Thanks.

Comments

onejam’s picture

You shouldn't try and put it in your page.tpl.php file. It's not the place for it whether it'll work or not. Why not stick that code in a block.

-----------------------------------------------------------------
We build engaging websites and intuitive designs that will benefit your business.
Duvien

i25’s picture

This was meant to be a quick fix until some more items can be developed for a block.

Antiquitties’s picture

I suspect you might have a path problem. Can you look at the source and see if this may be the case? Maybe change var so = new SWFObject("flash/mid-banner.swf", "mid-banner", "894", "132", "8");

Can you check what is at line 81 in http://websitehere.com/themes/miramwebs/flash/swfobject.js and a few lines above and below (post it here maybe).

What version of the swfobject are you using? In IE if you click on the error sign on lower left (the javascript error sign) you get more information.

Correct code should look like this:

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

<div id="flashcontent">
  This text is replaced by the Flash movie.
</div>

<script type="text/javascript">
   var so = new SWFObject("movie.swf", "mymovie", "400", "200", "8", "#336699");
   so.write("flashcontent");
</script>

I would double check two things: first check that the id is the same

<div id="flashcontent"> 

so.write("flashcontent");

And the second thing is the <div id="flashcontent"> ... </div> needs to be ABOVE the script, not below, because it will create problems (you cannot write to an HTML element that has not been loaded yet)

Please let me know if it helps.

Thanks,

Valentin

onejam’s picture

So should look something like this:

<script src="/themes/miramwebs/flash/swfobject.js" type="text/javascript"></script> 

<div id="flashcontent">Requires <a href="http://get.adobe.com/flashplayer/">flash</a> to view this content</div> 
<script type="text/javascript">
// <![CDATA[
var so = new SWFObject('/themes/flash/mid-banner.swf','mid-banner','894','132','8');
so.addParam('allowscriptaccess','true');
so.addParam('quality','high');
so.addParam('wmode','transparent');
so.write('flashcontent');
// ]]>
</script>

If you are going to copy this into a block, remember to use 'Full HTML' input format and not 'Filter' which will strip some of the code out when saved.

-----------------------------------------------------------------
We build engaging websites and intuitive designs that will benefit your business.
Duvien

i25’s picture

This is great... thanks guys.

The swf file is not displaying fine. However, the swf has a hyperlink in it that is not working. When I click on it, nothing happens. Does hard-coding the swf cause this, or is my problem something else? Thanks.

Antiquitties’s picture

I think it's a path problem again. Try to modify the swf to use full path http://www.... see if it works.

i25’s picture

I tried that and it did not work.

Antiquitties’s picture

Is it an external link, or a link to another flash movie? You could post the action script here if any.

Also, did you try it in different browsers ? For IE you could try internet explorer-tools-internet options-programtab-reset web settings.

If it's an anchor link (index.htm#anchor) then you could try changing


getURL("index.php#services"."_self");

to this

getURL("index.php#services"."_blank");

If you can post the code maybe we can help you more.

i25’s picture

Here is my code:

on(release) {
getURL("http://websitehere.com/resources/faq");
}

I've of course replaced the real website for the purposes of this post. I can manually browse to the url, so I know it exists.

Antiquitties’s picture

on(release) {
getURL("http://websitehere.com/resources/faq","_blank");
}

I read somewhere that flash has problems when accessing a website on a different domain.

i25’s picture

It's actually on the same domain. Should I try NOT hardcoding the entire url and using a relative path?

Antiquitties’s picture

You can try it with relative path, but is shouldn't be a problem. Does the link work when click it after just compiling flash, not in any browser? It should work there. If it does work, then check if you have firefox as default browser and try to set IE as default browser (not sure will fix it, but I read some people had problems with this).]

If the link doesn't work when building then there's something wrong with how you set-up the button, I don't know.

There's more info here: http://kb2.adobe.com/cps/141/tn_14192.html

i25’s picture

Strange...
It works perfectly from the swf itself. If I click on the links from Flash or if I browse directly to the swf in IE, it works fine.

Antiquitties’s picture

Try to debug unsing info from here: http://www.sephiroth.it/weblog/archives/2006/10/flashtracer_firefox_exte...

Or try changing the paths: instead of C:\blabla use C:/blabla, try the same with urls. (just shooting in the dark)

It's better if you can debug, you get more info, but it seems it's just a firefox problem? Or is it the source (how you embed it with the swfobject). Can you show the source? Maybe there's some styling on the div that has the swf.

i25’s picture

I'm still having problems with embedding an swf into page.tpl.php. I've made a few changes to the swf itself, hoping to fix the hyperlink issue, but now it won't even show up at all!

Can someone visit www.mwebdev.com/nt.html and take a quick look? The swf is supposed to be showing in that blank area immediately under the header images. Why is the swf not even showing up??? This is driving me crazy! Thanks guys!

danreb’s picture

There are 2 swfobject.js loaded into your site, you can see that by viewing the source, just remove the old version located here - " /themes/miramwebs/flash/swfobject.js " then try to insert this code into the head before the body tag:

<script type="text/javascript">
			var flashvars = {};
			var params = {};
			var attributes = {};
			attributes.id = "mid-banner";
			swfobject.embedSWF("/themes/miramwebs/flash/mid-banner.swf", "flashcontent", "894", "132", "9.0.0", false, flashvars, params, attributes);
</script>

and this for the body:

Please note that the div with an id of flashcontent will be replace by the actual flash file, you can also put alternate content in that area.

You can use this url to generate your code for swfobject

http://www.bobbyvandersluis.com/swfobject/generator/index.html

You can also read documentation for swfobject here - http://code.google.com/p/swfobject/

here's an example how I do it in my website:

<script type="text/javascript">
             var flashvars = {};
             var params = {};
             params.wmode ="transparent";
             var attributes = {};
             attributes.id = "Capul-FlashLogo";
      swfobject.embedSWF("/sites/all/themes/capul/media/Logo1.swf", "Capul-Logo", "949", "223", "9.0.0", "/media/expressInstall.swf", flashvars, params, attributes);
</script>

Then to the body it's coded like this :

     <div id="C-topwrapper">
         <div id="Capul-Logo"><!--// Flash Logo--></div>
         <h1><a href="/">The Capule&ntilde;o's Home Massage</a></h1>
     </div>

The div with an id of Capul-Logo will be replace by flash, if javascript is off, I have alternate logo to show to the user which is coded as background for C-topwrapper div, if css is off the H1 tag to the rescue with the name of the site - you can see it here - http://www.thecapulenos.com

danreb

i25’s picture

I used the generator that you linked to, and it now works great! Thanks for the link!