Insert Flash The Correct Way

Quick Tip: Insert Flash the Correct Way

Tutorial Details
  • Difficulty: Beginner
  • Completion Time: 15 Minutes

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!

Tags: Flash
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://alexcoleman.net Alex Coleman

    I love these little tips…quick and easy ways to verify your work or discover an alternate way to do things. Thanks.

  • http://www.chapi.de Tobi

    I always use swfobject for swf-files in html.
    http://code.google.com/p/swfobject/

  • http://www.detacheddesigns.com Jeffrey Way

    Everyone – If you enjoy these quick tips, please leave a comment and let us know. We’ll be experimenting with a nightly (hopefully) quick tip this week. If we find that you all like them, we’ll continue! Otherwise, they’re gone.

    Please leave a comment and let us know your thoughts! Thanks.

    -Jeffrey

  • jamie

    do you know of a way to include a flash file as a link. I want to display a thumbnail and when clicked on will bring up the larger image in the lightbox. Both images I want to be .swf.

  • http://elitestyles.co.uk Marek holeszowski

    Keep them coming, although they may be obvious to some im sure theres tips out there that would benefit everyone in one way or another

  • http://www.prestigebulletin.com Jonathan

    Funny as I read something similar, oh, maybe a two weeks ago and I forgot to bookmark it for later reading. So thanks Connor, just what I needed.

    Jeffrey Bring on the tips (Bit sized or Super sized – both are always welcome) ;-)

  • neil

    Keep ‘em coming.. I knew this one but i’m sure you have loads up your sleeves that I won’t know!

  • http://cyberantix.org Connor
    Author

    Glad you found this useful Jonathan.

  • rob

    great tip, very useful thanks!

  • Pingback: Inelastica - Blog sobre Cultura Gráfica! » Tip: la forma correcta de insertar flash

  • http://www.geekandhype.com pickupjojo

    Great tip, thanks for sharing! :)

  • Andrew

    These tips are of great importance. Cleaner code makes for a better WWW.
    It would be great to see something on a somewhat regular basis like this. Even the simplest of things can be new to a whole audience of people. Especially those of us who have been doing the “old” or “wrong” way for so many years.

    I can’t wait for more.

  • http://www.furleydelphia.com Furley

    inside the object tag you should put an image or something for those that dont have flash/need to upgrade

  • http://www.ben-griffiths.com Ben Griffiths

    Great little tip, thanks :D

  • http://thedailyapp.com Tommy M

    Of course post some quick tips! It’s better than not having any updates :) This was useful I’m sure for some people (I never use Flash).

  • http://myspace.com/wikkideclipse69 Chris

    We Like Tips!

  • http://cyberantix.org Connor
    Author

    You’re right Furley, but I figured that that wasn’t ‘quick’ enough ;)

  • Tyler

    Won’t this fall prey to the IE Click to Activate “feature?”

  • http://www.apostropheart.com/ Mike

    Is it not better to use swfobject to get around the activeX problem in good ole Internet Explorer?

  • http://www.danharper.me Dan Harper

    Thanks for this. And that’d be a great feature for the site!

  • Ibrahim

    Great tip, Keep them up Jeffrey :)

  • Kaia

    I really do enjoy these ‘quick tips’ and think they will be a great feature for the site! Keep ‘em coming!

  • demogar

    What about youtube? :P

  • Tim

    Great Tips!!!

    Though, I do think that a better solution for embedding flash in a page is through SWFObject. I would recommend looking into it and doing either a quick tip or full tutorial on it.

    http://code.google.com/p/swfobject/

  • http://www.rickety.us Rick

    Thanks for this tip. I will have to try it. I didn’t know there was an alternative to embed.

  • http://www.vintom.com Vin Thoms

    love the quick tips.

  • Andrew

    Love the tips! First thing i check when i get to work in the morning is the nettuts feed!

  • Dan

    +1 for more quick tips. These little tidbits are what make good coders great.

  • http://blog.dever.ro Dever

    Sorry to be negative, but your quick tip is kind of old news (more than a year) ;)
    I apologize to all the people that already posted and didn’t know about it.

  • http://www.detacheddesigns.com Jeffrey Way

    @Dever – I don’t think it is possible for a tip to be “old news”.

  • http://ha.xors.org Braden Keith

    keep em

    Dreamweaver will automatically prompt you to fix it if you do it wrong.

  • http://ha.xors.org Braden Keith

    @Jeffrey:
    Valid point! lol

  • http://ha.xors.org Braden Keith

    May I suggest as an improvement to the site, you make an easy way to where we can contact you. I’m not sure if my comment was lost in all of them or what, but I’d still love to hear from you Jeffrey via email if you will.

    I would appreciate it :D

  • http://www.detacheddesigns.com Jeffrey Way

    @Braden – Just emailed you.

  • Agi

    Forget the object method as it still has the problem of the users having to click on the flash to focus it plus too many browser’s handle the object code differently for it to be a successful implementation.

    just use swfobject – http://code.google.com/p/swfobject/

  • Jason

    Bookmarked!

  • http://talkingtofu2.iblogger.org Taylor Satula

    ghetto. :)
    Very helpful
    Will use

  • Khalid

    Does this work for FlashPaper documents as well? The only way I can get them to work successfully in Firefox and IE is to upload using Contribute software. I would love to just embed them directly from my code. Any ideas?

  • Robin

    This is actually still not the correct way to embed Flash. SWFObject must be used or your Flash will not operate correctly in Internet Explorer.

  • http://www.insicdesigns.info insic

    keep it coming. i like these feature of the site. quick tips for us. very helpful.

  • http://www.insicdesigns.info insic

    @Robin leave the damn internet explorer behind.

  • http://www.tasty.sk vlp

    Robin is right.

    Insic > you cannot leave the IE behind, because still most of the users are browsing with IE and you don’t want to lost them.

  • http://www.some1ne.com Fouad Masoud

    Ok worked fine for me, still the question that stopped me using this a year ago why doesn’t it support flashvars for firefox?

    any idea how this can be worked around?

  • http://www.some1ne.com Fouad Masoud

    Just got this from adobe live docs “FlashVars must be assigned in both the object and embed tags in order to work on all browsers.”

    http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00000668.html

    so again wont be using it, its either good old un-valid way or swfobject.

    though good post and keep em coming “meaning the quick tips”.

    Cheers

  • http://www.subooa.com mattems

    good tutorial but i think swfobject def takes the cake. Perfect solution and it does everything you need.

    1. ie activation problem
    2. cross browser
    3. can install flash if user doesnt have it.
    or
    gracefully show something to replace flash.

    :)

  • http://australia.delosgaia.nl hans

    Great info, works perfectly but I still don’t understand why Firefox don’t support
    Firefox is making a ness of the flash with this param
    This param is working great in IE7, Opera 9.5 and Safari 3.x.

  • http://www.storm-media.co.uk/ Mark McDonnell

    You’ll all have to keep using SWFObject for the time being I’m afraid as this solution only works for Internet Explorer.

    I really would have expected the author to have checked this method using both Firefox and Safari before telling people this is the correct way to embed flash?

    I’m sure that the people who don’t already use SWFObject appreciated this ‘tip’ but if the proposed solution isn’t cross-browser compatible then for me it isn’t a viable solution.

    Kind regards,

    M.

  • http://enhance.qd-creative.co.uk James

    Yep, very useful. I’m still a tiny bit anti flash (mainly because I am a real n00b in that area) but when I do get around to using it I’ll be using the methods described in this tut! thanks!

  • Pete

    This might be old news for some of you but Microsoft actually removed the ‘click to activate’ from IE in April this year!!

    http://blogs.msdn.com/ie/archive/2008/04/08/ie-automatic-component-activation-now-available.aspx

    http://www.adobe.com/devnet/activecontent/

    Obviously this relies on people to update their systems. Eventually though it will be a thing of the past :)

  • http://www.freshclickmedia.com Shane

    I’m not keen on flash either. Typically, as a user, I find flash sites use poor UI and annoy the hell out of me.

    That’s not really relevant though – I like the idea of the quick tips on nettuts.

    One more thing – it’s the W3C, not w3, though w3 is the domain name – perhaps that’s what you meant?