8

When I receive Flash objects from my designer, it comes with an example HTML page which includes both <object> tags and <embed> tags as well as a whole heap of JavaScript. If I copy and paste this code in to my webpage, it works, but the code looks a mess (and there is so much of it!). If I remove the extra code and try either just <embed> or <object> on their own, it works in some browsers, but not others.

Is there a neat, minimal method that works in all the major browsers?

Zistoloen
  • 10,036
  • 6
  • 35
  • 59
Mark Hatton
  • 1,447
  • 10
  • 15
  • 1
    Might want to try StackOverflow, better answers can be found there for this question. – Kevin Jul 09 '10 at 15:41
  • Fair point - an SO search has revealed this question: http://stackoverflow.com/questions/2254027/which-browsers-support-the-embed-and-object-tags

    However, I would imagine that most webmasters asking this questions would come here first, rather than StackOverflow, so I will self-answer with a link to the SO question.

    – Mark Hatton Jul 09 '10 at 16:09

4 Answers4

5

SWFObject is what you're looking for. It's a JavaScript library that does all the cross-browser heavy-lifting. Simply include the JavaScript file in your page, create an element to be replaced in your source, and tell swfobject the name that that element and the path to the .swf file.

It does the rest.

<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
    /* path, replacement element, width, height, minimum flash version */
    swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0");
</script>

That's all you need. Well, that and an element (usually a div) with an id="myContent" on it. The element with that ID will be replaced with whatever embed tag setup your current browser prefers.

The documentation is awesome, you'll have it up and running in no time. And if you hit any snags, ask another question.

Zistoloen
  • 10,036
  • 6
  • 35
  • 59
Bryson
  • 2,480
  • 16
  • 23
4

There are some great answers to this already over at StackOverflow: https://stackoverflow.com/questions/2254027/which-browsers-support-the-embed-and-object-tags

Mark Hatton
  • 1,447
  • 10
  • 15
1

You may want to have a look at Flash Satay - it is dated, but it quite nicely shows the issues in getting Flash working in a cross-browser fashion.

Grant Palin
  • 2,726
  • 3
  • 28
  • 41
0

You can use one of the following resources:

Flash Embedding Cage Match - discusses the issues in detail and suggests some workarounds along with their pros and cons.

swfobject library [recommended] - draws inspiration from the above article and adds functionality which the above article left as an exercise.

SWFObject 2 HTML and JavaScript generator - is a wizard which generates swfobject markup (HTML and JavaScript). You can ditch swfobject by choosing "static publishing", the remove all JavaScript tags from the generated markup.

Salman A
  • 352
  • 2
  • 13