aip solutions developer’s blog

06/02/2009

Include flash content in html page

Filed under: JavaScript — Tags: , , , — Peter Assenov @ 11:12

Recently I’ve made a small research and found many JavaScript classes that include dynamically flash in HTML pages. Most of them were easy to use and offered reasonable compatibility with different user agents and platforms. That’s great, but as a javascript developer I need to know also what’s behind the scene. How they work and how easy for modification and upgrade they are. When a client comes and say “I need this feature” or “can you support also this browser…”- he does not care what great-open-source-class I use- he just needs the thing done and I need to be able to make it.

Here comes the tricky part…

I took the uncompressed version of one popular class- swfobject 2.1 and I was surprised- it was 23KB! Well I know that these days 23K  are nothing for the web bandwidth but if you gonna maintain the code- they are a lot.  Isn’t it all about checking if there is Flash Player present and if yes just replace the innerHTML of some DIV- sounds  not so complex to require 700+ lines of code. I said- that’s ok the volume is not important if the code is simple and understandable. I scrolled down the code and I saw the file is ending with:

                }
            }
        }
    };
}();

Well, this simple complexity test just adds more concerns… what is this complex logic that requires such nesting? Besides what is the point you declare a function just to execute it on creation- can’t you just write the code, or if you want to be more structured- use static class for example.

And the final blow was the conditional parsing/line 88/ for detecting the OS in Internet explorer. Come on we’re not here to show how great programmers we are we just need to replace the innerHTML of a DIV.

Its not that I don’t appreciate the work done by the guys- they are great and I’d like to thank them for sharing it with others, but it’s just not my vision how it should be done.

So I thought to myself- there must be a simpler way… I don’t need complex event management, onDomContentLoaded handling or dynamic DOM elements manipulations- they are all out of scope of flash inclusion class and besides I already have them in the API’s core/I will introduce it in another post/.

I created my own class nearly 9 times smaller and doing exactly what is needed- include flash content  into html page.

When I have time I will write some documentation but it is so simple that I think the usage examples should be enough. If not, one can always take a look at the code :) . Here they are:

Usage: http://blog.aip-solutions.com/wp-content/uploads/2009/02/dl.swf.htm Actually this was my class test page used in its creation,  so don’t take into account the visual.

Source: http://blog.aip-solutions.com/wp-content/uploads/2009/02/dl.swf.js

Hope will be useful to you…

Cheers,

Peter




1 Comment »

  1. Another post with deeper look on the class…

    Pingback by inside dl.swf « aip solutions developer's blog — 11/02/2009 @ 11:56

RSS feed for comments on this post. TrackBack URL

Leave a comment

Anti-Spam Quiz:

Powered by WordPress