<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jozef Chúťka&#039;s blog &#187; EmbedCode</title>
	<atom:link href="http://blog.yoz.sk/tag/embedcode/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.yoz.sk</link>
	<description>My life, my work</description>
	<lastBuildDate>Tue, 31 Jan 2012 12:40:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>EmbedCode class to generate html code</title>
		<link>http://blog.yoz.sk/2009/10/embedcode-class-to-generate-html-code/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=embedcode-class-to-generate-html-code</link>
		<comments>http://blog.yoz.sk/2009/10/embedcode-class-to-generate-html-code/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 11:27:21 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[embed]]></category>
		<category><![CDATA[EmbedCode]]></category>
		<category><![CDATA[generate]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[object]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=473</guid>
		<description><![CDATA[EmbedCode class generates html code for your .swf files. You can define url, size, parameters, flashVars and the result is valid standard (&#60;object&#62;, &#60;params&#62;, &#60;embed&#62;) html code, that you can just copy paste into your htmls, blogs, gigya widgets etc. sk.yoz.html.EmbedCode Application package sk.yoz.html.EmbedCode.as: Application code1.text: code2.text:]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.yoz.sk/wp-content/uploads/embedcode.png"><img src="http://blog.yoz.sk/wp-content/uploads/embedcode-200x101.png" alt="embedcode" title="embedcode" width="200" height="101" class="alignleft size-medium wp-image-488" /></a></p>
<p>EmbedCode class generates html code for your .swf files. You can define url, size, parameters, flashVars and the result is valid standard (&lt;object&gt;, &lt;params&gt;, &lt;embed&gt;) html code, that you can just copy paste into your htmls, blogs, <a href="http://www.gigya.com/">gigya widgets</a> etc.</p>
<ul style="float:left;">
<li><a href="http://classes.yoz.sk/sk/yoz/html/EmbedCode.as">sk.yoz.html.EmbedCode</a></li>
<li>Application</li>
</ul>
<div style="clear:both;"></div>
<p><span id="more-473"></span></p>
<p>package sk.yoz.html.EmbedCode.as:</p>
<pre class="brush: as3; title: ; notranslate">package sk.yoz.html
{
    import flash.display.LoaderInfo;
    import flash.net.URLVariables;

    public class EmbedCode extends Object
    {
        private var _params:Object = {};
        private var _flashVars:URLVariables;
        private var _width:uint;
        private var _height:uint;
        private var _url:String;

        private var loaderInfo:LoaderInfo;
        private var parameters:Object;

        public var encodeAmpersands:Boolean = false;

        public function EmbedCode(loaderInfo:LoaderInfo = null, parameters:Object = null)
        {
            super();
            this.loaderInfo = loaderInfo;
            this.parameters = parameters;

            useActualURL();
            useActualFlashVars();
        }

        public static function suggest(loaderInfo:LoaderInfo = null, parameters:Object = null,
            encodeAmpersands:Boolean = false):EmbedCode
        {
            var embedCode:EmbedCode = new EmbedCode(loaderInfo, parameters);
            embedCode.encodeAmpersands = encodeAmpersands;
            embedCode.useActualURL();
            embedCode.useActualSize();
            embedCode.useActualFlashVars();
            return embedCode;
        }

        public static function containsProtocol(path:String):Boolean
        {
            return path.indexOf(&quot;http://&quot;) == 0 || path.indexOf(&quot;https://&quot;) == 0;
        }

        public static function urlToDomain(url:String):String
        {
            if(!containsProtocol(url))
                return null;
            var index:int = url.indexOf(&quot;/&quot;, 9);
            if(index == -1)
                return null;
            return url.substr(0, index);
        }

        public function get domain():String
        {
            return urlToDomain(url);
        }

        public function addParam(param:String, value:String):void
        {
            _params[param] = value;
        }

        public function set params(value:Object):void
        {
            _params = value;
        }

        public function get params():Object
        {
            return _params;
        }

        public function addFlashVar(variable:String, value:String):void
        {
            if(!flashVars)
                flashVars = new URLVariables();
            _flashVars[variable] = value;
        }

        public function set flashVars(value:URLVariables):void
        {
            _flashVars = value;
        }

        public function get flashVars():URLVariables
        {
            return _flashVars;
        }

        public function get flashVarsQueryString():String
        {
            var queryString:String = flashVars.toString();
            if(encodeAmpersands)
                queryString = queryString.replace(/\&amp;/g, &quot;&amp;amp;&quot;);
            return queryString;
        }

        public function set width(value:uint):void
        {
            _width = value;
        }

        public function get width():uint
        {
            return _width;
        }

        public function set height(value:uint):void
        {
            _height = value;
        }

        public function get height():uint
        {
            return _height;
        }

        public function set url(value:String):void
        {
            _url = value;
        }

        public function get url():String
        {
            return _url;
        }

        public function toString():String
        {
            var key:String;
            var r:String = '';
            r += '&lt;object width=&quot;' + width + '&quot; height=&quot;' + height + '&quot;&gt;';

            r += '&lt;param name=&quot;movie&quot; value=&quot;' + url + '&quot;&gt;&lt;/param&gt;';
            for(key in params)
                r += '&lt;param name=&quot;' + key + '&quot; value=&quot;' + params[key] + '&quot;&gt;&lt;/param&gt;';
            if(flashVars)
                r += '&lt;param name=&quot;FlashVars&quot; value=&quot;' + flashVarsQueryString + '&quot;&gt;&lt;/param&gt;';

            r += '&lt;embed src=&quot;' + url + '&quot; width=&quot;' + width + '&quot; height=&quot;' + height + '&quot; type=&quot;application/x-shockwave-flash&quot;';
            for(key in params)
                r += ' ' + key + '=&quot;' + params[key] + '&quot; ';
            if(flashVars)
                r += ' FlashVars=&quot;' + flashVarsQueryString + '&quot; ';
            r += '&gt;&lt;/embed&gt;';

            r += '&lt;/object&gt;';
            return r;
        }

        public function useActualURL():void
        {
            if(!loaderInfo)
                return;
            url = loaderInfo.url;
        }

        public function useActualSize():void
        {
            if(!loaderInfo)
                return;
            width = loaderInfo.width;
            height = loaderInfo.height;
        }

        public function useActualFlashVars():void
        {
            flashVars = new URLVariables();
            if(!parameters)
                return;
            for(var key:String in parameters)
                addFlashVar(key, parameters[key]);
        }
    }
}</pre>
<p>Application</p>
<pre class="brush: xml; title: ; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;vertical&quot; applicationComplete=&quot;init()&quot; xmlns:html=&quot;sk.yoz.html.*&quot;&gt;
&lt;mx:Script&gt;
&lt;![CDATA[
    import sk.yoz.html.EmbedCode;

    private function init():void
    {
        code1.text = EmbedCode.suggest(loaderInfo, parameters, true).toString();

        var embedCode2:EmbedCode = new EmbedCode();
        embedCode2.encodeAmpersands = true;
        embedCode2.width = 100;
        embedCode2.height = 100;
        embedCode2.url = &quot;http://domain/my.swf&quot;;
        embedCode2.addFlashVar(&quot;myFlashVar&quot;, &quot;123&quot;);
        embedCode2.addFlashVar(&quot;mySuperFlashVar&quot;, &quot;okey&quot;);
        embedCode2.addParam(&quot;wmode&quot;, &quot;transparent&quot;);
        embedCode2.addParam(&quot;allowfullscreen&quot;, &quot;true&quot;);

        code2.text = embedCode2.toString();
    }
]]&gt;
&lt;/mx:Script&gt;
&lt;mx:TextArea id=&quot;code1&quot; width=&quot;100%&quot; height=&quot;100%&quot; /&gt;
&lt;mx:TextArea id=&quot;code2&quot; width=&quot;100%&quot; height=&quot;100%&quot; /&gt;
&lt;/mx:Application&gt;</pre>
<p>code1.text:</p>
<pre class="brush: xml; title: ; notranslate">&lt;object width=&quot;500&quot; height=&quot;375&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;file:///D:/work/flex/...swf&quot;&gt;&lt;/param&gt;&lt;param name=&quot;FlashVars&quot; value=&quot;isAdmin=true&amp;amp;isFacebook=true&quot;&gt;&lt;/param&gt;&lt;embed src=&quot;file:///D:/work/flex/...swf&quot; width=&quot;500&quot; height=&quot;375&quot; type=&quot;application/x-shockwave-flash&quot; FlashVars=&quot;isAdmin=true&amp;amp;isFacebook=true&quot; &gt;&lt;/embed&gt;&lt;/object&gt;</pre>
<p>code2.text:</p>
<pre class="brush: xml; title: ; notranslate">&lt;object width=&quot;100&quot; height=&quot;100&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://domain/my.swf&quot;&gt;&lt;/param&gt;&lt;param name=&quot;wmode&quot; value=&quot;transparent&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowfullscreen&quot; value=&quot;true&quot;&gt;&lt;/param&gt;&lt;param name=&quot;FlashVars&quot; value=&quot;mySuperFlashVar=okey&amp;amp;myFlashVar=123&quot;&gt;&lt;/param&gt;&lt;embed src=&quot;http://domain/my.swf&quot; width=&quot;100&quot; height=&quot;100&quot; type=&quot;application/x-shockwave-flash&quot; wmode=&quot;transparent&quot;  allowfullscreen=&quot;true&quot;  FlashVars=&quot;mySuperFlashVar=okey&amp;amp;myFlashVar=123&quot; &gt;&lt;/embed&gt;&lt;/object&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2009/10/embedcode-class-to-generate-html-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

