Insert Flash The Correct Way

Evening Tip: Insert Flash The Correct Way

You create your site the right way. You follow all of the rules, so that in the end, you can proudly have a link to w3′s validator, confirming your site’s perfection. There’s just one problem: if you embed any flash into your page, you’ll get several errors. That’s because the embed tag is not a valid tag. You need to insert your flash the correct way!

What Not To Do

<embed
src="player.swf"
width="300"
height="300"
allowscriptaccess="always"
allowfullscreen="true"
/>

This is the simplified version. If you generate the default HTML web page directly from flash, it’s ten times more ugly. In fact, it just might be longer than this article – Just to embed a single flash file! And it doesn’t even do it with valid HTML (in fact 19 errors).

Errors

This is the result. As you can see, there are 6 errors. All 6 from the embed element (5 from the
attributes, and 1 from the tag itself)

What You Should Do

First of all, you shouldn’t use the embed tag at all. Forget it! Since we don’t have “embed” any more, we’re only left with the object tag. It’s a good thing that all browsers support it in some way!

Within the Object tag we will use the following attributes:

type=”"

data=”"

width=”"

height=”"

We’ll need to specify the MIME type of what we’re inserting. In this case, we’re inserting flash. So for the type attribute, we specify “application/x-shockwave-flash”. We declare the source through the data attribute. I think everyone can guess what the width and height attributes do. So this is how you should insert your flash, for validity:

<object
type="application/x-shockwave-flash"
data="flash.swf"
width="750" height="400">
<param name="movie"
value="flash.swf" />
</object>

You still need the <param> tag as well. Let’s test this new code now:

Validated

Final Words

Isn’t that “congratulations page” just so…validating? No pun intended. Anyway, I hope you found this to be useful, and have a great week!

Add Comment

Discussion 105 Comments

