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

<channel>
	<title>Jozef Chúťka&#039;s blog &#187; allowscriptaccess</title>
	<atom:link href="http://blog.yoz.sk/tag/allowscriptaccess/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.yoz.sk</link>
	<description>My life, my work</description>
	<lastBuildDate>Tue, 31 Jan 2012 12:40:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Full JavaScript Access From ActionScript (update)</title>
		<link>http://blog.yoz.sk/2010/02/full-javascript-access-from-actionscript/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=full-javascript-access-from-actionscript</link>
		<comments>http://blog.yoz.sk/2010/02/full-javascript-access-from-actionscript/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 10:10:55 +0000</pubDate>
		<dc:creator>Jozef Chúťka</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash / Flex]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[allowscriptaccess]]></category>
		<category><![CDATA[eval]]></category>
		<category><![CDATA[ExternalInterface]]></category>

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

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

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

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

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

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

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

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

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

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

		<guid isPermaLink="false">http://blog.yoz.sk/?p=1004</guid>
		<description><![CDATA[Many of you have come accross the horrendous bug that happens with text input in flash when the swf is embedded with wmode=transparent/opaque. It has been much discussed (Firefox Bugzilla entry for this bug, Adobe Forum discussion, etc.), but it seems that in all the years that this bug has existed nothing much has been [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.yoz.sk/wp-content/uploads/fakeTextInput-200x100.png" alt="" title="fakeTextInput" width="200" height="100" class="alignleft size-medium wp-image-1015" /></p>
<p>Many of you have come accross the horrendous bug that happens with text input in flash when the swf is embedded with wmode=transparent/opaque. It has been much discussed (<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=347185">Firefox Bugzilla entry for this bug</a>, <a href="http://bugs.adobe.com/jira/browse/FP-479">Adobe Forum discussion</a>, etc.), but it seems that in all the years that this bug has existed nothing much has been done. A <a href="http://www.google.cz/search?hl=cs&#038;rlz=1C1GGLS_csCZ334CZ334&#038;q=wmode+transparent+text+input+workaround&#038;btnG=Hledat&#038;lr=&#038;aq=f&#038;oq=">lot of workarounds have been published</a>, many of them based on custom key mapping etc&#8230; My workaround uses html element &lt;input type=&#8221;text&#8221;&gt; that is placed right over flex &lt;mx:TextInput&gt;. Html element is styled transparent (no design) so user will not notice.</p>
<p><span id="more-1004"></span></p>
<p>Following application uses wmode &#8220;opaque&#8221;, try inserting characters (čšň) into first text input (mx:TextInput) and than into second (uses html &lt;input type=&#8221;text&#8221;&gt; over flash)</p>
<p><iframe width="100%" height="300" src="http://blog.yoz.sk/examples/fakeTextInput/"></iframe></p>
<p>Main application</p>
<pre class="brush: xml; title: ; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
    applicationComplete=&quot;init()&quot; viewSourceURL=&quot;srcview/index.html&quot;&gt;
&lt;mx:Script&gt;
&lt;![CDATA[
    import mx.managers.PopUpManager;
    private function init():void
    {
        var window:FakeInputsWindow = new FakeInputsWindow();
        PopUpManager.addPopUp(window, this);
        PopUpManager.centerPopUp(window);
    }
]]&gt;
&lt;/mx:Script&gt;
&lt;/mx:Application&gt;</pre>
<p>FakeInputsWindow</p>
<pre class="brush: xml; title: ; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:TitleWindow
    xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
    xmlns:html=&quot;sk.yoz.html.*&quot;
    layout=&quot;vertical&quot; width=&quot;400&quot; height=&quot;250&quot;
    creationComplete=&quot;init()&quot;
    move=&quot;moveHandler()&quot;&gt;
&lt;mx:Script&gt;
&lt;![CDATA[
    [Bindable]
    private var text2:String = &quot;&quot;;

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

    private function moveHandler():void
    {
        fakeTextInput.positionChanged = true;
        fakeTextInput.invalidateProperties();
    }

    private function fakeTextChange(value:String):void
    {
        text2 = value;
    }
]]&gt;
&lt;/mx:Script&gt;
&lt;mx:Text text='&amp;lt;mx:TextInput ....'/&gt;
&lt;mx:TextInput id=&quot;text1&quot; width=&quot;300&quot; height=&quot;20&quot;/&gt;
&lt;mx:Label text=&quot;{text1.text}&quot; /&gt;
&lt;mx:Spacer height=&quot;10&quot; /&gt;
&lt;mx:Text text='&amp;lt;input type=&quot;text&quot; ....'/&gt;
&lt;mx:Canvas width=&quot;300&quot; height=&quot;20&quot;&gt;
    &lt;mx:TextInput width=&quot;300&quot; height=&quot;20&quot;/&gt;
    &lt;html:IFrame width=&quot;100%&quot; height=&quot;100%&quot; id=&quot;fakeTextInput&quot;
        autoResize=&quot;true&quot;/&gt;
&lt;/mx:Canvas&gt;
&lt;mx:Label text=&quot;{text2}&quot; /&gt;
&lt;/mx:TitleWindow&gt;</pre>
<p>lines:</p>
<ul>
<li>15: javascript-to-flash callback definition fakeTextInputChange (from javascript) sends value into actionscript fakeTextChange()</li>
<li>18: fakeTextInput is IFrame class, that controls position and size of html input, lets correct position on TitleWindow move&#8230;</li>
<li>35-39: I placed IFrame over TextInput. IFrame is in fact transparent html input, so what user see is just flex TextInput graphics</li>
</ul>
<p>Html template file</p>
<pre class="brush: xml; title: ; notranslate">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xml:lang=&quot;en&quot; lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;
&lt;head&gt;
    &lt;title&gt;FakeTextInput&lt;/title&gt;
    ...
    &lt;script type=&quot;text/javascript&quot; src=&quot;js/swfobject.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;js/flexiframe.js&quot;&gt;&lt;/script&gt;
    &lt;script type=&quot;text/javascript&quot;&gt;
    &lt;!--
        var flashvars = {}

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

        function fakeTextInputChange()
        {
            var input = document.getElementById('fakeTextInput');
            var flash = document.getElementById('flash');
            flash.fakeTextInputChange(input.value);
        }
    //--&gt;
    &lt;/script&gt; 

    &lt;style type='text/css'&gt;
    &lt;!--
        body {margin:0px;overflow:hidden;}
        html, body, object, embed {width:100%;height:100%;outline:none;}
        #fakeTextInput {
            position:absolute;
            border:none;
            outline:none;
            padding:0;
            margin:0;
            background:transparent url(&quot;images/spacer.gif&quot;);
            vertical-align:middle;
        }
    --&gt;
    &lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;div id=&quot;alternative&quot;&gt;
        &lt;a href=&quot;http://www.adobe.com/go/getflashplayer&quot;&gt;
            &lt;img src=&quot;http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif&quot; alt=&quot;Get Adobe Flash player&quot; /&gt;
        &lt;/a&gt;
    &lt;/div&gt;
    &lt;input type=&quot;text&quot; id=&quot;fakeTextInput&quot; onkeyup=&quot;fakeTextInputChange()&quot;/&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Notice lines:</p>
<ul>
<li>07: import <a href="http://blog.yoz.sk/2009/10/flex-iframe-web-browser-in-flash/">flexiframe.js</a> used for positioning html input on correct place</li>
<li>13: allowscriptaccess must be enabled</li>
<li>14: wmode opaque/transparent is what the source of all evil</li>
<li>22: javascript-to-flash communication</li>
<li>35-42: remove all html input text design and makes it transparent</li>
<li>53: input text definition, you may want to define your own handlers (submit, paste, focus&#8230;)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.yoz.sk/2010/02/textinput-wmode-opaque-transparent-workaround/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

