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?

2
  • 1
    Might want to try StackOverflow, better answers can be found there for this question.
    – Kevin
    Jul 9, 2010 at 15:41
  • Fair point - an SO search has revealed this question: stackoverflow.com/questions/2254027/… 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. Jul 9, 2010 at 16:09

4 Answers 4

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.

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

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.

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.