<?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; ExternalInterface</title>
	<atom:link href="http://blog.sebastian-martens.de/tag/externalinterface/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>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>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>
	</channel>
</rss>

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