Comment Page 2 of 3 1 2 3
  1. Jay Salvat says:

    Thanks for the tip.
    Good to know.

  2. BroOf says:

    ;D short but informativ!

  3. Medium says:

    Supporting theese quick tips ;)
    Keep them comming.

  4. Dan says:

    Quick tips are goooooooo!

  5. NGP says:

    Keep the quick tips!

  6. spadez says:

    Very useful! The quick tips are great.

  7. Connor says:
    Author

    Yeah…You’re right W3C is the name of the World Wide Web Consortium. But I was more referring to their site’s validator. And their site is w3.org.

  8. Freddie says:

    I use swfobject (well I am trying to warn my clients to stop with Flash…) but this method is a rapid way to get flash on a page. Anyway the tips must go on. Thanks a lot

  9. Stephanie says:

    One thing to point out, an additional benefit of using the object tag is that object tags can be nested, making “graceful degradability” an automatic process.

    In one of the examples on http://www.w3.org/TR/xhtml2/mod-object.html, you can see how this can be used to smoothly degrade from a java applet to an embedded video file, to a still image, and finally to text. The user never sees the “alternate” versions unless the “better” versions can’t be displayed.

  10. Do not use this solution.

    Use either Flash CS3′s JavaScript solution or SWFObject. Using this tutorial as your sole means of embedding Flash is just insane.

  11. Shane says:

    Great tip !

    Thanks!

  12. seb says:

    It sould be clear by now that this tutorial is giving a bad advice. Many knowledgeable users have already pointed-out that this method does not work in Safari and FireFox, and therefore using SWFObject method is still the only “good” method for embedding Flash.
    Either nobody reads other people’s comments before posting theirs, or the “Great tip! thanks” comments that keep pilling-up are fakes.

  13. Rob says:

    As far as I know, this won’t work in all browsers. OBJECT and EMBED are supported (poorly) across browsers differently. W3C may insist on a particular method, but that doesn’t mean that IE6, IE7, and Firefox agree that they (W3C) are correct.

    I love the simplicity of the means you provided here – I just don’t think that any type of object embedding has such a clean, elegant solution (though I wish it did!). Sort of like trying to embed a video file… dear lord. The work you need to go through to make sure it’s cross-browser compatible is just ridiculous.

  14. Immy says:

    great tip…… tks a ton.

    can u also give some seo tips for a flash website? i mean i have my website — http://www.redesignyourbiz.com — which has the menu and other pages in one single movie. how can i score well with search engines?

  15. Maicon says:

    thank your for the tip.

  16. Ben G says:

    Nice little tip, thanks!

  17. w1sh says:

    Quicktips ftw.

  18. Timo says:

    Nice tip! Keep’em comming.

  19. Roc says:

    Great Tip!

    I have been searching for a while on how to embed flash and get it w3c valid.

    Thanks!

  20. Mark Steven says:

    I agree with some of the other commentators here – this is an odd tip when there is such patchy support for the object tag.

    It remains a frustration for developers that the slightly fiddly swfobject, or invalid code, are the best ways forward.

    Does anyone know what is being done by Adobe / W3C / browser vendors to improve the situation?

  21. Quick tips like these are a great idea.

    I also use swfobject as its easy to have alternate content that is SEO friendly..

  22. Wayne says:

    Awesome! Thanks, man, keep ‘em coming!

  23. SataFLASH says:

    nice & short… and usefull!!!!!

    tnx a lot 4 the tip!

  24. jh. says:

    saved my life today. thank you. appreciated.

  25. Fidgit says:

    @insic…. you’re awesome
    @dever… you’re not, you wiseacre

    Keep the tips – and Jeffrey – you’re right; there’s no such thing as “old news”

  26. Dever says:

    This is why I said it’s old news (look at the article’s date). I also use(d) swfobject (I really like that you can show something when flash is disabled or not present).

  27. Ron says:

    Problems I found with simular things to this while experimenting is with only object tags in a strict doc it won’t in many major browsers like ie and opera. If you add in noscript tags around such stuff it will work in them but then won’t validate. So I am still hunting for the right combination that validates, works in most browsers, and offers an option to get flash if needed.

  28. Apart from all the other comments, another thing I’ve noticed, is that it seems to load the flash file twice, according to Firebug.

  29. Rap says:

    nice tip! thanks!

  30. Thank you for this one, I never knew of this.

  31. Sumit says:

    Excellent Tips… Thanks

  32. cenovis says:

    Caveats, caveats, caveats… This is a downgraded version A List Apart’s Flash Satay, by “downgraded” I mean it omits bits of code that will cause movies implemented with this method to stop streaming in IE. You will not notice the lag with smaller movies, but with larger ones you will see nothing but a big blank area until the _entire_ movie loads. There is a way to get around this (see/google: Flash Satay,) but it requires a separate “preloader” for every movie and an extra line of markup in your HTML.

    Frankly, the whole thing is too much of a pain in the ass for me to bother with. I use conditional comments instead, which are sandwiched between simplified object and embed tags. No, it’s not ideal either, but all the other ways I’ve seen always involve more code and/or more work, making it a nightmare to maintain and read, and this way at least it validates!

  33. Aditya says:

    What cenovis said about this method of embedding flash is correct.

    ***THIS METHOD BOTHCES YOUR FLASH FILES. ESPECIALLY THE PRELOADERS WONT WORK IN IE, AND YOUR USERS WILL SEE NOTHING BUT A BLANK BOX TILL THE WHOLE THING LOADS***

    I spent many frustrating hours trying to figure out what the problem is, and all the while, this was right under my nose, causing me intense agony.

    Personally, and after this experience, particularly, I decided to stick with the code that Flash CS3 spews out. It may be large/overwhelming/blah blah, but it works like a charm in all browsers, and that is what matters: your users seeing what you want them to.

    Aditya.

  34. sachin says:

    It really helps, thanks mate

  35. PJ says:

    Very useful tip. Thanks for sharing.

  36. Jeff Livings says:

    Thanks for the tip. I have always hated how flash breaks the w3c validation page.

  37. AonMusician says:

    Oh Thanks very much I love this topic I have the serious problem about ajax loading my flash for many days I try to find the way to fix it but I can’t till I’ve read this topic wowww woww I can now thanks god.

  38. Nice, but this not funtion in ie6

  39. .rojas. says:

    Nice tip, I was working from the HTML publish from Flash and it was all messy, now that I’ve started to picking up some more clean coding everything seems to float easier, thank you to everyone who gives this value information out, you guys are great!

  40. Rudi says:

    Thanks, after I read this article, my flash header is perfect now.

  41. Cory says:

    thanx so much I was looking everywhere for this

    works perfectly

  42. Carlos Chee says:

    Finallly… valid flash syntax… any way to add fullscreen?

  43. Andrew says:

    great tip, thanks!

  44. Matt Stevens says:

    This is a very neat and tidy method, but it doesn’t take into account browser compatibility or checking for the correct flash version, which other methods do very effectively.

  45. fmloftvjayF says:

    [url=http://wicketstuff.org/confluence/display/~ultram4rt]ultram pain management ededgonzalez [/url] [url=http://wiki.hudson-ci.org/display/~propecia8hvg]order pharmacy propecia assurance [/url] [url=http://docs2.codecauldron.org/display/~tramadol45g]tramadol make you tired Trisha [/url] [url=http://www.jugindex.org/display/~tramadol8ik]pet dosage for tramadol WATERMARK [/url] [url=http://wiki.directi.com/display/~klonopin5uvf]order Klonopin cheap prerequisites [/url] [url=http://www.amwiki.de/display/~acomplia7ui9]buy cheap acomplia overnight DeCanio [/url] [url=http://www.jugindex.org/display/~viagra8ik]cheapest viagra in Amsterdam ao [/url]

  46. Lance says:

    Without a doubt the “standard” way of adding flash is SWFObject… in fact — now it’s SWFObject2 and there are plenty of “extras” you can do with it.

    I recommend checking out http://www.gotoandlearn.com

    Good stuff regardless

    L

  47. phil says:

    what a terrible tip

Comment Page 2 of 3 1 2 3

Add a Comment

To add a code snippet to your comment, please wrap your code like so: <pre name="code" class="html">YOUR CODE</pre>. You can replace the class name with "js," "css," "sql," or "php." If there are any "<" or ">" within your code, please search and replace them with: &lt; and &gt; respectively.