<?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>if( ExternalInterface.available ){ &#187; JavaScript</title>
	<atom:link href="http://blog.sebastian-martens.de/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sebastian-martens.de</link>
	<description></description>
	<lastBuildDate>Tue, 24 Aug 2010 21:06:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>User Mouse Tracking / Website Research</title>
		<link>http://blog.sebastian-martens.de/2010/07/user-mouse-tracking-website-research/</link>
		<comments>http://blog.sebastian-martens.de/2010/07/user-mouse-tracking-website-research/#comments</comments>
		<pubDate>Sun, 11 Jul 2010 11:08:24 +0000</pubDate>
		<dc:creator>Sebastian.Martens</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Selfnote]]></category>
		<category><![CDATA[Click Test]]></category>
		<category><![CDATA[Mousetracking]]></category>
		<category><![CDATA[useability test]]></category>
		<category><![CDATA[user tests]]></category>
		<category><![CDATA[Usertracking]]></category>
		<category><![CDATA[Website Analytics]]></category>
		<category><![CDATA[website research]]></category>
		<category><![CDATA[websitetest]]></category>

		<guid isPermaLink="false">http://blog.sebastian-martens.de/?p=478</guid>
		<description><![CDATA[If you use website statistic tools &#8211; and thats something i guess everybody is interested in &#8211; you got well numbers about how many users visit your website and exactly which page of your website. You will also know from which other website the came and which key words they used within Google to get [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin:0px 0px 0px 0px;"></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2010%2F07%2Fuser-mouse-tracking-website-research%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2010%2F07%2Fuser-mouse-tracking-website-research%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://blog.sebastian-martens.de/wp-content/uploads/2010/07/mouse-move-tracker.jpg"><img src="http://blog.sebastian-martens.de/wp-content/uploads/2010/07/mouse-move-tracker-150x150.jpg" alt="" title="mouse-move-tracker" width="150" height="150" class="alignnone size-thumbnail wp-image-479" /></a></p>
<p>If you use website statistic tools &#8211; and thats something i guess everybody is interested in &#8211; you got well numbers about how many users visit your website and exactly which page of your website. You will also know from which other website the came and which key words they used within Google to get to your page. Each of this are very important facts for exmaple for SEO aspects, etc. For example Google Analytics is of course a great free tool for this ( include the old discussion how many more should Google know about you and your website ).<span id="more-478"></span></p>
<p>What i also want to know is where do the users navigate best on my website. What are the best places to put links, so the users will find AND click them ( no &#8211; i don&#8217;t plan to put any adds on my website &#8211; just interested ). Google Analytics has an overlay mode. But this will highlight the existing links. So it will show up which links works best. This comes close, but not perfect.</p>
<p>There are some enterprise tools which do such kind of overlay mode with the users mouse movements. But they are too expensive for me. I guess there will be also some free tools available out there, but programming is also fun :) </p>
<p>So i wrote my little tool which will save the users mouse postion each X milliseconds. If the users leavs the current page, it will make one AJAX request and save all mouse coordinates within one file ( currently not in a database, beacuse writing to filesystem is a bit faster ). When you would like to display the users mouse activity just add <strong>#overlay</strong> at the end of the current URL. It will sum up all saved mouse movements and create a grid overlay over your website. By default the grid elements are 10&#215;10 px large. Each grid field get a color by its relative mouse overs. The more often users moved their mouse over these coords the more red the field will be ( see screenshot for example ).</p>
<p>Of couse this is no perfect solution. But because most users move the mouse the same way they also look over the screen this is a very easy way to track such behaviour.</p>
<h5>How to implement:</h5>
<p>It&#8217;S very easy to use. Just extract the ZIP below onto your webserver and put a little piece of JavaScript into your HTML code:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #003366; font-weight: bold;">var</span> mouseMoveTracker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> MouseMoveTracker<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #3366CC;">'rootNodeId'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'contentNode'</span><span style="color: #339933;">,</span>
			<span style="color: #3366CC;">'actionURI'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'../server/'</span><span style="color: #339933;">,</span>
			<span style="color: #3366CC;">'actionURIOverlay'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'../server/result/'</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>The <strong>MouseMoveTracker</strong> class has three major parameters:</p>
<p><em>rootNodeId</em>: The html root node of the tracked section. Because the script id coordinate based it works best with a fixed size layout. Therefor you should enter the Id of the node which has a fixed width and sourrounds all content.</p>
<p><em>actionURI</em>: This is the path to the serverside writing script. To this adress the AJAX requests for writing the user coords will be send.</p>
<p><em>actionURIOverlay</em>: This is the url the script expects to get data from for creating the overlay mode. It will request data via AJAX from this URL after you enter #overlay at the end of the URL and refresh your page.</p>
<p>Feel free to use, modify the code and/or comment here.</p>
<p><a href='http://blog.sebastian-martens.de/wp-content/uploads/2010/07/mouse-move-tracker.zip'>Download mouse-move-tracker.zip (45kB) includes test html file</a></p>
<p>cheers,<br />
Sebastian</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sebastian-martens.de/2010/07/user-mouse-tracking-website-research/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dynamic Resize Flash Application Container / Flash Stage ( without external JavaScript )</title>
		<link>http://blog.sebastian-martens.de/2010/06/resize-flash-application-container/</link>
		<comments>http://blog.sebastian-martens.de/2010/06/resize-flash-application-container/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 12:29:32 +0000</pubDate>
		<dc:creator>Sebastian.Martens</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[resize]]></category>
		<category><![CDATA[resize stage]]></category>

		<guid isPermaLink="false">http://blog.sebastian-martens.de/?p=459</guid>
		<description><![CDATA[[Update: Add complete Flash Builder project source files. ] If you have dynamic content within your Flash application or you have several states or &#8220;pages&#8221; implemented, which all have different content, it might be helpful to resize your flash aplication container within the html- context. For this it&#8217;s not enough to resize the application from [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin:0px 0px 0px 0px;"></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2010%2F06%2Fresize-flash-application-container%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2010%2F06%2Fresize-flash-application-container%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>[<strong>Update</strong>: Add complete Flash Builder project source files. ]<br />
If you have dynamic content within your Flash application or you have several states or &#8220;pages&#8221; implemented, which all have different content, it might be helpful to resize your flash aplication container within the html- context. For this it&#8217;s not enough to resize the application from within the flash application. You also have to resize the surrounding html container. This is the <em>object</em> tag for Mozilla browsers or the <em>embed</em> tag, if the client uses the Internet Explorer.</p>
<p>In each case you have to use the ExternalInterface. You call it from the flash application with parameters for the new height and width value of the flash container. On the other side you have to define an javascript function which do the resize operation with these values.</p>
<p>Here is an AS3 class which already includes the JavaScript part. Soyou don&#8217;t have to define an extra JS function. So you just have to import the AS3 class into your project and your ready to resize you application from Flash.<span id="more-459"></span></p>
<p>There are three methods to call:</p>
<ul>
<li><b><em>resize</em></b>:This method takes two parameters <em>height</em> and <em>width</em> to completly set the absolute height and width of the flash application.</li>
<li><b><em>addHeight</em></b>: Takes one integer parameter. The value will be added to the current height. So &#8220;50&#8243; for 50px more height or &#8220;-20&#8243; for 20px less in height.</li>
<li><b><em>addWidth</em></b>: Takes one integer parameter. The value will be added to the current width. So &#8220;50&#8243; for 50px more width or &#8220;-20&#8243; for 20px less in width.</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * resizes the flash container to needed dimensions 
 * @param height - new needed height 
 * @param width - new needed with
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> resize<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">height</span>:<span style="color: #0066CC;">int</span>, <span style="color: #0066CC;">width</span>:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * adds a specific value (+/-) to current height
 * @param valueHeight
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addHeight<span style="color: #66cc66;">&#40;</span> valueHeight:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * adds a specific value (+/-) to current width
 * @param valueHeight
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addWidth<span style="color: #66cc66;">&#40;</span> valueWidth:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></pre></div></div>

<p>To resize your application you could add an resize event handler to check specific containers for resize and do the resizing via this class in the event handler method. If you have fixed sizes per state you could of course also do it the static way.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * @author: Sebastian Martens; sebastian@sebastian-martens.de
 * @copyright: Creative Commons. Free to use &quot;as is&quot;
 * 
 * Test Application
 */</span> 
package<span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">nonstatics</span>.<span style="color: #006600;">swfSelfResize</span>.<span style="color: #006600;">swfSelfResize</span>;
&nbsp;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
&nbsp;
	<span style="color: #66cc66;">&#91;</span>SWF<span style="color: #66cc66;">&#40;</span>frameRate=<span style="color: #ff0000;">&quot;31&quot;</span>, <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;500&quot;</span>, <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;100&quot;</span>, <span style="color: #0066CC;">backgroundColor</span>=<span style="color: #ff0000;">&quot;0x008866&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> swfSelfResizeTest <span style="color: #0066CC;">extends</span> Sprite<span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> resize:swfSelfResize;
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * constructor
		 */</span> 
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> swfSelfResizeTest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">resize</span> = <span style="color: #000000; font-weight: bold;">new</span> swfSelfResize<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// resize to 500px height, 400px width</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">resize</span>.<span style="color: #006600;">resize</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">500</span>, <span style="color: #cc66cc;">400</span> <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// add 50px height -&gt; 550px height </span>
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">resize</span>.<span style="color: #006600;">addHeight</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">50</span> <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// remove 10px width -&gt; 390px</span>
			<span style="color: #0066CC;">this</span>.<span style="color: #006600;">resize</span>.<span style="color: #006600;">addWidth</span><span style="color: #66cc66;">&#40;</span> -<span style="color: #cc66cc;">10</span> <span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><a href='http://blog.sebastian-martens.de/wp-content/uploads/2010/06/com1.zip'>Download com.nonstatics.swfSelfResize.as (12kB)</a><br />
<a href='http://blog.sebastian-martens.de/wp-content/uploads/2010/06/bin-debug.zip'>Download bin-debug (20kB)</a><br />
<a href='http://blog.sebastian-martens.de/wp-content/uploads/2010/06/swfSelfResize.zip'>Full Flash Builder Project (131kB)</a></p>
<p>Be aware of the security model of the flash player! This won&#8217;t work on local filesystem (file://xyz). So please use it on your server (http://www.yourdomain.com) or with your locally installed testserver (http://localhost/whatever).</p>
<p>Hope this helps you.</p>
<p>cheers,<br />
Sebastian</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sebastian-martens.de/2010/06/resize-flash-application-container/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Quick start with Flash ExternalInterface class</title>
		<link>http://blog.sebastian-martens.de/2010/05/quick-start-with-flash-externalinterface-class/</link>
		<comments>http://blog.sebastian-martens.de/2010/05/quick-start-with-flash-externalinterface-class/#comments</comments>
		<pubDate>Fri, 21 May 2010 08:52:45 +0000</pubDate>
		<dc:creator>Sebastian.Martens</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[flash javascript bridge]]></category>
		<category><![CDATA[HowTo]]></category>

		<guid isPermaLink="false">http://blog.sebastian-martens.de/?p=406</guid>
		<description><![CDATA[The ExternalInterface class allows you to communicate with the Flash wrapping container, which is usually the HTML page with JavaScript capeability. It allows you to send data from ActionsScript to JavaScript and vice versa. The ExternalInterface class is implemented for nearly all current browsers. Please see the documentation for a detailed list of the supported [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin:0px 0px 0px 0px;"></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2010%2F05%2Fquick-start-with-flash-externalinterface-class%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2010%2F05%2Fquick-start-with-flash-externalinterface-class%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>The <a href="http://livedocs.adobe.com/flash/9.0_de/ActionScriptLangRefV3/flash/external/ExternalInterface.html" rel="nofollow">ExternalInterface</a> class allows you to communicate with the Flash wrapping container, which is usually the HTML page with JavaScript capeability. It allows you to send data from ActionsScript to JavaScript and vice versa.</p>
<p>The ExternalInterface class is implemented for nearly all current browsers. Please see the documentation for a detailed list of the supported browsers <a href="http://livedocs.adobe.com/flash/9.0_de/ActionScriptLangRefV3/flash/external/ExternalInterface.html" rel="nofollow">here</a>.</p>
<p>All five attributes and methods are static, so you don&#8217;t need an instance of this class.</p>
<h4>Make sure ExternalInterface is available</h4>
<p>When using the ExternalInterface you should make sure it&#8217;s available. So please test the boolean value <em>ExternalInterface.available</em>:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> ExternalInterface.<span style="color: #006600;">available</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
  ExternalInterface.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span> .... <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><span id="more-406"></span></p>
<h4>Call JavaScript from ActionScript</h4>
<p>To call a JavaScript function from ActionScript you just the the method <em>ExternalInterface.call</em>. First argument must be the function name of the JavaScript method you would like to call. All other parameters will hand over as parameters to the JavaScript method. These parameters should be primitive types like String, Number or even simple Object.</p>
<p>JavaScript:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> myJSFunction<span style="color: #009900;">&#40;</span> param1<span style="color: #339933;">,</span> param2<span style="color: #339933;">,</span> param3 <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> param1 <span style="color: #339933;">+</span> <span style="color: #3366CC;">': '</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span> parseInt<span style="color: #009900;">&#40;</span>param2<span style="color: #339933;">,</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> parseInt<span style="color: #009900;">&#40;</span>param3<span style="color: #339933;">,</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #006600; font-style: italic;">// parseInt is definetly the nicer way</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>ActionScript:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">private</span> <span style="color: #003366; font-weight: bold;">function</span> externalInterfaceTest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">void</span><span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> a<span style="color: #339933;">:</span>int <span style="color: #339933;">=</span> <span style="color: #CC0000;">4</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> b<span style="color: #339933;">:</span>int <span style="color: #339933;">=</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> c<span style="color: #339933;">:</span>String <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Hello World&quot;</span><span style="color: #339933;">;</span>
&nbsp;
   ExternalInterface.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;myJSFunction&quot;</span><span style="color: #339933;">,</span> c<span style="color: #339933;">,</span> b<span style="color: #339933;">,</span> a <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This will show up an alert window with text and calculated numbers.</p>
<p>The <em>call</em> method will also handle return values of the JavaScript method. At least for this you should be aware of the security model of the flash player, otherwise you might get an <em>null</em> value instead the expected result. Therefore please set the flash parameter <em>allowScriptAccess</em> to <em>always</em> and the allowed domain within your flash application.</p>
<p>HTML:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;param name=&quot;allowScriptAccess&quot; value=&quot;always&quot; /&gt;
   &lt;embed allowScriptAccess=&quot;sameDomain&quot; [...]</pre></div></div>

<p>SWFObject:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> params <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
   params.<span style="color: #660066;">allowscriptaccess</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;always&quot;</span><span style="color: #339933;">;</span>
swfobject.<span style="color: #660066;">embedSWF</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;flvplayer.swf&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;videoPlayer&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;650&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;530&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;9.0.28&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;expressInstall.swf&quot;</span><span style="color: #339933;">,</span> flashvars<span style="color: #339933;">,</span> params<span style="color: #339933;">,</span> attributes<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Flash App:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">flash.<span style="color: #0066CC;">system</span>.<span style="color: #006600;">Security</span>.<span style="color: #0066CC;">allowDomain</span><span style="color: #66cc66;">&#40;</span> yourDomain <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>If you configured that way you will be able to recieve return values from your JavaScript function and use them in your ActionScript method.</p>
<p>JavaScript:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> myJSFunction<span style="color: #009900;">&#40;</span> val <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;JavaScripts says: &quot;</span> <span style="color: #339933;">+</span> val<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>ActionScript:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> exInterfaceTest<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
   <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> ExternalInterface.<span style="color: #006600;">available</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
      <span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span> ExternalInterface.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;myJSFunction&quot;</span>, <span style="color: #ff0000;">&quot;Hello World&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>; 
   <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h4>Call ActionScript method from JavaScript</h4>
<p>Its also possible to start the other way round, that you call an ActionScript method from an JavaScript function. Therefor you have to register an callback function within your AS code. You will connect any method name with an existing method.</p>
<p>This is done with the <em>addCallback</em> method. First argument is any function name you like. This will be the function you could call within JavaScript. The second argument is an function reference or closure which should be handle the call. All arguments will be passed to this method.</p>
<p>The JavaScript side function is an object of the flash wrapping container ( Object-Element / Embed-Element ) which should be referenced by it&#8217;s id/name. Also for this direction arguments and return values are possible.</p>
<p>HTML/JavaScript:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"> <span style="color: #339933;">&lt;</span>script language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;JavaScript&quot;</span><span style="color: #339933;">&gt;</span>
     <span style="color: #003366; font-weight: bold;">var</span> init <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
     <span style="color: #003366; font-weight: bold;">var</span> flashObjId <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;myExInterfaceTest&quot;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #006600; font-style: italic;">// flash is initialised and AS methods could be called</span>
     <span style="color: #003366; font-weight: bold;">function</span> flashReady<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         init <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
         callAsMethod<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
     <span style="color: #003366; font-weight: bold;">function</span> callAsMethod<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #003366; font-weight: bold;">var</span> objRef<span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> window<span style="color: #009900;">&#91;</span> flashObjId <span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
             <span style="color: #006600; font-style: italic;">// none microsoft</span>
             objRef <span style="color: #339933;">=</span> window<span style="color: #009900;">&#91;</span>flashObjId<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
             objRef <span style="color: #339933;">=</span> document<span style="color: #009900;">&#91;</span>flashObjId<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
&nbsp;
         <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> objRef.<span style="color: #660066;">jsCallHandler</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;myArguments&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
 <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
 <span style="color: #339933;">&lt;</span>body<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>object classid<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot;</span>
             id<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;myExInterfaceTest&quot;</span> width<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;100&quot;</span> height<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;100&quot;</span>
             codebase<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab&quot;</span><span style="color: #339933;">&gt;</span>
         <span style="color: #339933;">&lt;</span>param <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;movie&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;test.swf&quot;</span> <span style="color: #339933;">/&gt;</span>
         <span style="color: #339933;">&lt;</span>param <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;allowScriptAccess&quot;</span> value<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;sameDomain&quot;</span> <span style="color: #339933;">/&gt;</span>
         <span style="color: #339933;">&lt;</span>embed src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;test.swf&quot;</span> quality<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;high&quot;</span>
             width<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;100&quot;</span> height<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;100&quot;</span> <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;myExInterfaceTest&quot;</span> align<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;middle&quot;</span>
             allowScriptAccess<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;sameDomain&quot;</span> pluginspage<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://www.macromedia.com/go/getflashplayer_de&quot;</span><span style="color: #339933;">&gt;</span>
         <span style="color: #339933;">&lt;/</span>embed<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;/</span>object<span style="color: #339933;">&gt;</span>
&nbsp;
 <span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span></pre></div></div>

<p>ActionScript part:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// This method is called when initialisation is finished and application is ready</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> initCompleteHandler<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
   <span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> ExternalInterface.<span style="color: #006600;">available</span> <span style="color: #66cc66;">&#41;</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;jsCallHandler&quot;</span>, javaScriptHandlerMethod <span style="color: #66cc66;">&#41;</span>;
       ExternalInterface.<span style="color: #0066CC;">call</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;flashReady&quot;</span> <span style="color: #66cc66;">&#41;</span>;
   <span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span> 
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> javaScriptHandlerMethod<span style="color: #66cc66;">&#40;</span> arg <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;ActionScript says:&quot;</span> + arg <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>For a large number of JavaScript calls from ActionScript to JavaScript i regular use the <a href="/jscallstack">jsCallStack</a> class which implements an stack of javascript calls to handle this timed and avoid doubled calls. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sebastian-martens.de/2010/05/quick-start-with-flash-externalinterface-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preload assets with JavaScript, load-complete callback for single assets include SWF/Flash</title>
		<link>http://blog.sebastian-martens.de/2010/05/preload-assets-with-javascript-load-complete-callback-for-single-assets-include-swfflash/</link>
		<comments>http://blog.sebastian-martens.de/2010/05/preload-assets-with-javascript-load-complete-callback-for-single-assets-include-swfflash/#comments</comments>
		<pubDate>Sat, 15 May 2010 13:02:42 +0000</pubDate>
		<dc:creator>Sebastian.Martens</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flash callback]]></category>
		<category><![CDATA[flash loaded event]]></category>
		<category><![CDATA[Preloader]]></category>

		<guid isPermaLink="false">http://blog.sebastian-martens.de/?p=383</guid>
		<description><![CDATA[Currently i need to know within JavaScript when a SWF-file was loaded completly. You could easily handle this with a single ExternalInterface call from within the Flash-application. This is not a very nice solution if this has to be done for each of you flash-applications. This is the neccesary way if you also have to [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin:0px 0px 0px 0px;"></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2010%2F05%2Fpreload-assets-with-javascript-load-complete-callback-for-single-assets-include-swfflash%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2010%2F05%2Fpreload-assets-with-javascript-load-complete-callback-for-single-assets-include-swfflash%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Currently i need to know within JavaScript when a SWF-file was loaded completly. You could easily handle this with a single ExternalInterface call from within the Flash-application. This is not a very nice solution if this has to be done for each of you flash-applications. This is the neccesary way if you also have to access the flash-application from outside. But in my case i just need to know when the flash is loaded and available in the browser cache. </p>
<p>For this i wrote the <em>swfJSPreLoader</em>. This preloader accepts an array of assets you would like to preload. Internally it will create an flash-application which does the preloading. You could define several callback handlers. So JavaScript gets to know when all assets are loaded or each single asset is loaded including SWF-files.<span id="more-383"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #003366; font-weight: bold;">var</span> swfJSPreLoaderConfig <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #3366CC;">'_swfPath'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'./'</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// configure path to preloader SWF file</span>
&nbsp;
		<span style="color: #3366CC;">'assets'</span><span style="color: #339933;">:</span><span style="color: #009900;">&#91;</span>	<span style="color: #3366CC;">'assets/teaser.swf'</span><span style="color: #339933;">,</span>
				 	<span style="color: #3366CC;">'assets/img2.jpg'</span><span style="color: #339933;">,</span>
				 	<span style="color: #3366CC;">'--error--'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
&nbsp;
		<span style="color: #3366CC;">'assetLoaded'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> asset<span style="color: #339933;">,</span> bytes<span style="color: #339933;">,</span> <span style="color: #000066;">status</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span> asset <span style="color: #339933;">+</span> <span style="color: #3366CC;">' loaded ('</span> <span style="color: #339933;">+</span> bytes <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
		<span style="color: #3366CC;">'loadComplete'</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;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'all assets loaded. totally loaded bytes: '</span> <span style="color: #339933;">+</span> swfJSPreLoader.<span style="color: #660066;">loadedBytes</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
		<span style="color: #3366CC;">'loadError'</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;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'load error'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
		<span style="color: #3366CC;">'callback'</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>
			swfJSPreLoader.<span style="color: #660066;">addAsset</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'assets/teaser2.swf'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> <span style="color: #000066;">status</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
															<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'teaser2 loaded status:'</span> <span style="color: #339933;">+</span> <span style="color: #000066;">status</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
														<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
&nbsp;
&lt;script type=&quot;text/javascript&quot; src=&quot;swfobject.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;swfJSPreLoader.js&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>To use the swfJSPreLoader you have to include three js files for swfObjects, JQuery and the swfJSPreLoader.js. You also have to define an JS variable <em>swfJSPreLoaderConfig</em> to configure the preloader. The config-variable could hold the following items:</p>
<ul>
<li><strong><em>assets</em></strong>: assets is an array of the assets which should be loaded. The asset-paths must be relative the html page. If you insert wrong asset pathes you could define an error handler. The assets array is optional. You could also add assets via method call.</li>
<li><strong><em>assetLoaded</em></strong>: assetLoaded defines the callback method for each loaded asset. So this method will be called each time an asset is loaded completly. There are three parameters. <em>asset</em> &#8211; gives the asset-path; <em>bytes</em> &#8211; gives the number of loaded bytes of the current asset; <em>status</em> &#8211; gives the loading status ( 200: Ok, 404: Loading error )</li>
<li><strong><em>loadComplete</em></strong>:The loadComplete callback method will be called after the queue of assets to load is empty. Not all assets need be loaded successfully. If not the error-callback will be fired.</li>
<li><strong><em>loadError</em></strong>:The loadError callback will be triggered if the current asset could not be loaded correctly.</li>
<li><strong><em>callback</em></strong>:With callback you could register a method which is called after the initialization of the swfJSPreLoader. After this method is called you could use the public methods of the pre loader.</li>
</ul>
<p>There are two public methods of the swfJSPreLoader. Both methods are ready after the callback method is called and the initialisation is ready ( the loader flash is instanziated ).</p>
<p><strong><em>swfJSPreLoader.addAsset</em></strong>: The <em>addAsset</em> method allows you to add a single asset to add to the loading queue. It takes to parameters. The first is the path to the asset, the second is the callback handler, which will be fired after this specific asset was loaded. The callback will also be called if the loading fails. The callback gets one argument <em>status</em> with the loading status ( 200: Ok, 404: Loading error ).</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * @public 
 * 
 * adds asset to loading queue
 * @param {String} assetPath - path to assets to load
 * @param {Function} callback - optional callback handler when loading is complete
 */</span>
addAsset<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> assetPath<span style="color: #339933;">,</span> callback <span style="color: #009900;">&#41;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">swfJSPreLoader.<span style="color: #660066;">addAsset</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'assets/teaser2.swf'</span><span style="color: #339933;">,</span>
						<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> <span style="color: #000066;">status</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
							<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'teaser2 loaded status:'</span> <span style="color: #339933;">+</span> <span style="color: #000066;">status</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
						<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong><em>swfJSPreLoader.loadedBytes</em></strong>: The <em>loadedBytes</em> method returns the number of total loaded bytes.</p>
<p>Update 2009-05-17:<a href='http://blog.sebastian-martens.de/wp-content/uploads/2010/05/swfJSPreLoader.zip'>swfJSPreLoader Flash Builder Project Sourcefiles (ZIP, 553kb)</a></p>
<p>Update 2009-05-17:<a href='http://blog.sebastian-martens.de/wp-content/uploads/2010/05/swfJSPreLoader-Test1.zip'>swfJSPreLoader-Test (ZIP, 532kb)</a></p>
<p>I hope this is helpfull for anybody.</p>
<p>cheers,<br />
Sebastian</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sebastian-martens.de/2010/05/preload-assets-with-javascript-load-complete-callback-for-single-assets-include-swfflash/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>JavaScript Timer Class</title>
		<link>http://blog.sebastian-martens.de/2010/02/javascript-timer-class/</link>
		<comments>http://blog.sebastian-martens.de/2010/02/javascript-timer-class/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 21:22:14 +0000</pubDate>
		<dc:creator>Sebastian.Martens</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.sebastian-martens.de/?p=363</guid>
		<description><![CDATA[Here is a little JavaScript Class which allows you to have timed function calls. Of course there could be different instances of these timers. Here is a example how to use it: var timer = new Timer&#40; &#123;'interval':1000&#125; &#41;; timer.start&#40; timedFunction &#41;; &#160; function timedFunction&#40;&#41;&#123; // called every 1000 milliseconds &#125; The function timedFunction will [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin:0px 0px 0px 0px;"></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2010%2F02%2Fjavascript-timer-class%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2010%2F02%2Fjavascript-timer-class%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Here is a little JavaScript Class which allows you to have timed function calls. Of course there could be different instances of these timers. Here is a example how to use it:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> timer <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Timer<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'interval'</span><span style="color: #339933;">:</span><span style="color: #CC0000;">1000</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
timer.<span style="color: #660066;">start</span><span style="color: #009900;">&#40;</span> timedFunction <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> timedFunction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #006600; font-style: italic;">// called every 1000 milliseconds</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The function <em>timedFunction</em> will be called every 1000 milliseconds. The millisecond interval will be configured within the configuration object, which is given as parameter into the the class constructor. There is also an optional second parameter for the <em>start</em> function to set the scope. This allows you to use the timer within other JavaScript objects. To stop the timer use the <em>stop</em> function.<br />
<span id="more-363"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/** ------------------------------------------------------------------------------------------------------------ *
 * @class: Timer
 * @classDescription: implements a timer class to handle timed events
 * @author: Sebastian Martens
 ** ------------------------------------------------------------------------------------------------------------ */</span>
<span style="color: #003366; font-weight: bold;">function</span> Timer<span style="color: #009900;">&#40;</span> obj <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">isRunning</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// is timer currently running</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">interval</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// default interval of event calls</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">funcRef</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// reference to called function</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">scope</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #000066; font-weight: bold;">this</span>._timerId <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// global timer id</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * @constructor
	 * @param {Object} obj - construction parameter
	 */</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">construct</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> obj <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">mixIn</span><span style="color: #009900;">&#40;</span> obj<span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">// find smallest not used timer id</span>
		<span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span> document<span style="color: #009900;">&#91;</span> <span style="color: #3366CC;">'myTimer'</span><span style="color: #339933;">+</span><span style="color: #000066; font-weight: bold;">this</span>._timerId <span style="color: #009900;">&#93;</span><span style="color: #339933;">!=</span><span style="color: #003366; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">this</span>._timerId<span style="color: #339933;">++;</span>
		document<span style="color: #009900;">&#91;</span> <span style="color: #3366CC;">'myTimer'</span><span style="color: #339933;">+</span><span style="color: #000066; font-weight: bold;">this</span>._timerId <span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * mix a given object into this object
	 * @param {Object} obj - given object with parameters
	 */</span>	
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">mixIn</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> obj<span style="color: #339933;">,</span> scope <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>scope<span style="color: #009900;">&#41;</span> scope <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066; font-weight: bold;">item</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span> <span style="color: #000066; font-weight: bold;">in</span> obj<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			scope<span style="color: #009900;">&#91;</span> <span style="color: #000066; font-weight: bold;">item</span> <span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> obj<span style="color: #009900;">&#91;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * starts timer
	 * @param {Int} interval - time in milliseconds for time interval
	 * @param {Node} scope - the execution scope of the reference function
	 * @param {Function} funcRef - function reference of function to be called on time event
	 */</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">start</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span> funcRef<span style="color: #339933;">,</span> scope<span style="color: #339933;">,</span> interval <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>interval<span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">interval</span> <span style="color: #339933;">=</span> interval<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">scope</span> <span style="color: #339933;">=</span> scope<span style="color: #339933;">;</span>		
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">funcRef</span> <span style="color: #339933;">=</span> funcRef<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">isRunning</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">startTimer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * starts a new time event call with given time interval
	 */</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">startTimer</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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">isRunning</span> <span style="color: #009900;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span> 
		window.<span style="color: #660066;">setTimeout</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;document['myTimer&quot;</span><span style="color: #339933;">+</span><span style="color: #000066; font-weight: bold;">this</span>._timerId<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;'].timedHandler()&quot;</span><span style="color: #339933;">,</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">interval</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * stopps the timer
	 */</span>	
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">stopp</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;">this</span>.<span style="color: #660066;">isRunning</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * timed event handler. will be called on each time event
	 */</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">timedHandler</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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">isRunning</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: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">funcRef</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">funcRef</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">scope</span><span style="color: #009900;">&#41;</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;">this</span>.<span style="color: #660066;">stopp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #006600; font-style: italic;">// do next timer call</span>
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">startTimer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// constructor call</span>
	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">construct</span><span style="color: #009900;">&#40;</span> obj <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Download JavaScript <a href='http://blog.sebastian-martens.de/wp-content/uploads/2010/02/Timer.js'>Timer.js</a></p>
<p>cheers,<br />
Sebastian</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sebastian-martens.de/2010/02/javascript-timer-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Set innerHeight also for IE</title>
		<link>http://blog.sebastian-martens.de/2009/08/set-innerheight-also-for-ie/</link>
		<comments>http://blog.sebastian-martens.de/2009/08/set-innerheight-also-for-ie/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 17:49:10 +0000</pubDate>
		<dc:creator>Sebastian.Martens</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[innerHeight]]></category>
		<category><![CDATA[innerWidth]]></category>
		<category><![CDATA[Mozilla]]></category>

		<guid isPermaLink="false">http://blog.sebastian-martens.de/?p=233</guid>
		<description><![CDATA[I&#8217;m really not a fan of popup windows within a website. But sometimes it really makes sense. For example for a little campaign which is more or less a microsite. But you want not to lose the website context. In this case i would &#8220;allow&#8221; to open the campaign in a popup window. The popup [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin:0px 0px 0px 0px;"></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2009%2F08%2Fset-innerheight-also-for-ie%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2009%2F08%2Fset-innerheight-also-for-ie%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I&#8217;m really not a fan of popup windows within a website. But sometimes it really makes sense. For example for a little campaign which is more or less a microsite. But you want not to lose the website context. In this case i would &#8220;allow&#8221; to open the campaign in a popup window. </p>
<p>The popup window should of course be as small as possible and should resize to the campaigns size. But because you never know which kind of Browsertoolbars the user have installed ( and you don&#8217;t want to disallow all tool- and browserbars ) you can&#8217;t really set the window size, because the IE does not support the innerHeight or innerWidth attribute of the window-element.<br />
<span id="more-233"></span><br />
Mozilla based browsers do support it and resize the complete window that way, that all content is fully shown. The following script checks the browsers scroll attibute to resize the IE browser window step by step. Not very nice, but it works. Please let me know if there is a better way to to this. This is the first i found.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> setInnerSize<span style="color: #009900;">&#40;</span>width<span style="color: #339933;">,</span>height<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">innerWidth</span> <span style="color: #339933;">&amp;&amp;</span> window.<span style="color: #660066;">innerWidth</span><span style="color: #339933;">!=</span><span style="color: #3366CC;">&quot;undefined&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     	window.<span style="color: #660066;">innerWidth</span> <span style="color: #339933;">=</span> width<span style="color: #339933;">;</span>
     	window.<span style="color: #660066;">innerHeight</span> <span style="color: #339933;">=</span> height<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
     	run <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
     	runHeight <span style="color: #339933;">=</span> height<span style="color: #339933;">;</span>
     	runWidth <span style="color: #339933;">=</span> width<span style="color: #339933;">;</span>
&nbsp;
     	window.<span style="color: #660066;">resizeTo</span><span style="color: #009900;">&#40;</span> runWidth<span style="color: #339933;">,</span> runHeight <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     	<span style="color: #000066; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span> run  <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      		window.<span style="color: #660066;">scrollTo</span><span style="color: #009900;">&#40;</span> <span style="color: #CC0000;">1000</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1000</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      		scrollV <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">documentElement</span>.<span style="color: #660066;">scrollTop</span><span style="color: #339933;">?</span>document.<span style="color: #660066;">documentElement</span>.<span style="color: #660066;">scrollTop</span><span style="color: #339933;">:</span>document.<span style="color: #660066;">body</span>.<span style="color: #660066;">scrollTop</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      		scrollH <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">documentElement</span>.<span style="color: #660066;">scrollLeft</span><span style="color: #339933;">?</span>document.<span style="color: #660066;">documentElement</span>.<span style="color: #660066;">scrollLeft</span><span style="color: #339933;">:</span>document.<span style="color: #660066;">body</span>.<span style="color: #660066;">scrollLeft</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> scrollH <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#41;</span> runWidth <span style="color: #339933;">=</span> runWidth<span style="color: #339933;">+</span><span style="color: #CC0000;">10</span><span style="color: #339933;">;</span>
      		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> scrollV <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#41;</span> runHeight <span style="color: #339933;">=</span> runHeight<span style="color: #339933;">+</span><span style="color: #CC0000;">10</span><span style="color: #339933;">;</span>
&nbsp;
      		window.<span style="color: #660066;">resizeTo</span><span style="color: #009900;">&#40;</span> runWidth<span style="color: #339933;">,</span> runHeight <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      		<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#40;</span>scrollV<span style="color: #339933;">+</span>scrollH<span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;</span><span style="color: #CC0000;">10</span> <span style="color: #009900;">&#41;</span> run <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
     	<span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>cheers,<br />
Sebastian</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sebastian-martens.de/2009/08/set-innerheight-also-for-ie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>swfInputs: Solving Mozilla + Transparent Mode + Win + Special Chars within inputs</title>
		<link>http://blog.sebastian-martens.de/2009/05/swfinputs-solving-mozilla-transparent-mode-win-special-chars-within-inputs/</link>
		<comments>http://blog.sebastian-martens.de/2009/05/swfinputs-solving-mozilla-transparent-mode-win-special-chars-within-inputs/#comments</comments>
		<pubDate>Fri, 29 May 2009 19:30:43 +0000</pubDate>
		<dc:creator>Sebastian.Martens</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[inputs]]></category>
		<category><![CDATA[Mozilla]]></category>
		<category><![CDATA[opaque]]></category>
		<category><![CDATA[Player]]></category>
		<category><![CDATA[special characters]]></category>
		<category><![CDATA[swfInputs]]></category>
		<category><![CDATA[transparent mode]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[wmode]]></category>

		<guid isPermaLink="false">http://blog.sebastian-martens.de/?p=159</guid>
		<description><![CDATA[As you probably know the Flash Player uses three different types of modes an Flash movie is embedded in the browser window. Its is set via the wmode parameter in the embed or param tag. &#60;param name=&#34;wmode&#34; value=&#34;transparent&#34; /&#62; &#60;embed wmode=&#34;transparent&#34; ... With the transparent mode you can influence the relation between the Flash movie [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin:0px 0px 0px 0px;"></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2009%2F05%2Fswfinputs-solving-mozilla-transparent-mode-win-special-chars-within-inputs%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2009%2F05%2Fswfinputs-solving-mozilla-transparent-mode-win-special-chars-within-inputs%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>As you probably know the Flash Player uses three different types of modes an Flash movie is embedded in the browser window. Its is set via the <em>wmode</em> parameter in the embed or param tag.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">  &lt;param name=&quot;wmode&quot; value=&quot;transparent&quot; /&gt;
  &lt;embed wmode=&quot;transparent&quot; ...</pre></div></div>

<p>With the transparent mode you can influence the relation between the Flash movie an the surrounding HTML. If the set the wmode to window the Flash movie will always lay on top of the rest of the page. This is absolutly helpfull if your application is &#8220;standalone&#8221;, means the only center of user interaction or if you have an full window application ( at least with full screen ).<br />
But often you have other HTML elements around the Flash movie which are at the same level of user interaction and might be as important as the Flash movie ( Best example might by fly-out menus which has to overlay all other content. Or maybe confirm messages which are not realized by the JavaScript confirm-dialog ). If you use <em>wmode</em> window html elements will always behind the Flash movie (setting the html z-index has no effect ), so there is no real interaction between HTML/JavaScript an the Flash movie. For this you need <em>wmode</em> equals <em>transparent</em>.<br />
<span id="more-159"></span><br />
wmode transparent allows an equal mixture between Flash and HTML/ JavaScript. Just as the parameters sounds, the Flash movie will also have an transparent background and let the behind HTML shine through. Attention: The transaparent background is expensive in performance. Use it carefully.<br />
The third mode after <em>window</em> and <em>transparent</em> is <em>opaque</em>. The opaque also allows the mix of Flash and HTML/ JavaScript, but has now transparent background.</p>
<p>Since the introduction of these two modes (<em>transparent, opaque</em>) there is a bug with Mozilla based Browsers and textfields on Window plattforms. If you try to enter special character &#8211; famoused example is the @ &#8211; in text fields it wont work. This is very uncomfortable if you want to have a user login where you use e-mail adresses as username ( @see <a href="http://bugs.adobe.com/jira/browse/FP-479">Adobe Bug Base</a> ).</p>
<h3>swfInput</h3>
<p>My solution to solve this issue is called swfInputs. It uses the ExternalInterface class of the Flash player. swfInputs is a an AS3 which extends the Flex TextInput class. It communicates with an JavaScript class. This will create normal HTML Inputfields and places it exactly above the original Flash Inputfield.<br />
On entering text in the overlay-HTML-Inputfield the text will be transfered via ExternalInterface into the Flash movie and the corresponding Flash Inputfield. For the Flash application this mechanism is transparent because the access to the field and change events on the input field will still work.</p>
<p>The JavaScript class will only generate the overlay input field if its necessary, means on the Mozilla-Windows-Combination. Other browsers will use the normal Flash movie inputs.</p>
<p>The styles (height, width, border, colors ) which you set on the Flash Input will be transfered to the HTML-Input and set via CSS styles. For further styling like background images you could of course also use standard CSS.</p>
<p>swfInputs also support multiple Flash movies within on HTML page and have an &#8220;point-to-point&#8221; connection between the overlaying HTML-Input and the Flash-Input. So there is no general keylogger on the complete HTML page, which might cause problems with your JavaScript functions. This also means that you could have different Flash movies on one page ( which might also communicate to each other via LocalConnection ) where each movie could have its own TextInputs. </p>
<h3>What to do in your code?</h3>
<p>swfInputs consists of two parts:</p>
<ul>
<li>The SWFTextInput AS3 Class (which create the connection to the JavaScript class)</li>
<li>and the swfInputs JavaScript Class (which handles the creation and HTML communication)</li>
</ul>
<p>To activate the JavaScript part you just need to insert two script-tags into the HTML code and call the constructor method. At the moment swfInputs uses the dojoToolkit JavaScript library for position calculation and basic connection handling. I looking forward to remove this need of dojo to reduce the filesize.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script src=&quot;../javascript/dojo.js&quot; language=&quot;javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;../javascript/swfInputs.js&quot; language=&quot;javascript&quot;&gt;&lt;/script&gt;
&lt;script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;&gt;
			swfInputs.init('swfInputTestcase');
&lt;/script&gt;</pre></div></div>

<p>The String-value int the constructor call is the channel-name. This is optional if you just use on single instance within the HTML-page.</p>
<p>Within you Flash/ Flex application you have to use the SWFTextInput class for textfields instead of TextInput. The SWFTextInput class uses the <a href="/2009/03/how-to-handle-massive-externalinterface-calls-jscallstack/">JSCallStack</a> to optimize the JavaScript communiaction ( which could be a lot on fast typing, so its recommanded to use it ).</p>
<p>A basic Flash/ Flex app could look like this. You see there is nothing very special instead of the <strong><em>swfInputs:SWFTextInput</em></strong> class.</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> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;400&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;600&quot;</span> backgroundAlpha=<span style="color: #ff0000;">&quot;0.5&quot;</span> <span style="color: #0066CC;">backgroundColor</span>=<span style="color: #ff0000;">&quot;#674523&quot;</span>
	initialize=<span style="color: #ff0000;">&quot;init()&quot;</span> xmlns:swfInputs=<span style="color: #ff0000;">&quot;com.nonstatics.swfInputs.*&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
	<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;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">Alert</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// </span>
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> clickHandler<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span><span style="color: #66cc66;">&#123;</span>
				Alert.<span style="color: #0066CC;">show</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;swfInput01: &quot;</span>+swfInput01.<span style="color: #0066CC;">text</span>+<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>+
						   <span style="color: #ff0000;">&quot;swfInput02: &quot;</span>+swfInput02.<span style="color: #0066CC;">text</span>+<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>+
						   <span style="color: #ff0000;">&quot;swfInput03: &quot;</span>+swfInput03.<span style="color: #0066CC;">text</span><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>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:VBox x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
		<span style="color: #66cc66;">&lt;</span>mx:TextInput <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;160&quot;</span> <span style="color: #0066CC;">borderColor</span>=<span style="color: #ff0000;">&quot;#674523&quot;</span> <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;{ swfInput01.text + swfInput02.text }&quot;</span> <span style="color: #66cc66;">/&gt;</span>
&nbsp;
		<span style="color: #66cc66;">&lt;</span>swfInputs:SWFTextInput id=<span style="color: #ff0000;">&quot;swfInput01&quot;</span> <span style="color: #0066CC;">borderColor</span>=<span style="color: #ff0000;">&quot;#ff0000&quot;</span> fontFamily=<span style="color: #ff0000;">&quot;Verdana&quot;</span> <span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>swfInputs:SWFTextInput id=<span style="color: #ff0000;">&quot;swfInput02&quot;</span> <span style="color: #0066CC;">borderColor</span>=<span style="color: #ff0000;">&quot;#00ffff&quot;</span> fontFamily=<span style="color: #ff0000;">&quot;Arial&quot;</span> <span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;</span>swfInputs:SWFTextInput id=<span style="color: #ff0000;">&quot;swfInput03&quot;</span> <span style="color: #0066CC;">borderColor</span>=<span style="color: #ff0000;">&quot;#0000ff&quot;</span> fontFamily=<span style="color: #ff0000;">&quot;Times&quot;</span> <span style="color: #66cc66;">/&gt;</span>
&nbsp;
		<span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Senden&quot;</span> click=<span style="color: #ff0000;">&quot;clickHandler()&quot;</span> <span style="color: #66cc66;">/&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;/</span>mx:VBox<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:Application<span style="color: #66cc66;">&gt;</span></pre></div></div>

<h3>Download Files (swfInputs 1.0)</h3>
<p><a href='http://blog.sebastian-martens.de/wp-content/uploads/2009/05/swftextinput.as'>SWFTextInput.as</a><br />
<a href='http://blog.sebastian-martens.de/wp-content/uploads/2009/05/swfinputs.js'>swfInputs.js</a><br />
<a href='http://blog.sebastian-martens.de/wp-content/uploads/2009/05/swfinputtestproject.zip'>SWFInputs Eclipse Testproject (ZIP)</a></p>
<p>Please feal free to leave some comments and let me know if its helpful or what should be done for future releases.</p>
<p>cheers,<br />
Sebastian</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sebastian-martens.de/2009/05/swfinputs-solving-mozilla-transparent-mode-win-special-chars-within-inputs/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to handle massive ExternalInterface calls (JsCallStack)</title>
		<link>http://blog.sebastian-martens.de/2009/03/how-to-handle-massive-externalinterface-calls-jscallstack/</link>
		<comments>http://blog.sebastian-martens.de/2009/03/how-to-handle-massive-externalinterface-calls-jscallstack/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 20:45:22 +0000</pubDate>
		<dc:creator>Sebastian.Martens</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[JsCallStack]]></category>

		<guid isPermaLink="false">http://blog.sebastian-martens.de/?p=79</guid>
		<description><![CDATA[We use the ExternalInterface of the Flash Player to let JavaScript resize the HTML-Container of the Flex application. Our App loads dynamic content via XML and builds a list of entries. But we would like the user to use the standard browser scrollbar and not a scrollbar within the flex application. So we have to [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin:0px 0px 0px 0px;"></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2009%2F03%2Fhow-to-handle-massive-externalinterface-calls-jscallstack%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2009%2F03%2Fhow-to-handle-massive-externalinterface-calls-jscallstack%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>We use the ExternalInterface of the Flash Player to let JavaScript resize the HTML-Container of the Flex application. Our App loads dynamic content via XML and builds a list of entries. But we would like the user to use the standard browser scrollbar and not a scrollbar within the flex application. So we have to resize the HTM-Container of the Flex application, depending on its actual loaded content. Each time a new entry is added to the list, we call an JavaScript method from the Flex app via ExternalInterface to resize the HTML. This is done by using the resize-Event of Flex.</p>
<p>But sometimes the resize event is called up to 100 times within a second. In this cases some browsers ( sorry, but the IE seems to be ok ) didn&#8217;t get all JavaScript calls we made via ExternalInterface and some of our calls weren&#8217;t handled ( the container was not resized and our Flex list was cutted off ).<br />
<span id="more-79"></span><br />
In our first version of the app we made an default call, which calls the last JavaScript-resize after a specific period again. Easy but not very elegant.</p>
<p>What if done now is to implement an JavaScript-Call-Stack. You put in your ExternalInterface calls and the stack will process each after an other after a given pause between the calls. If you often have the same call, maybe only with updated parameters, just like our resize-Event which has different height and width values, the stack is able to clean older calls ( which aren&#8217;t processed up to than ) and only calles the latest (in our example the JavaScript method runs ~3 times and not 100 times). The disadvantage of ExternalInterface calls via such a stack is that this is no an asynchronous process and you have to define a callback-handler if you expect an return value of the JavaScript method.</p>
<p>How it&#8217;s done:<br />
Create an instance of the JsCallStack class. You should  set the timer for the JavaScript calls in ms (will be 500ms by default). Maybe this value could differ from browser to browser (and maybe client hardware), i didn&#8217;t test best values for that.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// init JS function call stack</span>
<span style="color: #0066CC;">this</span>._jsCalls = <span style="color: #000000; font-weight: bold;">new</span> JsCallStack<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">this</span>._jsCalls.<span style="color: #006600;">timerInterval</span> = <span style="color: #cc66cc;">30</span>;</pre></div></div>

<p>It is also possible to give the stack a different mode. By default the stack will be handled as FIFO-Stack (First-In-First-Out). This means that every new call will set at the last position of the queue. It&#8217;s also possible to use it as LIFO-Stack (Last-In-First-Out), means that the last call will be handled next.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// init JS function call stack as LIFO-Stack</span>
<span style="color: #0066CC;">this</span>._jsCalls = <span style="color: #000000; font-weight: bold;">new</span> JsCallStack<span style="color: #66cc66;">&#40;</span> JsCallStack.<span style="color: #006600;">STACK_MODE_LIFO</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Second easy step: Make your JavaScript call:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">this</span>._jsCalls.<span style="color: #006600;">addJSCall</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;swfInputs.swfInputInit&quot;</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>, jsInitCompleteHandler<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This will add a JavaScript method-call to your stack. First param is the method-name (here: method &#8220;swfInputInit&#8221; of the swfInputs-Object). The second parameter is an object which will be passed to the JavaScript method. This parameter is optional. The third parameter is the result-handler reference. If you expect any results from the JS-method, they will be handed over to this AS-method.<br />
The return value of the addJSCall-method is an integer value of the stack position your call have ( 1 = will be processed next ). If the result is -1 the ExternalInterface isn&#8217;t available.</p>
<p>There are also two more parameters: The fourth is the <em>skipOldCalls</em>-parameter. If this is set to true (default is false) older calls of the same JS-method name will be ignored and removed from the stack. The fifth-parameter is <em>convertToJSON</em>. This will convert your given object, which should pass to the JS-method, to JSON.</p>
<p>Happy AS + JS coding.</p>
<p>Download (2009/12/19) <a href="http://blog.sebastian-martens.de/wp-content/uploads/2009/12/jscallstack.as">JsCallStack.as (Vector)</a><br />
Download (2009/03/29) <a href="http://blog.sebastian-martens.de/wp-content/uploads/2009/03/jscallstack.as">JsCallStack.as (ArrayCollection)</a></p>
<p>cheers,<br />
Sebastian</p>
<p>Doing nice code-comments allows you faster blog-posts:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/**
 * constructor method
 * @param stackMode:int - stack mode of handling stack entries
 */</span> 
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> JsCallStack<span style="color: #66cc66;">&#40;</span> stackMode:<span style="color: #0066CC;">int</span>=JsCallStack.<span style="color: #006600;">STACK_MODE_FIFO</span> <span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * adds an javascript function call to call stack
 * @param funcName:String - function name of js function to call
 * @param paramter:Object - object of paramters to path to the javascript function
 * 							Object will be converted to JSON and hand over an JSON-Object
 * @param resultHandler:Function - method to handler javascript results
 * @param skipOldCalls:Boolean - if true older calls in stack of the same functionname won't be 
 * 								 called any more, only latest call
 * @param convert2JSON:Boolean - if true the parameter object will be converted to JSON for the javascript call
 * @return Int value of stack position, returns -1 if External Interface is not available
 */</span> 
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> addJSCall<span style="color: #66cc66;">&#40;</span> funcName:<span style="color: #0066CC;">String</span>, parameter:<span style="color: #0066CC;">Object</span>=<span style="color: #000000; font-weight: bold;">null</span>, resultHandler:<span style="color: #000000; font-weight: bold;">Function</span>=<span style="color: #000000; font-weight: bold;">null</span>, skipOldCalls:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span>, convert2JSON:<span style="color: #0066CC;">Boolean</span>=<span style="color: #000000; font-weight: bold;">false</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * removes an javascript call from stack
 * @param id:int - identifier position of call which was returned from addJSCall Method
 * @return Boolean - function found an removed, false if already called
 */</span> 
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> removeJSCall<span style="color: #66cc66;">&#40;</span> id:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * returns if the timer is running 
 * @return Boolean - is the execution timer running 
 */</span> 
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> isExecutionRunning<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Boolean</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * returns the n number of registered functions at this momment 
 * @return INT - numer of registered functions, which are not executed yet
 */</span> 
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getRegisteredFunctionsCount<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * setter method for timer interval value
 * @param value:Int - timer interval in milliseconds
 */</span> 
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> timerInterval<span style="color: #66cc66;">&#40;</span> value:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * getter method for timer interval
 * @return Int - set timer interval
 */</span> 
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> timeInterval<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">int</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * pauses the execution of javascript calls
 */</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> pauseExecution<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/**
 * restarts the execution of javascript calls 
 */</span> 
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> startExecution<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.sebastian-martens.de/2009/03/how-to-handle-massive-externalinterface-calls-jscallstack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Preset a Selection within Input or TextArea</title>
		<link>http://blog.sebastian-martens.de/2009/03/preset-a-selection-within-input-or-textarea/</link>
		<comments>http://blog.sebastian-martens.de/2009/03/preset-a-selection-within-input-or-textarea/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 20:39:04 +0000</pubDate>
		<dc:creator>Sebastian.Martens</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.sebastian-martens.de/?p=74</guid>
		<description><![CDATA[I wrote this very little pice of code several times now, because i lost it each time again. Hopefully i find it next time here&#8230; So what to do if you want to preset an selection within an input or textarea, just to support your users a little ( which they will never recognize &#8211; [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin:0px 0px 0px 0px;"></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2009%2F03%2Fpreset-a-selection-within-input-or-textarea%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2009%2F03%2Fpreset-a-selection-within-input-or-textarea%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I wrote this very little pice of code several times now, because i lost it each time again. Hopefully i find it next time here&#8230;<br />
So what to do if you want to preset an selection within an input or textarea, just to support your users a little ( which they will never recognize &#8211; of course, they are users and do expect these things ). We&#8217;re lucky, Mozilla and IE also have little methods for that:</p>
<p><span id="more-74"></span></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * @description setSelection - sets an selection for end input from start to end- index
 * $Id: range_selection.js 2 2009-03-17 19:25:27Z dinnerout $
 * @param node DOM-Node/String - DOM-Node or Id of Node to set selection in
 * @param startIndex Int - Startindex od selection
 * @param length Int - length of selection
 */</span>
<span style="color: #003366; font-weight: bold;">function</span> setSelection<span style="color: #009900;">&#40;</span> node<span style="color: #339933;">,</span> startIndex<span style="color: #339933;">,</span> length <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> dNode <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> node <span style="color: #339933;">==</span> <span style="color: #3366CC;">'string'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">?</span>$<span style="color: #009900;">&#40;</span>node<span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>node<span style="color: #339933;">;</span>
	dNode.<span style="color: #000066;">focus</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #006600; font-style: italic;">// IE</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">selection</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> range <span style="color: #339933;">=</span> document.<span style="color: #660066;">selection</span>.<span style="color: #660066;">createRange</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		range.<span style="color: #660066;">move</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'character'</span><span style="color: #339933;">,-</span><span style="color: #CC0000;">10000000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// reset cursor position</span>
		range.<span style="color: #660066;">moveStart</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'character'</span><span style="color: #339933;">,</span>startIndex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		range.<span style="color: #660066;">moveEnd</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'character'</span><span style="color: #339933;">,</span>startIndex<span style="color: #339933;">+</span>length<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		range.<span style="color: #660066;">select</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #006600; font-style: italic;">// Mozilla</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>dNode.<span style="color: #660066;">selectionStart</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		dNode.<span style="color: #660066;">selectionStart</span> <span style="color: #339933;">=</span> startIndex<span style="color: #339933;">;</span>
		dNode.<span style="color: #660066;">selectionEnd</span> <span style="color: #339933;">=</span> startIndex <span style="color: #339933;">+</span> length<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.sebastian-martens.de/2009/03/preset-a-selection-within-input-or-textarea/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rendererror on IE6 + AJAX with multiple selects</title>
		<link>http://blog.sebastian-martens.de/2009/03/rendererror-on-ie6-ajax/</link>
		<comments>http://blog.sebastian-martens.de/2009/03/rendererror-on-ie6-ajax/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 15:25:00 +0000</pubDate>
		<dc:creator>Sebastian.Martens</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[DHTML]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[IE6]]></category>

		<guid isPermaLink="false">http://blog.sebastian-martens.de/?p=66</guid>
		<description><![CDATA[Who ever has to support the old IE6 and is not able to ignore or to bann users with this browser (or is part of an active resistance de:&#8221;Webmaster-Aufstand-gegen-alte-Internet-Explorer&#8221; ), has to hack around things quiet often. One big problem is that the IE6 has some render problems when you manipulate content in the DOM [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin:0px 0px 0px 0px;"></div><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2009%2F03%2Frendererror-on-ie6-ajax%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.sebastian-martens.de%2F2009%2F03%2Frendererror-on-ie6-ajax%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Who ever has to support the old IE6 and is not able to ignore or to bann users with this browser (or is part of an active resistance de:&#8221;<a href="http://www.heise.de/netze/Webmaster-Aufstand-gegen-alte-Internet-Explorer--/news/meldung/133204">Webmaster-Aufstand-gegen-alte-Internet-Explorer</a>&#8221; ), has to hack around things quiet often.<br />
One big problem is that the IE6 has some render problems when you manipulate content in the DOM tree. If this happens to earlie you maybe get boxs which are cut off or your footer may have an wrong position because the IE didn&#8217;t update the box size in which you updated your content.<span id="more-66"></span></p>
<p>In my case i had an select field with the attribute &#8220;multiple&#8221;. This should haven an height of 300px set via CSS. The select-node was created via JavaScript. The first select got content via AJAX. The second should be empty as long as you don&#8217;t double click the first and copy content from left to right.  The complete construction was created and attachted on page load. The first select was displayed correctly. But the second one looks like an normal select with one line height, not 300px as expected.</p>
<p>To fix this problem you have to set an little timer which triggers an function which again manipulates the element to force the IE to rerender this section. So if your footer position is wrong after an update of any content, just update an little style attribute and reset it:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;getElementById('footerId').style.height = (footerHeight+1)+'px'; getElementById('footerId').style.height = (footerHeight-1)+'px';&quot;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This <strong>doesn&#8217;t</strong> work with my empty multiple select when i used the select field itself. I had to create an new DIV-Container right under the select-field which i resized a bit and removed it afterwards. This then also updated the select-field.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">setTimeout<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ieFixSelect('mySelect')&quot;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> ieFixSelect<span style="color: #009900;">&#40;</span> selectId <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> node <span style="color: #339933;">=</span> getElementById<span style="color: #009900;">&#40;</span> selectId <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003366; font-weight: bold;">var</span> fixNode <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'DIV'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    node.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span> fixNode <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    fixNode.<span style="color: #660066;">style</span>.<span style="color: #660066;">height</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'1px'</span><span style="color: #339933;">;</span>
    fixNode.<span style="color: #660066;">parentNode</span>.<span style="color: #660066;">removeChild</span><span style="color: #009900;">&#40;</span> fixNode <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.sebastian-martens.de/2009/03/rendererror-on-ie6-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.309 seconds -->
