Insert Flash elements in the Editor as Dynamic Content

by: Allan Thræn

Here’s just a quick little piece of Dynamic Content I threw together yesterday together with a partner. It’s for when you want editors to be able to insert flash elements directly in XHTML fields. A bit like inserting images – except that instead of an <img> tag we now want <object> and <embed> tags.

FlashDC

The code for this is fairly straightforward :

namespace EPiServer.Research.DynamicContent
{
    public class FlashDC : IDynamicContent
    {
 
        protected PropertyDocumentUrl flash;
        protected PropertyNumber width;
        protected PropertyNumber height;
 
        /// <summary>
        /// Setup properties
        /// </summary>
        public FlashDC()
        {
            flash = new PropertyDocumentUrl();
            flash.Name = "Flash file ";
 
            width = new PropertyNumber(300);
            width.Name = "Width";
 
            height = new PropertyNumber(300);
            height.Name = "Height";
        }
 
        #region IDynamicContent Members
 
        /// <summary>
        /// We'll use the render method instead
        /// </summary>
        /// <param name="hostPage"></param>
        /// <returns></returns>
        public System.Web.UI.Control GetControl(PageBase hostPage)
        {
            throw new NotImplementedException();
        }
 
        public EPiServer.Core.PropertyDataCollection Properties
        {
            get {
                PropertyDataCollection pdc = new PropertyDataCollection();
                pdc.Add(flash);
                pdc.Add(width);
                pdc.Add(height);
                return pdc;
            }
        }
 
        public string Render(PageBase hostPage)
        {
            return string.Format("<object width=\"{1}\" height=\"{2}\"><param name=\"movie\" value=\"{0}\"><embed src=\"{0}\" width=\"{1}\" height=\"{2}\"></embed></object>", flash.ToString(), width.ToString(), height.ToString());
        }
 
        public bool RendersWithControl
        {
            get { return false; }
        }
 
        public string State
        {
            get
            {
                return flash.ToString() + "|" + width.ToString() + "|" + height.ToString();
            }
            set
            {
                string[] parts = value.Split('|');
                if (parts.Length == 3)
                {
                    flash.ParseToSelf(parts[0]);
                    width.ParseToSelf(parts[1]);
                    height.ParseToSelf(parts[2]);
                }
            }
        }
 
        #endregion
    }
}

And it’s registrered in web.config like this:

<add description="Displays a flash element" name="FlashPlugin" type="EPiServer.Research.DynamicContent.FlashDC, FlashDC"/>

 

Download the code and binary here.

30 January 2009


Comments

  1. Would be nice if instead of using embed & object tags it used something like SWFObject, to not break validation of pages.
  2. Sweet sample, Allan! Dynamic content has a lot of great applications. Huring, you would probably want to add additional properties, or simply modify the rendered markup to include browser-specific markup!
  3. Allan - shoudn't the dynamic content control know of it's CurrentPage? Today the pageFolder (when opening a file dialog) will not be correct, since CurrentPage defaults to StartPage.
  4. Mari: Yes, you are right. However, I think it's a general bug that Dynamic Content doesn't have the CurrentPage context on edit-time. Of course, one could make a workaround using cookies or session state to set the CurrentPage when editing - but that was outside the scope of this post.
  5. Really nice Allan!
  6. Great work. Really easy. Thanks!
  7. I've updated Allan's code to now use swobject, and added the ability to use Flash Video. http://www.frederikvig.com/2009/11/flash-and-flash-video-episerver-dynamic-content/
Post a comment    
User verification Image for user verification  
Allan Thræn

About me

I am a product manager @ EPiServer, with a passion for the more geeky side of things. My technical interests are typically focused around user problems, user experience,  search, information management, artificial intelligence and  personalization

On top of this blog I have the blog Allan On Technology and I often crosspost.

DISCLAIMER: Unless otherwise stated in the posts, this blog expresses my personal opinions, experiments and views, not necessarilly the views of EPiServer AB.

 1533 page views this week.

 

 

Syndications


Archive


Tag cloud

EPiTrace logger