A problem occured while loading the plugin: krl_flickr_photoset -> : Assigning the return value of new by reference is deprecated on line 18
kelvinluck.com: Embedding flash in TXP
Get Firefox! creative commons

Embedding flash in TXP

Not only does kml_flashembed make it nice and easy to embed Flash files in your textpattern pages – it also produces validating markup and deals nicely with detecting the Flash Player and displaying a message to the user if it isn’t installed. This is thanks to Geoff Stern’s JavaScript which it uses to embed the Flash files.
But… There was a couple of little problems with the plugin. I have error_reporting set to E_ALL on my system and the plugin was throwing a couple of notices due to unset variables.
So I made a few little changes to the code – here it is in it’s new state:

 * Original code from Michael Bester:
 * http://www.kimili.com/journal/32/textpattern-plugin-kimili-flash-embed
 * Slightly adjusted to work when error_reporting is set to E_ALL

function kml_flashembed($atts) {

    if (is_array($atts)) extract($atts);
    $out = array();
    if (!empty($movie) && !empty($height) && !empty($width)) {
        $fversion     = (!empty($fversion)) ? $fversion : 6;
        $target       = (!empty($target)) ? '"'.$target.'"' : '' ;
        $fvars        = isset($fvars) ? explode(";", $fvars) : array();
        $height       = ($height{strlen($height) - 1} == "%") ? '"'.$height.'"' : $height;
        $width        = ($width{strlen($width) - 1} == "%") ? '"'.$width.'"' : $width;
        $id           = isset($id) ? $id : "fm_".$movie; // if no id is provided then default to the name of the swf being embedded which is hopefully unique
        # Convert any quasi-HTML in alttext back into tags
        $alttext      = preg_replace("/{(.*?)}/i", "<$1>", isset($alttext) ? $alttext : "");

        $out[] = '';
        $out[] = '<script type="text/javascript">';
        $out[] = '    // <![CDATA[';
        $out[] = '';
        $out[] = '    var flashObject = new FlashObject("'.$movie.'", "'.$id.'", '.$width.', '.$height.', '.$fversion.', "'.(isset($bgcolor) ? $bgcolor : "").'");';
        if (!empty($alttext))        $out[] = '    flashObject.altTxt = "'.$alttext.'"';
        if (!empty($play))           $out[] = '    flashObject.addParam("play", "'.$play.'");';
        if (!empty($loop))           $out[] = '    flashObject.addParam("loop", "'.$loop.'");';
        if (!empty($menu))           $out[] = '    flashObject.addParam("menu", "'.$menu.'");';
        if (!empty($scale))          $out[] = '    flashObject.addParam("scale", "'.$scale.'");';
        if (!empty($quality))        $out[] = '    flashObject.addParam("quality", "'.$quality.'");';
        if (!empty($wmode))          $out[] = '    flashObject.addParam("wmode", "'.$wmode.'");';
        if (!empty($align))          $out[] = '    flashObject.addParam("align", "'.$align.'");';
        if (!empty($salign))         $out[] = '    flashObject.addParam("salign", "'.$salign.'");';
        // Loop through and add any name/value pairs in the  attribute
        for ($i = 0; $i < count($fvars); $i++) {
            $thispair    = trim($fvars[$i]);
            $nvpair      = explode("=",$thispair);
            $name        = trim($nvpair[0]);
            $value       = trim($nvpair[1]);
            $out[]       = '    flashObject.addVariable("'.$name.'", "'.$value.'");';
        $out[] = '    flashObject.write('.$target.');';
        $out[] = '';
        $out[] = '    // ]]>';
        $out[] = '</script>';
        // Add NoScript content
        if (!empty($noscript)) {
            $out[] = '<noscript>';
            $out[] = '    ' . $noscript;
            $out[] = '</noscript>';
        $out[] = '';
    return join("\n",$out);
As you can see, the changes are very simple – just making sure that $fvars, $id, $alttext and $bgcolor are defined before they are used.
Here it is in action – embedding a little Flash movie I wrote which connects to the Flickr API to download the 6 most recent photos uploaded to Flickr. Refresh to see more photos – they are uploaded at an alarming rate!

Sorry, you require Flash 7 to view this movie.

Once again – props to Geoff Stern for his work on this cool and valid way to embed Flash in a page and to Michael Bester for bringing it to TXP in the form of an easy to use plugin.

  1. Kelvin –

    Thanks for the insight into the plugin! I’ve put together a new release that incorporates variations on your changes, which you can get here.

    The auto ID feature now strips any path and extension information, leaving just the filename to create the ID.

    BTW – I really like your New Zeland landscape photos. You should put together a photoblog with those.
    Michael Bester    Feb 24, 21:33    #
  2. Michael –
    Thanks for the response and for the updated release. I’m now using the new release on my site…

    And glad you like the photos :) Did you find this page where you can view all the headers at once? I’m planning on getting together some sort of photo site – that is partly why I have been playing around with Flickr…

    Rest assured I’ll post about it in my blog when I finally get around to building my photo site!
    Kelvin    Feb 28, 10:27    #