<?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>FLEX{er} &#187; Javascript</title>
	<atom:link href="http://www.flexer.info/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flexer.info</link>
	<description>flex developers web corner</description>
	<lastBuildDate>Tue, 04 Oct 2011 16:23:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
  <link>http://www.flexer.info</link>
  <url>http://www.flexer.info/favicon.ico</url>
  <title>FLEX{er}</title>
</image>
		<item>
		<title>Deep Linking with SWFAddress and IE6 problem</title>
		<link>http://www.flexer.info/2009/02/20/deep-linking-with-swfaddress-and-ie6-problem/</link>
		<comments>http://www.flexer.info/2009/02/20/deep-linking-with-swfaddress-and-ie6-problem/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 12:19:36 +0000</pubDate>
		<dc:creator>Andrei Ionescu</dc:creator>
				<category><![CDATA[Bugs]]></category>
		<category><![CDATA[Flash Player]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[deep linking]]></category>

		<guid isPermaLink="false">http://www.flexer.info/?p=568</guid>
		<description><![CDATA[This week I&#8217;ve been working on a project that uses deep linking with SWFAddress library. SWFAddress is a useful tool that lets you go to a specified part of a flash site by changing the browser&#8217;s url.
Anyway this project was in part completed but had to do some changes and fix some bugs. Most bugs [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-right: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.flexer.info%2F2009%2F02%2F20%2Fdeep-linking-with-swfaddress-and-ie6-problem%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.flexer.info%2F2009%2F02%2F20%2Fdeep-linking-with-swfaddress-and-ie6-problem%2F" height="61" width="51" /></a></div><div style="float: right; margin-right: 10px"><a class="google_buzz"  
href="http://www.google.com/reader/link?url=http://www.flexer.info/2009/02/20/deep-linking-with-swfaddress-and-ie6-problem/&title=Deep+Linking+with+SWFAddress+and+IE6+problem&srcURL=http://www.flexer.info" target="_blank" rel="nofollow"><img
src="http://www.flexer.info/wp-content/plugins/google-buzz-button-for-wordpress/images/google-buzz.png" alt="Google Buzz" /></a></div><p>This week I&#8217;ve been working on a project that uses deep linking with <a href="http://www.asual.com/swfaddress/" target="_blank">SWFAddress</a> library. SWFAddress is a useful tool that lets you go to a specified part of a flash site by changing the browser&#8217;s url.</p>
<p>Anyway this project was in part completed but had to do some changes and fix some bugs. Most bugs were found using Internet Explorer 6. If you wonder why IE6 in the era of Firefox and IE8, because today it has 25% of the market (but going down which is a very good thing) and the client needs to be compliant with it. IE6 is not working on Vista so I had to use a Virtual PC image of XP Sp3 to test with IE6. </p>
<p>The biggest bug found was related to SWFAddress Javascript classes. The site continued to jump from one page to another without no reason. I want to mention that this bug did not appeared on Firefox or IE8 or other browser and I have the following browsers for testing: Firefox, Opera, IE8, SeaMonkey and Google Chrome.</p>
<p>I did some research on Google and I found a comment, &#8220;Left by Niklas at Thu, 2 Nov 4:07 PM&#8221; on the following page: <a href="http://www.asual.com/blog/swfaddress/swfaddress-deep-linking-for-flash.html" target="_blank">http://www.asual.com/blog/swfaddress/swfaddress-deep-linking-for-flash.html</a>. That way I found that for IE6 the <strong>swfaddress.html</strong> file must be placed in the same folder where <strong>swfaddress.js</strong> resides. That didn&#8217;t resolved it then I started to test the examples from the SWFAddress zip file. </p>
<p>I&#8217;ve seen that in adobe folder is an approach like mine: use on Flash/Flex Javascript classes with SWFAddress. Tested it on IE6 and is working. Then i started comparing with my project. The difference was that in my project I used also the Flash/Flex history Javascript class. So I removed the following line from my project:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script src=&quot;history/history.js&quot; language=&quot;javascript&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>That fixed my bug. Two this I had to do:</p>
<ol>
<li>add <strong>swfaddress.html</strong></li>
<li>remove the Flash/Flex history Javascript libraries</li>
</ol>
<p>As far us I noticed if you used <a href="http://code.google.com/p/swfobject/" target="_blank">SWFObject</a> with <a href="http://www.asual.com/swfaddress/" target="_blank">SWFAddress</a> this problem will not occur because, I think, SWFObject do not uses history.</p>
<p>I hope, in the future, to write an entire article dedicated to deep linking, but I need time for that.</p>
<p>Some resources bellow:<br />
<a href="http://www.asual.com/blog/swfaddress/swfaddress-deep-linking-for-flash.html" target="_blank">http://www.asual.com/blog/swfaddress/swfaddress-deep-linking-for-flash.html</a><br />
<a href="http://www.asual.com/swfaddress/" target="_blank">http://www.asual.com/swfaddress/</a><br />
<a href="http://code.google.com/p/swfobject/" target="_blank">http://code.google.com/p/swfobject/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flexer.info/2009/02/20/deep-linking-with-swfaddress-and-ie6-problem/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How To Scroll To Embeded SWF Object</title>
		<link>http://www.flexer.info/2008/10/29/how-to-scroll-to-embeded-swf-object/</link>
		<comments>http://www.flexer.info/2008/10/29/how-to-scroll-to-embeded-swf-object/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 15:01:03 +0000</pubDate>
		<dc:creator>Andrei Ionescu</dc:creator>
				<category><![CDATA[How to]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[RIA]]></category>
		<category><![CDATA[embed]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[scroll]]></category>

		<guid isPermaLink="false">http://www.flexer.info/?p=279</guid>
		<description><![CDATA[These days I was struggling with this problem: I needed to scroll the page (using javascript) to the embeded swf object. After some search and tests I used the following function (found here) to find the Y position of the object.

function findPosY&#40;obj&#41; &#123;
    var curtop = 0;
    if&#40;obj.offsetParent&#41;
  [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-right: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.flexer.info%2F2008%2F10%2F29%2Fhow-to-scroll-to-embeded-swf-object%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.flexer.info%2F2008%2F10%2F29%2Fhow-to-scroll-to-embeded-swf-object%2F" height="61" width="51" /></a></div><div style="float: right; margin-right: 10px"><a class="google_buzz"  
href="http://www.google.com/reader/link?url=http://www.flexer.info/2008/10/29/how-to-scroll-to-embeded-swf-object/&title=How+To+Scroll+To+Embeded+SWF+Object&srcURL=http://www.flexer.info" target="_blank" rel="nofollow"><img
src="http://www.flexer.info/wp-content/plugins/google-buzz-button-for-wordpress/images/google-buzz.png" alt="Google Buzz" /></a></div><p>These days I was struggling with this problem: I needed to scroll the page (using javascript) to the embeded swf object. After some search and tests I used the following function (found <a href="http://blog.firetree.net/2005/07/04/javascript-find-position/" target="_blank">here</a>) to find the <strong>Y</strong> position of the object.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> findPosY<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> curtop <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">offsetParent</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            curtop <span style="color: #339933;">+=</span> obj.<span style="color: #660066;">offsetTop</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>obj.<span style="color: #660066;">offsetParent</span><span style="color: #009900;">&#41;</span>
                <span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
            obj <span style="color: #339933;">=</span> obj.<span style="color: #660066;">offsetParent</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">y</span><span style="color: #009900;">&#41;</span>
        curtop <span style="color: #339933;">+=</span> obj.<span style="color: #660066;">y</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> curtop<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The next step was to use it with according to my need. So I taken the following steps:</p>
<ol>
<li>get the object using <strong>getElementById</strong> (my object has an <strong>id</strong> set)</li>
<li>put the obtained object into the <strong>findPosY</strong> funtion to get its <strong>Y</strong> position</li>
<li>use scrollTo function to scroll the page to the desired <strong>Y</strong> position
</ol>
<p>But&#8230; big problem occurred. Firefox browser is returning a totally different <strong>Y</strong> position (afterward I found that it happens to all Gecko based browsers). The difference is approximately the height of the swf object. By trial and error I found that I have to substract the swf height and add 15 pixels. </p>
<p>Using embeds doesn&#8217;t give you the same problem. Instead of <strong>document.getElementById()</strong> function use <strong>document.embeds[]</strong> array and you won&#8217;t have this problem. You can test all these following this <a href="http://www.flexer.info/wp-content/uploads/2008/10/test_object_embed.html" target="_blank">link</a>.</p>
<p>The scrolling method is here:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> scrollToMovie<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> cy <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// get the y position</span>
    cy <span style="color: #339933;">=</span> findPosY<span style="color: #009900;">&#40;</span>obj<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #006600; font-style: italic;">// Gecko engine work arround</span>
    <span style="color: #006600; font-style: italic;">// </span>
    <span style="color: #006600; font-style: italic;">// Gecko returns another value (when using the</span>
    <span style="color: #006600; font-style: italic;">// object tag instead of embed tag) which is </span>
    <span style="color: #006600; font-style: italic;">// somehow equal with:</span>
    <span style="color: #006600; font-style: italic;">//     y position + object height - 15</span>
    <span style="color: #006600; font-style: italic;">// (this was found by trial and error)</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>obj.<span style="color: #660066;">tagName</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">&quot;OBJECT&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">userAgent</span>.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Gecko&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!=-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            cy <span style="color: #339933;">=</span> cy <span style="color: #339933;">-</span> obj.<span style="color: #660066;">height</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">15</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #006600; font-style: italic;">// scroll to the movie</span>
    window.<span style="color: #660066;">scrollTo</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> cy <span style="color: #339933;">-</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Please notice that we check if <strong>OBJECT</strong> is used and if the browser is <strong>Gecko</strong>. This is it. Archive with the HTML file can be downloaded at the end. If you&#8217;ll open the HTML file from your desktop a notification window will appear regarding flash security issues.</p>
<p>The test page is here: <a href="http://www.flexer.info/wp-content/uploads/2008/10/test_object_embed.html" target="_blank">http://www.flexer.info/wp-content/uploads/2008/10/test_object_embed.html</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flexer.info/2008/10/29/how-to-scroll-to-embeded-swf-object/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Browser Window Close Event and Flex Applications</title>
		<link>http://www.flexer.info/2008/02/25/browser-window-close-event-and-flex-applications/</link>
		<comments>http://www.flexer.info/2008/02/25/browser-window-close-event-and-flex-applications/#comments</comments>
		<pubDate>Mon, 25 Feb 2008 13:27:39 +0000</pubDate>
		<dc:creator>Andrei Ionescu</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[MXML]]></category>
		<category><![CDATA[RIA]]></category>

		<guid isPermaLink="false">http://www.flexer.info/2008/02/25/browser-window-close-event-and-flex-applications/</guid>
		<description><![CDATA[When speaking about RIA one of many nice usabilities is that to be able to give feedback to the user when it comes to critical actions like submitting important data, saving work, etc. Let&#8217;s have the following example: You log in into a RIA with your user and password, you do changes to your data [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-right: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.flexer.info%2F2008%2F02%2F25%2Fbrowser-window-close-event-and-flex-applications%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.flexer.info%2F2008%2F02%2F25%2Fbrowser-window-close-event-and-flex-applications%2F" height="61" width="51" /></a></div><div style="float: right; margin-right: 10px"><a class="google_buzz"  
href="http://www.google.com/reader/link?url=http://www.flexer.info/2008/02/25/browser-window-close-event-and-flex-applications/&title=Browser+Window+Close+Event+and+Flex+Applications&srcURL=http://www.flexer.info" target="_blank" rel="nofollow"><img
src="http://www.flexer.info/wp-content/plugins/google-buzz-button-for-wordpress/images/google-buzz.png" alt="Google Buzz" /></a></div><p>When speaking about RIA one of many nice usabilities is that to be able to give feedback to the user when it comes to critical actions like submitting important data, saving work, etc. Let&#8217;s have the following example: You log in into a RIA with your user and password, you do changes to your data but you didn&#8217;t press save or your data is saved at logout and you close the window. All your work is lost and frustration takes its place. This article we will look into JavaScript, DOM and Flex to be able to tell the user to save its work before closing the browser window by a confirmation. Many of you have seen that in action in Ajax sites and I think one good example is GMail which display a confirmation dialog when trying to leave a page where you create a new message without saving.</p>
<p>We will build a simple case: a flex application with a checkbox that will enable or disable the checking system when closing the browser window. </p>
<p>You can use this afterwards in applications where you need to check if data is saved, if you&#8217;re logged in or out and in many other cases.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:Application xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> 
    layout=<span style="color: #ff0000;">&quot;absolute&quot;</span> applicationComplete=<span style="color: #ff0000;">&quot;init();&quot;</span><span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
        <span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
            <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> cancloseornot<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
            <span style="color: #66cc66;">&#123;</span>
                <span style="color: #b1b100;">return</span> closeornot.<span style="color: #006600;">selected</span>;
            <span style="color: #66cc66;">&#125;</span>
&nbsp;
            <span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
            <span style="color: #66cc66;">&#123;</span>
                ExternalInterface.<span style="color: #006600;">addCallback</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;cancloseornot&quot;</span>,
                                               cancloseornot<span style="color: #66cc66;">&#41;</span>;
            <span style="color: #66cc66;">&#125;</span>
        <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;</span>mx:CheckBox id=<span style="color: #ff0000;">&quot;closeornot&quot;</span> label=<span style="color: #ff0000;">&quot;Direct close? (Checked=Yes)&quot;</span> <span style="color: #66cc66;">/&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:Application<span style="color: #66cc66;">&gt;</span></pre></div></div>

<p>At application initialization (function <strong>init</strong>) we instruct the player to make available to the HTML document &#8211; through <strong>ExternalInterface</strong> &#8211; the <strong>cancloseornot</strong> function which is returning if the checkbox is checked or not. <strong>addCallback</strong> method of ExternalInterface takes 2 parameters:</p>
<ol>
<li>the external name of the function made available to HTML document and</li>
<li>the name of the function inside the flex application</li>
</ol>
<p>This way our cancloseornot function will be available outside flex application to HTML document and JavaScript.</p>
<p>In the HTML document we set the <strong>onbeforeunload</strong> event handler:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">onbeforeunload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>$<span style="color: #009900;">&#123;</span>application<span style="color: #009900;">&#125;</span>.<span style="color: #660066;">cancloseornot</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;Checkbox checked.&quot;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>onbeforeunload</strong> event is occurring for the following actions:</p>
<ol>
<li>close</li>
<li>moving away from the page: back, forward, following links</li>
</ol>
<p><strong>${application}</strong> is the <strong>id</strong> of the swf file that is resulting after compiling the flex application (the object has id and embed has name) and in the template file everything with the pattern ${variable} will be replaced at compile time with values. So by this way both swf and our JavaScript will have the same application id. </p>
<p>It is <strong>IMPORTANT</strong> to know that <strong>ExternalInterface</strong> have security requirements as described <a href="http://livedocs.adobe.com/flex/201/html/passingarguments_086_19.html" target="_blank">here</a>. To be short: &#8220;<em>By default, an HTML page can only communicate with the ActionScript in your Flex application if it originates from the same domain.</em>&#8221;</p>
<p>With this thing we can provide nice usability to users and keep them out of frustration.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flexer.info/2008/02/25/browser-window-close-event-and-flex-applications/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

