Categories

Partners
  • Free Flash Website

  • Website Templates

  • Desktop Wallpapers

  • Adobe Photoshop Tutorials

  • Bittorent and
    Google desktop programs

  • Free Stock Photos and Images

  • Adobe Photoshop Tutorials

  • Merry Christmas Tree

  • IPowerWeb Hosting
  • Search


    Advanced Search











    PSD to HTML

    SWFObject Examples
    Published  08/20/2006 | Macromedia Flash Player

    Download PSD File

       




    SWFObject Examples

    The previous example is all that you need for barebones usage of SWFObject. But what if you need to use some of the other parameters that Flash Player offers? SWFObject makes it very easy to add any extra parameter you may need.

    The following examples show a number of different methods you may wish to use to embed your Flash content.

    Simple Example Adding a Few Parameters

    In this example, I create a new SWFObject file and set quality to "low", the wmode parameter to "transparent", and alignment to "t":

    <script type="text/javascript">
    var so = new SWFObject("movie.swf",
    "mymovie", "200", "100%", "7", "#336699");
    so.addParam("quality", "low");
    so.addParam("wmode", "transparent");
    so.addParam("salign", "t");
    so.write("flashcontent");
    </script>

    You can find a full list of the current parameters and their possible values in the following Flash Player TechNote: Flash OBJECT and EMBED tag attributes.

    Passing Variables into SWFs Using the FlashVars Parameter

    Using FlashVars is the easiest way to get data from your HTML file into your SWF, but you can pass the data in only when your movie first loads. Normally, you would add a parameter called flashvars and then, for the value, pass a string of name/value pairs like this:

    variable1=value1&variable2=value2&variable3=value3  

    and so on.

    SWFObject makes this a bit easier by allowing you to add as many variables as you like in a similar manner in which you add additional parameters. Here is an example of passing values into your SWF using FlashVars:

    <script type="text/javascript">
    var so = new SWFObject("movie.swf",
    "mymovie", "200", "100", "7", "#336699");
    so.addVariable("variable1", "value1");
    so.addVariable("variable2", "value2");
    so.addVariable("variable3", "value3");
    so.write("flashcontent");
    </script>

    Once this is done, all of the variables you pass in will be available immediately inside the SWF. Just access them as you would any variable on the _root timeline. For more information on how FlashVars work, see this Flash TechNote: Using FlashVars to pass variables to a SWF.

    Pulling Variable Values from the URL String

    The SWFObject script comes with a function that allows you to pull variable values from the URL string. For example, suppose you have a URL like this:

    http://www.example.com/page.html?variable1=value1&variable2=value2 

    Using the function getQueryParamValue(), you can easily pull these values from the URL and then pass them into your SWF. Using the previous URL, you would have the following:

    <script type="text/javascript"> 
    var so = new SWFObject("movie.swf",
    "mymovie", "200", "100", "7", "#336699");
    so.addVariable("variable1", getQueryParamValue("variable1"));
    so.addVariable("variable2", getQueryParamValue("variable2"));
    so.write("flashcontent");
    </script>

    The getQueryParamValue() function also supports reading variables from location.hash, which is used sometimes when deep-linking into your Flash application.

    Article Series
    This article is part 3 of a 5 part series. Other articles in this series are shown below:
    1. JavaScript Flash Player Detection and Embedding with SWFObject
    2. How SWFObject Works
    3. SWFObject Examples
    4. Using Express Install with SWFObject
    5. Comparing SWFObject with Other Methods