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

<channel>
	<title>Flex Examples &#187; JavaScript</title>
	<atom:link href="http://blog.flexexamples.com/category/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Returning values from JavaScript in your Flex applications using the ExternalInterface API</title>
		<link>http://blog.flexexamples.com/2008/03/11/returning-values-from-javascript-in-your-flex-applications-using-the-externalinterface-api/</link>
		<comments>http://blog.flexexamples.com/2008/03/11/returning-values-from-javascript-in-your-flex-applications-using-the-externalinterface-api/#comments</comments>
		<pubDate>Wed, 12 Mar 2008 01:21:12 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[call()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2008/03/11/returning-values-from-javascript-in-your-flex-applications-using-the-externalinterface-api/</guid>
		<description><![CDATA[<p>In a previous example, <a href="http://blog.flexexamples.com/2008/03/09/calling-javascript-functions-from-your-flex-applications-using-the-externalinterface-api/">&#8220;Calling JavaScript functions from your Flex applications using the ExternalInterface API&#8221;</a>, we saw how we could call JavaScript functions from our Flex application.</p> <p>The following example shows us how we can return a value from a JavaScript function call and use the data in our Flex application.</p> <p>Full code after [...]]]></description>
			<content:encoded><![CDATA[<p>In a previous example, <a href="http://blog.flexexamples.com/2008/03/09/calling-javascript-functions-from-your-flex-applications-using-the-externalinterface-api/">&#8220;Calling JavaScript functions from your Flex applications using the ExternalInterface API&#8221;</a>, we saw how we could call JavaScript functions from our Flex application.</p>
<p>The following example shows us how we can return a value from a JavaScript function call and use the data in our Flex application.</p>
<p>Full code after the jump.</p>
<p><span id="more-555"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ExternalInterface_call_test_3/main.mxml">View MXML</a></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;!-- http://blog.flexexamples.com/2008/03/11/returning-values-from-javascript-in-your-flex-applications-using-the-externalinterface-api/ --&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.utils.ObjectUtil;

            private function callJavaScript():void {
                var keys:Array = "appCodeName,appName,appVersion,cookieEnabled,language,platform,systemLanguage,userAgent,userLanguage".split(",");
                var arr:Array = ExternalInterface.call("getNavigatorObject", keys);
                dataGrid.dataProvider = arr;
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Button label="Get browser navigator object"
                click="callJavaScript();" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:DataGrid id="dataGrid"
            variableRowHeight="true"
            width="100%"
            height="100%" &gt;
        &lt;mx:columns&gt;
            &lt;mx:DataGridColumn dataField="key"
                    width="120" /&gt;
            &lt;mx:DataGridColumn dataField="value"
                    wordWrap="true" /&gt;
        &lt;/mx:columns&gt;
    &lt;/mx:DataGrid&gt;

&lt;/mx:Application&gt;
</pre>
<p class="download">/src/externalInterface.js</p>
<pre class="code">
// JavaScript
/** http://blog.flexexamples.com/2008/03/11/returning-values-from-javascript-in-your-flex-applications-using-the-externalinterface-api/ */
function getNavigatorObject(keys) {
    var arr = [];
    var i;
    var len = keys.length;
    var key;
    var value;
    for (i=0; i&lt;len; i++) {
        key = keys[i];
        value = navigator[key];
        arr.push({key:key, value:value});
    }

    return arr;
}
</pre>
<p class="download">/html-template/index.template.html</p>
<pre class="code">
&lt;head&gt;
...
<strong style="color:red;">&lt;script language=&quot;JavaScript&quot; src=&quot;externalInterface.js&quot;&gt;&lt;/script&gt;</strong>
&lt;/head&gt;
</pre>
<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/ExternalInterface_call_test_3/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/ExternalInterface_call_test_3/bin/main.html" width="100%" height="350"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Returning values from JavaScript in your Flex applications using the ExternalInterface API on FlexExamples.com',url: 'http://blog.flexexamples.com/2008/03/11/returning-values-from-javascript-in-your-flex-applications-using-the-externalinterface-api/',contentID: 'post-555',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'call()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2008/03/11/returning-values-from-javascript-in-your-flex-applications-using-the-externalinterface-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

