<?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; JavaScript</title>
	<atom:link href="http://blog.yoz.sk/category/javascript/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>Quick Tip: How to run Android application from browser?</title>
		<link>http://blog.yoz.sk/2010/11/quick-tip-how-to-run-android-application-from-browser/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=quick-tip-how-to-run-android-application-from-browser</link>
		<comments>http://blog.yoz.sk/2010/11/quick-tip-how-to-run-android-application-from-browser/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 10:57:52 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[navigator]]></category>
		<category><![CDATA[run]]></category>
		<category><![CDATA[userAgent]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=2629</guid>
		<description><![CDATA[For now I succeeded with general approach &#8211; Android market application. If you go through Publishing Your Applications you will notice there is a url (with market:// scheme) that can be used to navigate user to your application in Android market. Sadly this url works only from Android device not from desktop (404 not found)! [...]]]></description>
			<content:encoded><![CDATA[<p>For now I succeeded with general approach &#8211; Android market application. If you go through <a href="http://developer.android.com/guide/publishing/publishing.html">Publishing Your Applications</a> you will notice there is a url (with market:// scheme) that can be used to navigate user to your application in Android market. Sadly this url works only from Android device not from desktop (404 not found)! So I came up with this code:</p>
<pre class="brush: jscript; title: ; notranslate">var isAndroid = navigator.userAgent.toLowerCase().search(&quot;android&quot;) &gt; -1;
if(isAndroid &amp;&amp; confirm(&quot;Do you want to run onBoard Android application?&quot;))
    window.location = &quot;market://details?id=air.onBoard2Android&quot;;</pre>
<p>What it does is:</p>
<ol>
<li>it first test user agent if it is an Android device, if so</li>
<li>it asks user to decide wheter to use Android and than</li>
<li>it redirects user into Android market application showing details of your application</li>
</ol>
<p>From here user can install or open the application. You may try it on <a href="http://onboard.yoz.sk">http://onboard.yoz.sk</a> (run from Android device).</p>
<p>I was also playing with the idea about how to run my Android AIR application from browser, well normaly for AIR apps you would use <a href="http://www.adobe.com/devnet/air/articles/badge_for_air.html">install badge</a> or its <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=distributing_apps_3.html">customized version</a> in order to check if the application is installed already and then run or install it. But I hit a major problem with <a href="http://airdownload.adobe.com/air/browserapi/air.swf">air.swf</a> not dispatching Event.INIT on Android flash player <img src='http://blog.yoz.sk/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' />  &#8230; I will surely get back into this to discover more.<br />
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2010/11/quick-tip-how-to-run-android-application-from-browser/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Authorizing Iframe Facebook Applications For Graph API</title>
		<link>http://blog.yoz.sk/2010/06/authorizing-iframe-facebook-applications-for-graph-api/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=authorizing-iframe-facebook-applications-for-graph-api</link>
		<comments>http://blog.yoz.sk/2010/06/authorizing-iframe-facebook-applications-for-graph-api/#comments</comments>
		<pubDate>Thu, 03 Jun 2010 11:48:09 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Access Token]]></category>
		<category><![CDATA[facebook api]]></category>
		<category><![CDATA[FacebookOAuthGraph]]></category>
		<category><![CDATA[Graph API]]></category>
		<category><![CDATA[OAuth]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=1732</guid>
		<description><![CDATA[This article continues my exploration of best facebook graph api integration into your flash app. Before continue reading, make sure you understand the previous article. Due to huge interest, I am adding codes that makes your flash app working with graph api within facebook iframe. Try this app live on http://apps.facebook.com/blogoauthgraph/, notice once you get [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.yoz.sk/wp-content/uploads/auth-dialog-example.jpg" alt="" title="auth-dialog-example" width="200" height="100" class="alignleft size-full wp-image-1562" /></p>
<p>This article continues my exploration of best facebook graph api integration into your flash app. Before continue reading, make sure you understand the <a href="http://blog.yoz.sk/2010/05/facebook-graph-api-and-oauth-2-and-flash/">previous article</a>. Due to huge interest, I am adding codes that makes your flash app working with graph api within facebook iframe. Try this app live on <a href="http://apps.facebook.com/blogoauthgraph/">http://apps.facebook.com/blogoauthgraph/</a>, notice once you get there, you are redirected to grant permissions (if not authorized or granted already) and then redirected back to the app, where you are connected and ready to use graph api.</p>
<p><span id="more-1732"></span></p>
<p>What I did was changing one line of ActionScript, I added autoConnect() methods that sends app flashvars directly into <a href="http://classes.yoz.sk/sk/yoz/net/FacebookOAuthGraph.as">FacebookOAuthGraph</a> object.</p>
<pre class="brush: as3; title: ; notranslate">var facebook:FacebookOAuthGraph = new FacebookOAuthGraph();
...
facebook.autoConnect(parameters); // passing flashvars</pre>
<p>See <a href="http://blog.yoz.sk/2010/05/facebook-graph-api-and-oauth-2-and-flash/">full ActionScript code</a> for details.</p>
<p>Now there is a different html wrapper for facebook iframe &#8211; facebook.php:</p>
<pre class="brush: php; title: ; notranslate">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; lang=&quot;cs&quot; xml:lang=&quot;cs&quot;&gt;
&lt;head&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
    &lt;meta http-equiv=&quot;Content-language&quot; content=&quot;cs&quot; /&gt;
    &lt;title&gt;FacebookOAuthGraphTest&lt;/title&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;js/swfobject.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
        //&lt;![CDATA[
		function allRequestParameters()
		{
			var data = {};
			var strHref = window.location.href;
			if ( strHref.indexOf(&quot;?&quot;) &gt; -1 ) {
				var strQueryString = strHref.substr(strHref.indexOf(&quot;?&quot;)+1);
				var aQueryString = strQueryString.split(&quot;&amp;&quot;);
				for ( var iParam = 0; iParam &lt; aQueryString.length; iParam++ ) {
					var aParam = aQueryString[iParam].split(&quot;=&quot;);
					data[aParam[0]] = aParam[1];
				}
			}
			return data;
		}

		function generateFlash()
		{
			var flashvars = allRequestParameters();
			flashvars.session = '{&quot;access_token&quot;:&quot;' + signed_request.oauth_token + '&quot;}';

			var params = {
				allowScriptAccess: &quot;sameDomain&quot;
			};

			var attributes = {
				id: &quot;FacebookOAuthGraphTest&quot;,
				name: &quot;FacebookOAuthGraphTest&quot;
			};

			swfobject.embedSWF(&quot;FacebookOAuthGraphTest.swf?v=2&quot;, &quot;alternative&quot;, &quot;100%&quot;, &quot;100%&quot;, &quot;10.0.0&quot;,
				&quot;expressInstall.swf&quot;, flashvars, params, attributes);
		}

		&lt;?php
		$signed_request = $_REQUEST[&quot;signed_request&quot;];
		list($encoded_sig, $payload) = explode('.', $signed_request, 2);
		$data = base64_decode(strtr($payload, '-_', '+/'));
		echo &quot;var signed_request=&quot; . $data . &quot;;&quot;;
		?&gt;

		if(!signed_request.oauth_token){
			window.top.location = &quot;https://www.facebook.com/dialog/oauth&quot;
				+ &quot;?client_id=&quot; + '268718683475'
				+ &quot;&amp;redirect_uri=&quot; + 'http://apps.facebook.com/blogoauthgraph/'
				+ &quot;&amp;scope=publish_stream,user_photos,user_photo_video_tags&quot;
				+ &quot;&amp;response_type=token&quot;;
		}else{
			generateFlash();
		}
        //]]&gt;
    &lt;/script&gt;
    &lt;style&gt;
        body {margin:0px;overflow:hidden}
        html, body, object, embed {width:100%;height:100%;outline:none;}
    &lt;/style&gt;
 &lt;/head&gt;
 &lt;body style=&quot;text-align:center;&quot;&gt;
    &lt;div id=&quot;alternative&quot;&gt;
        &lt;a href=&quot;http://www.adobe.com/go/getflashplayer&quot;&gt;
            &lt;img src=&quot;http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif&quot; alt=&quot;Get Adobe Flash player&quot; /&gt;
        &lt;/a&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>There are few lines of code to be mentioned:</p>
<ul>
<li><del datetime="2011-03-16T08:55:15+00:00">getRequestParameter(name) &#8211; returns GET parameter from iframe url, you can use your own functions</del></li>
<li>allRequestParameters() &#8211; returns object consisting of all iframe GET parameters, used to pass flashvars into our flash</li>
<li>php code to define javascript signed_request variable containing valid token</li>
<li>window.top.location &#8211; if there is no token parameter found (not authorized yet), you are redirected to the facebook authorization. Do not forget to change <strong>client_id</strong> and <strong>redirect_uri</strong> when using for your app.</li>
</ul>
<p>Facebook settings:</p>
<pre class="brush: plain; title: ; notranslate">App ID: 268718683475
Site URL: http://blog.yoz.sk/examples/FacebookOAuthGraph/
Site Domain: yoz.sk
Canvas Page: http://apps.facebook.com/blogoauthgraph/
Canvas URL: http://blog.yoz.sk/examples/FacebookOAuthGraph/facebook.php?a=b
Canvas FBML/iframe: iframe

Disable Deprecated Auth Methods: Enabled
Stream post URL security: Disabled
OAuth 2.0 for Canvas: Enabled
POST for Canvas: Enabled
Canvas Session Parameter (Deprecated): Disabled
November 2010 Rollup: Enabled
Timezone-less events: Enabled
Upgrade to Requests 2.0: Enabled
JSON Encoding Empty Arrays: Enabled</pre>
<p>Here is the final facebook app <a href="http://apps.facebook.com/blogoauthgraph/">http://apps.facebook.com/blogoauthgraph/</a></p>
<p><del datetime="2011-03-16T08:55:15+00:00">updated Jul 21, 2010: Quickfix for late facebook changes:</del></p>
<p><del datetime="2011-03-16T09:07:55+00:00">updated Jul 22, 2010: Facebook rollbacked the change and added &#8220;Canvas Session Parameter&#8221; parameter in facebook app settings / Migrations tab. With this setting enabled, your apps should work normally as they previously did.</del></p>
<p>updated Mar 16, 2011: Catching token from POST parameter.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2010/06/authorizing-iframe-facebook-applications-for-graph-api/feed/</wfw:commentRss>
		<slash:comments>115</slash:comments>
		</item>
		<item>
		<title>Inviting Friends into Facebook Application  (update)</title>
		<link>http://blog.yoz.sk/2010/03/inviting-friends-into-facebook-application/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=inviting-friends-into-facebook-application</link>
		<comments>http://blog.yoz.sk/2010/03/inviting-friends-into-facebook-application/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 11:51:26 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[facebook api]]></category>
		<category><![CDATA[FBML]]></category>
		<category><![CDATA[request-form]]></category>
		<category><![CDATA[serverFbml]]></category>
		<category><![CDATA[XFBML]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=1182</guid>
		<description><![CDATA[Those are hard times. Facebook discontinued support for Notifications.send method March 1, 2010. Calling this method returns error code 3 (Unknown method). Instead, developers are directed to use other communication channels. From those some are not yet even a part of facebook-actionscript-api yet (dashboard) other not published from facebook (invites) and those that may work [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.yoz.sk/wp-content/uploads/facebookInvites.jpg" alt="" title="facebookInvites" width="200" height="172" class="alignleft size-full wp-image-1183" /></p>
<p>Those are hard times. Facebook discontinued support for <a href="http://wiki.developers.facebook.com/index.php/Notifications.send">Notifications.send</a> method March 1, 2010. Calling this method returns error code 3 (Unknown method). Instead, developers are directed to use other <a href="http://wiki.developers.facebook.com/index.php/Communication_Channels_Best_Practices">communication channels</a>. From those some are not yet even a part of <a href="http://code.google.com/p/facebook-actionscript-api/">facebook-actionscript-api</a> yet (<a href="http://wiki.developers.facebook.com/index.php/Dashboard_API">dashboard</a>) other not published from facebook (<a href="http://wiki.developers.facebook.com/index.php/Roadmap_Invites">invites</a>) and those that may work via api are experimental and may change any day (<a href="http://wiki.developers.facebook.com/index.php/Dashboard.publishActivity">activities</a>).</p>
<p>Excluding <a href="http://wiki.developers.facebook.com/index.php/Roadmap_Stream">streams</a> as communication channel, the only usable way, these days, to acquire some new facebook application users is using <a href="http://wiki.developers.facebook.com/index.php/Fb:request-form">&lt;Fb:request-form&gt;</a> (part of <a href="http://wiki.developers.facebook.com/index.php/Category:FBML_tags">FBML</a>). When your application is IFrame, you may find interesting that you are able to use FBML within your HTML files. In order to make this happen, you have to use <a href="http://wiki.developers.facebook.com/index.php/Fb:serverFbml">&lt;Fb:serverFbml&gt;</a> (renders the FBML on a Facebook server inside an iframe). Now, lets see how to open request form in your Facebook <strong>Iframe</strong> application:</p>
<p><span id="more-1182"></span></p>
<p>First thing you need is <a href="http://wiki.developers.facebook.com/index.php/Cross_Domain_Communication_Channel">Cross Domain Communication Channel</a> file . It is simple static file, you should name it xd_receiver.htm</p>
<pre class="brush: xml; title: ; notranslate">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;
   &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;
&lt;head&gt;
    &lt;title&gt;Cross-Domain Receiver Page&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;script src=&quot;http://static.ak.connect.facebook.com/js/api_lib/v0.4/XdCommReceiver.js?2&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>now your application index.html file with request form:</p>
<pre class="brush: xml; title: ; notranslate">&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xmlns:fb=&quot;http://www.facebook.com/2008/fbml&quot;&gt;
&lt;head&gt;&lt;/head&gt;
&lt;body&gt;
&lt;script src=&quot;http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	window.onload = function()
	{
		FB_RequireFeatures([&quot;XFBML&quot;], function()
		{
			FB.Facebook.init(&quot;*YOUR*API*KEY*HERE*&quot;, &quot;xd_receiver.htm&quot;);
		});
	};
&lt;/script&gt;

&lt;fb:serverFbml style=&quot;width: 750px;&quot;&gt;
	&lt;script type=&quot;text/fbml&quot;&gt;
		&lt;fb:fbml&gt;
			&lt;fb:request-form action=&quot;http://www.google.com&quot; method=&quot;POST&quot; invite=&quot;true&quot; type=&quot;TestApp&quot;
				content=&quot;Join my app &amp;lt;fb:req-choice url=&amp;quot;http://apps.facebook.com/facebookyoztest/&amp;quot; label=&amp;quot;Go Test app&amp;quot; /&amp;gt;&quot;&gt;
				&lt;fb:multi-friend-selector showborder=&quot;false&quot; actiontext=&quot;Invite your friends to use Test app.&quot;&gt;
			&lt;/fb:request-form&gt;
		&lt;/fb:fbml&gt;
	&lt;/script&gt;
&lt;/fb:serverFbml&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Place both files in the same folder (or specify xd_receiver.htm path correctly in FB.Facebook.init() function). Now make sure you setup your application correctly: </p>
<pre class="brush: plain; title: ; notranslate">Canvas Callback URL: http://facebook.yoz.sk/Test/
Connect URL: http://facebook.yoz.sk/Test/
Base Domain: yoz.sk
Canvas URL: http://apps.facebook.com/facebookyoztest/
FBML/iframe: iframe
Application Type: Website</pre>
<p>Now request form should be generated when you visit canvas url.</p>
<p><img src="http://blog.yoz.sk/wp-content/uploads/facebookInvites2.jpg" alt="" title="facebookInvites2" width="400" height="220" class="alignnone size-full wp-image-1197" /></p>
<p>Important:</p>
<ul>
<li><strong>Your application must be iframe type</strong></li>
<li><strong>URLs used in this article are not to be used in your apps</strong></li>
<li><strong>This article was written and is valid on March 9, 2010</strong></li>
</ul>
<h2>Using Invitations in light popup (iframe)</h2>
<p>If you need to show invitation module over your application, you can use this procedure. If you plan to open iframe over flash app make sure your flash is in wmode transparent or opaque so iframe can overlay it&#8230; index.html</p>
<pre class="brush: xml; title: ; notranslate">...
&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
	function showInvite(){
		document.getElementById('invite').style.display = 'block';
		document.getElementById('invite').src = &quot;invite.html&quot;;
	}

	function hideInvite(){
		document.getElementById('invite').style.display = 'none';
		document.getElementById('invite').src = &quot;about:blank&quot;;
	}
//--&gt;
&lt;/script&gt;
...
&lt;button onclick=&quot;showInvite()&quot;&gt;show invite&lt;/button&gt;
&lt;button onclick=&quot;hideInvite()&quot;&gt;hide invite&lt;/button&gt;
&lt;iframe id=&quot;invite&quot; width=&quot;584&quot; height=&quot;513&quot; style=&quot;display:none&quot;&gt;&lt;/iframe&gt;</pre>
<p>invite.html</p>
<pre class="brush: xml; title: ; notranslate">&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xmlns:fb=&quot;http://www.facebook.com/2008/fbml&quot;&gt;
&lt;head&gt;
	&lt;style type='text/css'&gt;
	&lt;!--
		body {margin:0px;overflow:hidden;}
		html, body {width:100%;height:100%;outline:none;}
	--&gt;
	 &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;script src=&quot;http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	window.onload = function()
	{
		FB_RequireFeatures([&quot;XFBML&quot;], function()
		{
			FB.Facebook.init(&quot;d5702b09b56c330a5a4c85ab7b2635bd&quot;, &quot;xd_receiver.htm&quot;);
		});
	};
&lt;/script&gt;
&lt;fb:serverFbml style=&quot;width: 584px;&quot;&gt;
	&lt;script type=&quot;text/fbml&quot;&gt;
		&lt;fb:fbml&gt;
			&lt;fb:request-form action=&quot;http://facebook.yoz.sk/testapp/invite_callback.html&quot; method=&quot;POST&quot; invite=&quot;true&quot; type=&quot;TestApp&quot;
				content=&quot;Join my app &amp;lt;fb:req-choice url=&amp;quot;http://www.yoz.sk/phpinfo.php&amp;quot; label=&amp;quot;Go Test app&amp;quot; /&amp;gt;&quot;&gt;
				&lt;fb:multi-friend-selector max=&quot;1&quot; cols=&quot;3&quot; rows=&quot;3&quot; showborder=&quot;true&quot; actiontext=&quot;Invite your friends to use Test app.&quot;/&gt;
			&lt;/fb:request-form&gt;
		&lt;/fb:fbml&gt;
	&lt;/script&gt;
&lt;/fb:serverFbml&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>invite_callback.html</p>
<pre class="brush: xml; title: ; notranslate">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;sk&quot; lang=&quot;sk&quot; dir=&quot;ltr&quot;&gt;
&lt;head&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
	&lt;!--
		window.parent.hideInvite();
	//--&gt;
	&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Continue reading:</p>
<ul>
<li>[deprecated] <a href="http://wiki.developers.facebook.com/index.php/Notifications.send">Notifications.send</a></li>
<li>[deprecated] <a href="http://wiki.developers.facebook.com/index.php/Notifications.sendRequest">Notifications.sendRequest</a></li>
<li>[May 2010] <a href="http://wiki.developers.facebook.com/index.php/Roadmap_Invites">Roadmap Invites</a></li>
<li><a href="http://wiki.developers.facebook.com/index.php/Dashboard.addNews">Dashboard.addNews</a></li>
<li><a href="http://wiki.developers.facebook.com/index.php/Dashboard.multiAddNews">Dashboard.multiAddNews</a></li>
<li><a href="http://wiki.developers.facebook.com/index.php/Multi_friend_selector">Multi friend selector</a></li>
<li><a href="http://wiki.developers.facebook.com/index.php/Communication_Channels_Best_Practices">Communication Channels Best Practices</a></li>
<li><a href="http://wiki.developers.facebook.com/index.php/Developer_Roadmap">Developer Roadmap</a></li>
<li><a href="http://wiki.developers.facebook.com/index.php/XFBML">XFBML</a></li>
<li><a href="http://wiki.developers.facebook.com/index.php/Fb:serverFbml">Fb:serverFbml</a></li>
<li><a href="http://wiki.developers.facebook.com/index.php/Fb:request-form">Fb:request-form</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2010/03/inviting-friends-into-facebook-application/feed/</wfw:commentRss>
		<slash:comments>87</slash:comments>
		</item>
		<item>
		<title>Inline Images</title>
		<link>http://blog.yoz.sk/2010/02/inline-images/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=inline-images</link>
		<comments>http://blog.yoz.sk/2010/02/inline-images/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 14:59:44 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[ByteArray]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[PNGEncoder]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=1106</guid>
		<description><![CDATA[Have you ever heard about inline images? Inline images use the data URI scheme to embed images directly within web pages. As defined by RFC 2397, data URIs are designed to embed small data items as &#8220;immediate&#8221; data, as if they were referenced externally. This basicaly means, you can insert base64 encoded byte code of [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.yoz.sk/wp-content/uploads/inlineImage-200x122.png" alt="" title="inlineImage" width="200" height="122" class="alignleft size-medium wp-image-1111" /></p>
<p>Have you ever heard about <a href="http://www.websiteoptimization.com/speed/tweak/inline-images/">inline images</a>? Inline images use the data URI scheme to embed images directly within web pages. As defined by RFC 2397, data URIs are designed to embed small data items as &#8220;immediate&#8221; data, as if they were referenced externally. This basicaly means, you can insert base64 encoded byte code of any image directly into html file. Using inline images saves HTTP requests over externally referenced objects. Data URIs can potentially <a href="http://www.greywyvern.com/code/php/binary2base64">store any type of data</a>, not just images!</p>
<p><span id="more-1106"></span></p>
<p>This example creates snapshot of flash application (on left side) and dynamicly (using javascript) creates inline image (right side) with base64 encoded bytes in src attribute. (right side is html &lt;img&gt;)</p>
<p><iframe width="100%" height="300" style="border:none;" src="http://blog.yoz.sk/examples/inlineImages/"></iframe></p>
<p>Application source:</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;
    enterFrame=&quot;enterFrame()&quot; borderStyle=&quot;solid&quot; borderColor=&quot;#000000&quot;
    backgroundColor=&quot;#ffffff&quot;&gt;
&lt;mx:Script&gt;
&lt;![CDATA[
    import com.adobe.images.PNGEncoder;
    import com.dynamicflash.util.Base64;

    private function enterFrame():void
    {
        if(!container || !container.width)
            return;

        container.graphics.beginFill(Math.random() * 0xffffff, Math.random());
        container.graphics.drawCircle(
            Math.random() * container.width,
            Math.random() * container.height, Math.random() * 30);

    }

    private function makeSnapshot(source:DisplayObject):void
    {
        var script:String = 'var img = document.getElementById(&quot;img&quot;);'
            + 'if(!img)'
            + '{'
                + 'img = document.createElement(&quot;IMG&quot;);'
                + 'img.id=&quot;img&quot;;'
                + 'document.body.appendChild(img);'
            + '}'
            + 'img.src=&quot;' + getSrc(source) +'&quot;;';
        ExternalInterface.call(&quot;function(){&quot; + script + &quot;}&quot;);
    }

    private function getByteArray(source:DisplayObject):ByteArray
    {
        var bitmapData:BitmapData = new BitmapData(source.width, source.height);
        bitmapData.draw(source);
        var bitmap:Bitmap = new Bitmap(bitmapData);
        return PNGEncoder.encode(bitmapData);
    }

    private function getSrc(source:DisplayObject):String
    {
        var byteArray:ByteArray = getByteArray(source);
        return 'data:image/png;base64,'
            + Base64.encodeByteArray(byteArray);
    }
]]&gt;
&lt;/mx:Script&gt;
&lt;mx:Container id=&quot;container&quot; width=&quot;100%&quot; height=&quot;100%&quot;/&gt;
&lt;mx:Button label=&quot;Make Snapshot&quot; click=&quot;makeSnapshot(this)&quot;/&gt;
&lt;/mx:Application&gt;</pre>
<p>Data URLs save HTTP requests. When combined with CSS sprites, data URLs can save numerous HTTP requests. It would be interesting to see if data URLs can be combined with USEMAPS or make a data URL CSS sprite. Data URLs are a convenient way to create self-enclosed web pages that don&#8217;t rely on external objects to render.</p>
<ul>
<li>Save HTTP requests, avoids adding to object overhead</li>
<li>Save concurrent thread &#8211; browsers default to two simultaneous connections per hostname</li>
<li>HTTPS requests are simplified and performance improved</li>
</ul>
<p>Well, for now I have no idea how can flash benefit from data urls <img src='http://blog.yoz.sk/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  but if I come to something I let you know.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2010/02/inline-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick tip: ExternalInterface.call is synchronous!</title>
		<link>http://blog.yoz.sk/2010/02/quick-tip-externalinterface-call-is-synchronous/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=quick-tip-externalinterface-call-is-synchronous</link>
		<comments>http://blog.yoz.sk/2010/02/quick-tip-externalinterface-call-is-synchronous/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 16:21:01 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[ExternalInterface]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=1067</guid>
		<description><![CDATA[It is a little wonder to me how flash player communicates with JavaScript. Calls are fully synchronous, it works as those (fp and js) were fully integrated into each other. To simulate this lets test some simple flow: Following flex application runs simple JavaScript: and results are logged into TextArea: This means that ExternalInterface.call() is [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.yoz.sk/wp-content/uploads/synchronous.jpg" alt="" title="synchronous" width="200" height="100" class="alignleft size-full wp-image-1081" /></p>
<p>It is a little wonder to me how flash player communicates with JavaScript. Calls are fully synchronous, it works as those (fp and js) were fully integrated into each other. To simulate this lets test some simple flow:</p>
<p><span id="more-1067"></span></p>
<div style="clear:both;"></div>
<pre class="brush: plain; title: ; notranslate">Flash Player calls JavaScript
    JavaScript calls FlashPlayer
        FlashPlayer do some stuff and finishes
    JavaScript finishes
FlashPlayer continues</pre>
<p>Following flex application runs simple JavaScript:</p>
<pre class="brush: jscript; title: ; notranslate">document.getElementById(&quot;flash&quot;).universalCallback();
return &quot;synchronous return&quot;;</pre>
<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;
    applicationComplete=&quot;init()&quot;&gt;
&lt;mx:Script&gt;
&lt;![CDATA[
    [Bindable]
    private var lastResult:String = &quot;&quot;;

    private function init():void
    {
        ExternalInterface.addCallback(&quot;universalCallback&quot;, universalCallback);
    }

    private function runScript():void
    {
        var script:String = 'document.getElementById(&quot;flash&quot;).universalCallback();' +
                'return &quot;synchronous return&quot;;';

        var result:String = ExternalInterface.call(&quot;function(){&quot; + script + &quot;}&quot;);
        lastResult += result + &quot;\n&quot;;
    }

    private function universalCallback(... rest):void
    {
        lastResult += &quot;universalCallback&quot; + &quot;\n&quot;;
    }
]]&gt;
&lt;/mx:Script&gt;
&lt;mx:Button click=&quot;runScript()&quot; label=&quot;Run&quot;/&gt;
&lt;mx:TextArea width=&quot;100%&quot; height=&quot;100%&quot; text=&quot;{lastResult}&quot; /&gt;
&lt;/mx:Application&gt;</pre>
<p>and results are logged into TextArea:</p>
<pre class="brush: plain; title: ; notranslate">universalCallback
synchronous return</pre>
<p>This means that ExternalInterface.call() is synchronous and waits until called JavaScript finishes. Just after that, flash player moves on the next line. This interesting behaviour makes flash player to hold (but not to freeze) on one line while it is able to continue on different execution (universalCallback()). </p>
<p>Notice, JavaScript to ActionScript data can be sent via ExternalInterface.addCallback() or simple by synchronous return:</p>
<pre class="brush: as3; title: ; notranslate">var result:String = ExternalInterface.call(&quot;function(){&quot; + script + &quot;}&quot;);</pre>
<p>however, you can not use eval method this way!</p>
<pre class="brush: as3; title: ; notranslate">var result:String = ExternalInterface.call(&quot;eval&quot;, script);</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2010/02/quick-tip-externalinterface-call-is-synchronous/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Full JavaScript Access From ActionScript (update)</title>
		<link>http://blog.yoz.sk/2010/02/full-javascript-access-from-actionscript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=full-javascript-access-from-actionscript</link>
		<comments>http://blog.yoz.sk/2010/02/full-javascript-access-from-actionscript/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 10:10:55 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[allowscriptaccess]]></category>
		<category><![CDATA[eval]]></category>
		<category><![CDATA[ExternalInterface]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=1005</guid>
		<description><![CDATA[Have you ever tought about accessing DOM from ActionScript? In fact, you can do it and even far more. You can create and call JavaScript methods and objects, access cookies, change styles&#8230; All you need is correct AllowScriptAccess parameter within your flash object. No framework needed here, no hacks, ExternalInterface takes care. Following application runs [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.yoz.sk/wp-content/uploads/fullJavascriptAccess.png" alt="" title="fullJavascriptAccess" width="200" height="100" class="alignleft size-full wp-image-1047" /></p>
<p>Have you ever tought about accessing <a href="http://cs.wikipedia.org/wiki/Document_Object_Model">DOM</a> from ActionScript? In fact, you can do it and even far more. You can create and call JavaScript methods and objects, access cookies, change styles&#8230; All you need is correct <a href="http://kb2.adobe.com/cps/164/tn_16494.html">AllowScriptAccess</a> parameter within your flash object. No framework needed here, no hacks, ExternalInterface takes care.</p>
<p><span id="more-1005"></span></p>
<p style="clear:both;">Following application runs JavaScript from textarea:</p>
<p><iframe width="100%" height="300" style="border:none;" src="http://blog.yoz.sk/examples/fullJavascriptAccess/"></iframe></p>
<p>Application. Line 16 does all the fun <img src='http://blog.yoz.sk/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </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;
    applicationComplete=&quot;init()&quot;&gt;
&lt;mx:Script&gt;
&lt;![CDATA[
    [Bindable]
    private var lastResult:String = &quot;&quot;;

    private function init():void
    {
        ExternalInterface.addCallback(&quot;universalCallback&quot;, universalCallback);
    }

    private function runScript():void
    {
        ExternalInterface.call(&quot;eval&quot;, script.text);
    }

    private function universalCallback(... rest):void
    {
        lastResult = String(rest[0]);
    }
]]&gt;
&lt;/mx:Script&gt;
&lt;mx:HBox width=&quot;100%&quot; height=&quot;100%&quot;&gt;
    &lt;mx:TextArea id=&quot;script&quot; width=&quot;100%&quot; height=&quot;100%&quot;&gt;
        &lt;mx:text&gt;
            &lt;![CDATA[
function myFunction(){
    var flash = document.getElementById(&quot;flash&quot;);
    var data = document.childNodes[1].innerHTML;
    flash.universalCallback(data);
}

myFunction();
alert(document.getElementsByTagName('title')[0].innerHTML);
            ]]&gt;
        &lt;/mx:text&gt;
    &lt;/mx:TextArea&gt;
    &lt;mx:TextArea width=&quot;100%&quot; height=&quot;100%&quot; text=&quot;{lastResult}&quot; /&gt;
&lt;/mx:HBox&gt;

&lt;mx:Button click=&quot;runScript()&quot; label=&quot;Run&quot;/&gt;
&lt;/mx:Application&gt;</pre>
<p>HTML template</p>
<pre class="brush: xml; title: ; notranslate">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;
&lt;head&gt;
    &lt;title&gt;Full Javascript Access&lt;/title&gt;
    &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;application/xml; charset=utf-8&quot; /&gt;
    &lt;meta http-equiv=&quot;Cache-Control&quot; content=&quot;no-cache&quot; /&gt;
    &lt;meta http-equiv=&quot;expires&quot; content=&quot;1&quot; /&gt;
    &lt;meta http-equiv=&quot;pragma&quot; content=&quot;no-cache&quot; /&gt; 

    &lt;meta name=&quot;author&quot; content=&quot;http://studio.yoz.sk&quot; /&gt;
    &lt;meta name=&quot;description&quot; content=&quot;Full Javascript Access&quot; /&gt;
    &lt;meta name=&quot;robots&quot; content=&quot;all&quot; /&gt; 

    &lt;script type=&quot;text/javascript&quot; src=&quot;js/swfobject.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
    &lt;!--
        var flashvars = {}

        var params = {
            allowscriptaccess: &quot;always&quot;
        };
        var attributes = {
            id: &quot;flash&quot;,
            name: &quot;flash&quot;
        };
        swfobject.embedSWF(&quot;Tests.swf&quot;, &quot;alternative&quot;, &quot;100%&quot;, &quot;100%&quot;, &quot;10.0.0&quot;,
            &quot;flash/expressInstall.swf&quot;, flashvars, params, attributes);
    //--&gt;
    &lt;/script&gt;

    &lt;style type='text/css'&gt;
    &lt;!--
        body {margin:0px;overflow:hidden;}
        html, body, object, embed {width:100%;height:100%;outline:none;}
    --&gt;
    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div id=&quot;alternative&quot;&gt;
        &lt;a href=&quot;http://www.adobe.com/go/getflashplayer&quot;&gt;
            &lt;img src=&quot;http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif&quot; alt=&quot;Get Adobe Flash player&quot; /&gt;
        &lt;/a&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>No additional nothing here just:</p>
<ul>
<li>line 20: allowscriptaccess: &#8220;always&#8221; (&#8220;sameDomain&#8221; may also be used)</li>
<li>line 24: tip &#8211; add name attribute with swfobject so ExternalInterface.objectID will get correct value</li>
</ul>
<p><a href="http://stackoverflow.com/questions/86513/why-is-using-javascript-eval-function-a-bad-idea">Considerations of using eval</a>:</p>
<ul>
<li>Improper use of eval opens up your code for injection attacks</li>
<li>Debugging can be more challenging (no line numbers, etc.)</li>
<li>eval&#8217;d code executes more slowly (no opportunity to compile/cache eval&#8217;d code)</li>
</ul>
<p>Update (Feb 11, 2010): You can use either eval call:</p>
<pre class="brush: as3; title: ; notranslate">ExternalInterface.call(&quot;eval&quot;, script.text);</pre>
<p>or wrap your script into anonymous function:</p>
<pre class="brush: as3; title: ; notranslate">ExternalInterface.call(&quot;function(){&quot; + script.text + &quot;}&quot;);</pre>
<p>Personally, I do not see any difference in execution, it seems to be the same, maybe some performance testing would clarify it. What do you think?</p>
<p>Where to go from here:</p>
<ul>
<li><a href="http://cookbooks.adobe.com/post_Inject_JavaScript_code_in_html_wrapper_from_Flex_A-17157.html">JavaScript injecting by Abdul Qabiz</a></li>
<li><a href="http://cookbooks.adobe.com/post_Embed_of_JavaScript_code_in_the_Flex_application-14530.html?w=rel">Embed of JavaScript code in the Flex application</a></li>
<li><a href="http://code.google.com/p/jsinterface/">JSInterface &#8211; JavaScript API for ActionScript 3</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2010/02/full-javascript-access-from-actionscript/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Update: Facebook application missing session key on first visit</title>
		<link>http://blog.yoz.sk/2009/11/facebook-application-missing-session-key-on-first-visit/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=facebook-application-missing-session-key-on-first-visit</link>
		<comments>http://blog.yoz.sk/2009/11/facebook-application-missing-session-key-on-first-visit/#comments</comments>
		<pubDate>Thu, 26 Nov 2009 11:39:40 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Authorize]]></category>
		<category><![CDATA[facebook api]]></category>
		<category><![CDATA[FBML]]></category>
		<category><![CDATA[fb_sig_session_key]]></category>
		<category><![CDATA[Redirect]]></category>
		<category><![CDATA[verifySession]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=691</guid>
		<description><![CDATA[There are still some issues with facebook flash api vs. facebook communication. Some of them, you as an application developer, will never get into, but general user will. For example, when new user comes into your facebook iframe flash application for a first time, the first thing he see is &#8220;Allow Access?&#8221; window: After clicking [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.yoz.sk/wp-content/uploads/facebookAllowAccess.png"><img src="http://blog.yoz.sk/wp-content/uploads/facebookAllowAccess-200x82.png" alt="facebookAllowAccess" title="facebookAllowAccess" width="200" height="82" class="alignleft size-medium wp-image-692" /></a></p>
<p>There are still some issues with facebook flash api vs. facebook communication. Some of them, you as an application developer, will never get into, but general user will. For example, when new user comes into your facebook iframe flash application for a first time, the first thing he see is &#8220;Allow Access?&#8221; window:</p>
<p><span id="more-691"></span></p>
<div style="clear:both;"></div>
<p><a href="http://blog.yoz.sk/wp-content/uploads/facebookAllowAccess.png"><img src="http://blog.yoz.sk/wp-content/uploads/facebookAllowAccess.png" alt="facebookAllowAccess" title="facebookAllowAccess" width="477" height="197" class="alignnone size-full wp-image-692" /></a></p>
<p>After clicking &#8220;Allow&#8221;, you should serve user your flash app. But, notice there is no fb_sig_session_key parameter in facebook iframe src. So you wount be able to verify user session with:</p>
<pre class="brush: as3; title: ; notranslate">if(parameters.fb_sig_session_key)
    session.verifySession();
else
    session.login()</pre>
<p>&#8230; and new window is opened instead (that handles the session) so users get confused&#8230;</p>
<h3>Solution 1</h3>
<p>After some thinking I came to this idea. Once user allowed your app, it is enough to refresh page and the session parameter is available, this can be done in javascript:</p>
<pre class="brush: jscript; title: ; notranslate">FB.Bootstrap.requireFeatures([&quot;Connect&quot;], function(){
    FB.Facebook.init(api_key, xd_receiver);

    // open facebook &quot;Allow Access&quot; window:
    FB.Connect.requireSession(function() {
        // user clicked on &quot;Allow&quot;
        // ask for fb_sig_session_key parameter if not found
        if(!getRequestParameter(&quot;fb_sig_session_key&quot;)){
            // lets ask for it with simple refresh
            top.location =  &quot;http://apps.facebook.com/MYAPPNAME/&quot;;
        }else{
            // we have fb_sig_session_key, ready for flash app
        }
    });
}

// support function, you can use your own test
function getRequestParameter(name){
    name = name.replace(/[\[]/,&quot;\\\[&quot;).replace(/[\]]/,&quot;\\\]&quot;);
    var regex = new RegExp(&quot;[\\?&amp;]&quot; + name + &quot;=([^&amp;#]*)&quot;);
    var results = regex.exec(window.location.href);
    return results == null ? &quot;&quot; : results[1];
}</pre>
<h3>Solution 2</h3>
<p>Update: I just discovereded, there is a cleaner solution, as the <a href="http://wiki.developers.facebook.com/index.php/Authorizing_Applications">authorizing application spec says</a>. It states there that:</p>
<blockquote><p>Facebook passes the following parameters to your application when a user interacts with your application:<br />
fb_sig_added:  If set to true, then the user has authorized your application.<br />
&#8230;</p></blockquote>
<blockquote><p>Facebook passes the following parameters only if fb_sig_added is true (that is, if the user has authorized your application):<br />
fb_sig_session_key: &#8230;</p></blockquote>
<p>Facebook offers server side or client side login request (read <a href="http://wiki.developers.facebook.com/index.php/Authorizing_Applications">section How Users Can Authorize an Application</a>) in combination with <a href="http://wiki.developers.facebook.com/index.php/Post-Authorize_Redirect_URL">Post-Authorize Redirect URL</a>. Solutions works this way:</p>
<ol>
<li>new user comes to your app</li>
<li>your app (client side or server side) redirects user to original facebook page where user can authorize your application (<a href="http://blog.yoz.sk/wp-content/uploads/authorizeApplicationOnFacebook.png">see image</a>)</li>
<li>after authorization user is redirected to your app again (Post-Authorize Redirect URL used, typically, you want to make this URL your canvas page)</li>
<li>BEHOLD user is back on your app with fb_sig_session_key</li>
</ol>
<p>Here is some code for server side redirect:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php
require_once 'facebook.php';

$appapikey = 'YOUR API KEY';
$appsecret = 'YOUR APPLICATION SECRET';
$facebook = new Facebook($appapikey, $appsecret);
$user = $facebook-&gt;require_login();</pre>
<p>&#8230; or use client side (FBML) code to redirect:</p>
<pre class="brush: xml; title: ; notranslate">&lt;fb:if-is-app-user&gt;
  &lt;!-- your normal code --&gt;
  &lt;fb:else&gt;
   &lt;fb:redirect url=&quot;http://www.facebook.com/login.php?v=1.0&amp;api_key=[your_app_key]&amp;next=[your_canvas_page_URL]&amp;canvas=&quot;/&gt;
  &lt;/fb:else&gt;
&lt;/fb:if-is-app-user&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2009/11/facebook-application-missing-session-key-on-first-visit/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>FB.Connect.showPermissionDialog</title>
		<link>http://blog.yoz.sk/2009/10/fb-connect-showpermissiondialog/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fb-connect-showpermissiondialog</link>
		<comments>http://blog.yoz.sk/2009/10/fb-connect-showpermissiondialog/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 13:01:08 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[facebook api]]></category>
		<category><![CDATA[solution]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=385</guid>
		<description><![CDATA[If your facebook iframe applications need extra permissions granted, you can use Facebook JavaScript Api to generate modal window over your content to request permissions from users. For this purpose I created a simple FB_test_perm() function. It takes 4 arguments: api_key &#8211; your application api key xd_receiver &#8211; path to xd_receiver.htm file (Cross-Domain Receiver Page) [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.yoz.sk/wp-content/uploads/facebookpermissions.png"><img src="http://blog.yoz.sk/wp-content/uploads/facebookpermissions-200x176.png" alt="facebookpermissions" title="facebookpermissions" width="200" height="176" class="alignleft size-medium wp-image-450" /></a></p>
<p>If your facebook iframe applications need extra permissions granted, you can use Facebook JavaScript Api to generate modal window over your content to request permissions from users. For this purpose I created a simple FB_test_perm() function. It takes 4 arguments:</p>
<ul style="float:left;">
<li><strong>api_key</strong> &#8211; your application api key</li>
<li><strong>xd_receiver</strong> &#8211; path to xd_receiver.htm file (<a href="http://wiki.developers.facebook.com/index.php/Cross_Domain_Communication_Channel">Cross-Domain Receiver Page</a>)</li>
<li><strong>permission</strong> &#8211; <a href="http://wiki.developers.facebook.com/index.php/Extended_permission">publish_stream, read_stream &#8230;</a></li>
<li><strong>callback</strong> &#8211; your function with boolean return (true if permission granted, false if not granted)</li>
</ul>
<div style="clear:both;"></div>
<p><span id="more-385"></span></p>
<p>facebook_permission_test.js</p>
<pre class="brush: jscript; title: ; notranslate">function FB_test_perm(api_key, xd_receiver, permission, callback)
{
	FB.Bootstrap.requireFeatures([&quot;Connect&quot;], function()
	{
		FB.Facebook.init(api_key, xd_receiver);
		FB.Connect.requireSession(function()
		{
			FB.Facebook.apiClient.users_hasAppPermission(permission, function(result)
			{
				if (result != 0)
					return callback(true);

				FB.Connect.showPermissionDialog(permission, function(result)
				{
					return callback(result == null ? false : (result.indexOf(permission) != -1));
				}, true, null);
			});
		});
	});
}</pre>
<p>index.html</p>
<pre class="brush: xml; title: ; notranslate">&lt;html&gt;
&lt;body&gt;
&lt;script src=&quot;http://static.ak.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;facebook_permission_test.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	function FB_perm_result(value){
		alert(value ? &quot;granted&quot; : &quot;not granted&quot;);
	}
	FB_test_perm(&quot;***&quot;, &quot;xd_receiver.htm&quot;, &quot;publish_stream&quot;, FB_perm_result);
&lt;/script&gt;
&lt;!-- Note: Include this div markup as a workaround for a known bug in this release on IE where you may get a &quot;operation aborted&quot; error --&gt;
&lt;div id=&quot;FB_HiddenIFrameContainer&quot; style=&quot;display:none; position:absolute; left:-100px; top:-100px; width:0px; height: 0px;&quot;&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>xd_receiver.htm</p>
<pre class="brush: xml; title: ; notranslate">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot;
   &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; &gt;
&lt;head&gt;
    &lt;title&gt;Cross-Domain Receiver Page&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;script src=&quot;http://static.ak.facebook.com/js/api_lib/v0.4/XdCommReceiver.js?v2&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>If you can not get your facebook showPermissionDialog popup opened, make sure you set Canvas Callback URL, Connect URL, Base domain, Connect Preview URL correctly:</p>
<p><a href="http://blog.yoz.sk/wp-content/uploads/Clipboard011.png"><img src="http://blog.yoz.sk/wp-content/uploads/Clipboard011-143x200.png" alt="Clipboard01" title="Clipboard01" width="143" height="200" class="alignnone size-medium wp-image-386" /></a></p>
<p>Make sure you embed flash in transparent / opaque wmode and iframe size (width, height) is enough to display facebook modal window.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2009/10/fb-connect-showpermissiondialog/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Flex IFrame &#8211; Web browser in flash (update)</title>
		<link>http://blog.yoz.sk/2009/10/flex-iframe-web-browser-in-flash/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=flex-iframe-web-browser-in-flash</link>
		<comments>http://blog.yoz.sk/2009/10/flex-iframe-web-browser-in-flash/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 10:45:21 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Projects]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[Canvas]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[FlexIFrame]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[IFrame]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=139</guid>
		<description><![CDATA[You can not have a web browser inside your web flash applications right? Well, you can! This solution uses html iframe to generate fake build in browser. So the behaviour of the browser in flash is the same as the one you are previewing this flash in (it is the same one). The best part [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.yoz.sk/wp-content/uploads/Clipboard02.png"><img src="http://blog.yoz.sk/wp-content/uploads/Clipboard02-200x196.png" alt="Clipboard02" title="Clipboard02" width="200" height="196" class="alignleft size-medium wp-image-370" /></a></p>
<p>You can not have a web browser inside your web flash applications right? Well, you can! This solution uses html iframe to generate fake build in browser. So the behaviour of the browser in flash is the same as the one you are previewing this flash in (it is the same one). The best part of it is, you can manipulate with the position and size of this browser directly from flash. <a href="http://classes.yoz.sk/sk/yoz/html/IFrame.as">sk.yoz.html.IFrame</a> solution was inspired by <a href="http://www.netthreads.co.uk/">Alistair Rutherford, www.netthreads.co.uk</a>.</p>
<ul style="float: left;">
<li><a href="http://classes.yoz.sk/sk/yoz/html/IFrame.as">sk.yoz.html.IFrame</a></li>
<li>FlexIFrame.js</li>
<li>Application</li>
<li>Application html</li>
</ul>
<p><span id="more-139"></span></p>
<p style="clear:both;">Flex Iframe application</p>
<p><iframe src="http://blog.yoz.sk/examples/flexIframe/" width="100%" height="350" style="border:none;"></iframe></p>
<p>Core of this thing is <a href="http://classes.yoz.sk/sk/yoz/html/IFrame.as">sk.yoz.html.IFrame</a> class. It extends Canvas that is used to inherit properties and methods for positioning and sizing. There is one in order to make it work &#8211; every IFrame element must have id!</p>
<pre class="brush: as3; title: ; notranslate">package sk.yoz.html
{
    import flash.events.Event;
    import flash.external.ExternalInterface;
    import flash.geom.Point;

    import mx.containers.Canvas;

    public class IFrame extends Canvas
    {
        public var methodResize:String = &quot;FlexIFrame.resize&quot;;
        public var methodMove:String = &quot;FlexIFrame.move&quot;;
        public var methodNavigate:String = &quot;FlexIFrame.navigate&quot;;
        public var methodVisibility:String = &quot;FlexIFrame.visibility&quot;;

        public var positionChanged:Boolean = false;
        public var sizeChanged:Boolean = false;

        private var _autoResize:Boolean = false;
        private var _url:String = '';

        public function IFrame()
        {
            super();
            addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler)
        }

        override public function set id(value:String):void
        {
            super.id = value;
        }

        protected function addedToStageHandler(event:Event):void
        {
            positionChanged = true;
            sizeChanged = true;
            invalidateProperties();
        }

        public function set autoResize(value:Boolean):void
        {
            _autoResize = value;
            if(value)
                addEventListener(Event.RESIZE, autoResizeHandler);
            else
                removeEventListener(Event.RESIZE, autoResizeHandler);
        }

        public function get autoResize():Boolean
        {
            return _autoResize;
        }

        protected function autoResizeHandler(event:Event):void
        {
            positionChanged = true;
            sizeChanged = true;
            invalidateProperties();
        }

        override protected function commitProperties():void
        {
            super.commitProperties();

            if(positionChanged)
            {
                var point:Point = localToGlobal(new Point(0, 0));
                callJS(methodMove, point.x, point.y);
                positionChanged = false;
            }

            if(sizeChanged)
            {
                callJS(methodResize, width, height);
                sizeChanged = false;
            }
        }

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

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

        protected function callJS(method:String, ... values):void
        {
            if(!id)
                throw new Error(&quot;IFrame id is not defined&quot;);
            var args:Array = [method, id];
            try
            {
                ExternalInterface.call.apply(ExternalInterface, args.concat(values));
            }
            catch(error:Error)
            {
                trace(error.message);
            }
        }

        override public function set visible(value:Boolean):void
        {
            super.visible = value;
            callJS(methodVisibility, value);
        }

        override public function set width(value:Number):void
        {
            super.width = value;
            callJS(methodResize, value, height);
        }

        override public function set height(value:Number):void
        {
            super.height = value;
            callJS(methodResize, width, value);
        }

        override public function set x(value:Number):void
        {
            super.x = value;
            var point:Point = localToGlobal(new Point(0, 0));
            callJS(methodMove, point.x, point.y);
        }

        override public function set y(value:Number):void
        {
            super.y = value;
            var point:Point = localToGlobal(new Point(0, 0));
            callJS(methodMove, point.x, point.y);
        }
    }
}</pre>
<p> FlexIFrame.js is JavaScript file. It uses your flex IFrame id from to create (html iframe) or use html element (any element) with the same id (id in flash = id in html). So you can use your prefabricated html elements (banners etc).</p>
<pre class="brush: jscript; title: ; notranslate">var FlexIFrame = {
    get: function(id)
    {
        var iframe = document.getElementById(id);
        if(!iframe)
            return FlexIFrame.create(id);
        return iframe;
    },

    create: function(id)
    {
        var iframe = document.createElement('iframe');
        iframe.id = id;
        iframe.frameborder = 0;
        iframe.style.position = &quot;absolute&quot;;
        iframe.style.zIndex = 1;
        iframe.style.border = &quot;none&quot;;
        document.body.insertBefore(iframe, document.body.firstChild);
        return iframe;
    },

    resize: function(id, width, height)
    {
        var iframe = FlexIFrame.get(id);
        iframe.style.width = width + &quot;px&quot;;
        iframe.style.height = height + &quot;px&quot;;
    },

    move: function(id, x, y)
    {
        var iframe = FlexIFrame.get(id);
        iframe.style.left = x + &quot;px&quot;;
        iframe.style.top = y + &quot;px&quot;;
    },

    navigate: function(id, url)
    {
        var iframe = FlexIFrame.get(id);
        iframe.src = url;
    },

    visibility: function(id, visible)
    {
        var iframe = FlexIFrame.get(id);
        iframe.style.display = visible ? &quot;block&quot; : &quot;none&quot;;
    }
}</pre>
<p>This is simple applicationion presenting draggable TitleWindow with &#8220;web browser&#8221; inside:</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[
    private function init():void
    {
        go();
    }

    private function go():void
    {
        iframe.url = iframeURL.text;
    }

    private function mouseDownHandler():void
    {
        container.startDrag();
        container.addEventListener(Event.ENTER_FRAME, enterFrameDrag);
    }

    private function mouseUpHandler():void
    {
        container.stopDrag();
    }

    private function enterFrameDrag(event:Event):void
    {
        iframe.positionChanged = true;
        iframe.invalidateProperties();
    }
]]&gt;
&lt;/mx:Script&gt;
&lt;mx:TitleWindow id=&quot;container&quot; layout=&quot;vertical&quot; width=&quot;300&quot; height=&quot;300&quot;
    mouseDown=&quot;mouseDownHandler()&quot; mouseUp=&quot;mouseUpHandler()&quot; &gt;
    &lt;mx:HBox width=&quot;100%&quot;&gt;
        &lt;mx:TextInput id=&quot;iframeURL&quot; text=&quot;http://blog.yoz.sk&quot; width=&quot;100%&quot;
            enter=&quot;go()&quot;/&gt;
        &lt;mx:Button label=&quot;Go&quot; click=&quot;go()&quot;/&gt;
    &lt;/mx:HBox&gt;
    &lt;html:IFrame width=&quot;100%&quot; height=&quot;100%&quot; id=&quot;iframe&quot; autoResize=&quot;true&quot;/&gt;
&lt;/mx:TitleWindow&gt;
&lt;/mx:Application&gt;</pre>
<p>Finally do not forget to add flexiframe.js into your .html file:</p>
<pre class="brush: xml; title: ; notranslate">&lt;html&gt;
    &lt;head&gt;
        &lt;script type=&quot;text/javascript&quot; src=&quot;js/flexiframe.js&quot;&gt;&lt;/script&gt;
        ...</pre>
<p>Update (Feb 8, 2010): flexiframe.js resize() method uses style property for width and height (instead of original html element width, height)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2009/10/flex-iframe-web-browser-in-flash/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Code optimization</title>
		<link>http://blog.yoz.sk/2009/10/code-optimization/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=code-optimization</link>
		<comments>http://blog.yoz.sk/2009/10/code-optimization/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 12:25:36 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[break]]></category>
		<category><![CDATA[continue]]></category>
		<category><![CDATA[nesting]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://blog.yoz.sk/?p=339</guid>
		<description><![CDATA[First, my golden rule: method with more than 12 rows is too long. Methods should be short, simple, clean and reusable. In most cases your methods fits into 5-12 rows. If not, you should consider rewriting your methods. Look at the next code. There is too much nested tests. Soon you get lost with more [...]]]></description>
			<content:encoded><![CDATA[<p>First, my golden rule: <strong>method with more than 12 rows is too long</strong>. Methods should be short, simple, clean and reusable. In most cases your methods fits into 5-12 rows. If not, you should consider rewriting your methods.</p>
<p>Look at the next code. There is too much nested tests. Soon you get lost with more and more nested levels:</p>
<pre class="brush: as3; title: ; notranslate">function gimmeResult(a, b, c)
{
    var result;
    if(a)
    {
        if(b || c)
        {
            if(b &amp;&amp; c &lt; 0)
            {
                result = 1;
            }
            else
            {
                result = 2;
                // where am I?
            }
        }
        else
        {
            result = 3;
        }
    }
    else
    {
        result = 4;
    }
    return result;
}</pre>
<p>Try to linearize code, it is much more cleaner for reading when no multiple nesting used:</p>
<pre class="brush: as3; title: ; notranslate">function gimmeResult(a, b, c)
{
    if(!a)
        return 4;
    if(!b &amp;&amp; !c)
        return 3;
    if(b &amp;&amp; c &lt; 0)
        return 1;
    return 2;
}</pre>
<p><span id="more-339"></span></p>
<p>Sometimes your function does more things than it should. In this case, it chooses item and operate over it. But is it really good to use it this way?</p>
<pre class="brush: as3; title: ; notranslate">function doSomething(key)
{
    for(i in list)
    {
        if(i == key)
        {
            if(item[i].value &gt; 0)
            {
                item[i].value2 = 1;
            }
            else
            {
                item[i].value2 = 2;
            }
            if(item[i].value3 == 100)
            {
                while(item[i].value3 &gt; 0)
                {
                    // where the hell I am now
                    item[i].value3--;
                }
            }
        }
    }
}</pre>
<p>Split your code into separated functions. One selects your item, other operates over item. Result code is more cleaner and reusable.</p>
<pre class="brush: as3; title: ; notranslate">function doSomething(key)
{
    item = getItem(key);
    if(!item)
        return;
    item.value2 = item.value &gt; 0 ? 1 : 2;
    if(item.value3 != 100)
        return;
    while(item.value3 &gt; 0)
        item.value3--;
}

function getItem(key)
{
    for(i in list)
        if(i == key)
            return list[i];
    return null;
}</pre>
<p>Using <strong>continue</strong> in while cycle causes the current iteration to skip and go to the next one. Sometimes you do not need more processing from current iteration:</p>
<pre class="brush: as3; title: ; notranslate">while(someIterator)
{
    // some processes here
    if(someIterator != &quot;someValue&quot;)
    {
        // some processes here
        // and here
        // and here
    }
}
</pre>
<p>Using <strong>continue</strong> removes nesting, code is cleaner:</p>
<pre class="brush: as3; title: ; notranslate">while(someIterator)
{
    // some processes here
    if(someIterator == &quot;someValue&quot;)
        continue;
    // some processes here
    // and here
    // and here
}
</pre>
<p>When you do not need more iterations&#8230;</p>
<pre class="brush: as3; title: ; notranslate">i = 100;
j = 0;
while(i)
{
    if(i &gt; 90)
        j++;
    i--;
}
// 100 iterations means 100 &quot;i &gt; 50&quot; tests
</pre>
<p>&#8230; you can use <strong>break</strong> to stop current while cycle and save unnecessary processing:</p>
<pre class="brush: as3; title: ; notranslate">i = 100;
j = 0;
while(i)
{
    if(i &lt;= 90)
        break;
    j++;
    i--;
}
// 10 iterations means 10 &quot;i &lt;= 50&quot; tests</pre>
<p>Where to go from here:</p>
<ul>
<li><a href="http://blog.yoz.sk/2010/05/myth-buster-benchmarking-loops/">Myth Buster – Benchmarking Loops</a></li>
<li><a href="http://www.insideria.com/2009/04/51-actionscript-30-and-flex-op.html">Round up of ActionScript 3.0 and Flex optimization techniques and practices</a></li>
<li><a href="http://help.adobe.com/en_US/as3/mobile/flashplatform_optimizing_content.pdf">Optimizing Performance for theADOBE® FLASH® PLATFORM</a></li>
<li><a href="http://jacksondunstan.com/articles/663">The Size of Empty</a></li>
<li><a href="http://jpauclair.net/2010/03/15/flash-asm/">Faster arithmetic &#8211; Flash Assembler (not ByteCode) : And you thought it couldn’t get faster</a></li>
<li><a href="http://www.gskinner.com/talks/quick/">GSkinner Talks</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2009/10/code-optimization/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

