<?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>flashsimulations.com</title>
	<atom:link href="http://flashsimulations.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://flashsimulations.com</link>
	<description>Rich Internet Applications and Mobile Development &#124; Flash, Flex, AIR, iOS, Android</description>
	<lastBuildDate>Sun, 18 Dec 2011 22:42:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Apple Push Notification Service native extension for Adobe AIR</title>
		<link>http://flashsimulations.com/2011/12/16/apple-push-notification-service-native-extension-for-adobe-air/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=apple-push-notification-service-native-extension-for-adobe-air</link>
		<comments>http://flashsimulations.com/2011/12/16/apple-push-notification-service-native-extension-for-adobe-air/#comments</comments>
		<pubDate>Fri, 16 Dec 2011 01:23:41 +0000</pubDate>
		<dc:creator>Piotr Koscierzynski</dc:creator>
				<category><![CDATA[adobe air]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[air 3.1]]></category>
		<category><![CDATA[APNs]]></category>
		<category><![CDATA[apple push notifications]]></category>
		<category><![CDATA[flash builder]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[native extensions]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://flashsimulations.com/?p=335</guid>
		<description><![CDATA[Here&#8217;s another AIR native extension for iOS I&#8217;m currently working on &#8211; Apple Push Notification Service (APNs) support. It&#8217;s almost complete &#8211; the most important things are there. You can register to APNs, get your device token and receive remote &#8230; <a href="http://flashsimulations.com/2011/12/16/apple-push-notification-service-native-extension-for-adobe-air/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F12%2F16%2Fapple-push-notification-service-native-extension-for-adobe-air%2F' data-shr_title='Apple+Push+Notification+Service+native+extension+for+Adobe+AIR'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F12%2F16%2Fapple-push-notification-service-native-extension-for-adobe-air%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F12%2F16%2Fapple-push-notification-service-native-extension-for-adobe-air%2F' data-shr_title='Apple+Push+Notification+Service+native+extension+for+Adobe+AIR'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F12%2F16%2Fapple-push-notification-service-native-extension-for-adobe-air%2F' data-shr_title='Apple+Push+Notification+Service+native+extension+for+Adobe+AIR'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Here&#8217;s another AIR native extension for iOS I&#8217;m currently working on &#8211; Apple Push Notification Service (APNs) support.<br />
It&#8217;s almost complete &#8211; the most important things are there. You can register to APNs, get your device token and receive remote notification in ActionScript &#8211; everything that you need to build a great app.</p>
<p>Grab the source from github: <a href="https://github.com/pkoscierzynski/NativeAPNService" title="NativeAPNService on GitHub">https://github.com/pkoscierzynski/NativeAPNService</a></p>
<p>To run the example you need to go to Apple Developer Portal and create a new application id, generate push notification certificates and a new mobile provisioning profile.<br />
I&#8217;d recomend this tutorial by Matthijs Hollemans, it&#8217;s very detailed and self explanatory (like all the tutorials on Ray&#8217;s site).<br />
<a href="http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12" title="Apple Push Notification Services Tutorial: Part 1/2" target="_blank">Apple Push Notification Services Tutorial: Part 1/2</a></p>
<p>I also used php sample to publish my message to APNs sandbox servers. Follow the tutorial step by step and you should get everything working.</p>
<p>When you&#8217;ll have your app id and be sure to put it in the apropriate xml tags of AIR application descriptior.<br />
In AIR 3.1, application descriptor has a new section for iOS apps &#8211; Entitlements. In Entitlements section you need to provide the id of you application, otherwise the APN won&#8217;t work (this section is the content of Entitlements.plist file known from native Xcode / Objective-C).</p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2011/12/Entitlements_AIR_app_descriptor.png"><img src="http://flashsimulations.com/wp-content/uploads/2011/12/Entitlements_AIR_app_descriptor.png" alt="Adobe AIR application descriptor. iPhone Entitlements section." title="Adobe AIR application descriptor. iPhone Entitlements section." width="485" height="433" class="alignleft size-full wp-image-337" /></a></p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2011/12/AIR_app_APN-1.png"><img src="http://flashsimulations.com/wp-content/uploads/2011/12/AIR_app_APN-1.png" alt="" title="Push notification - app in the background" width="320" height="480" class="alignleft size-full wp-image-338" /></a></p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2011/12/AIR_app_APN-2.png"><img src="http://flashsimulations.com/wp-content/uploads/2011/12/AIR_app_APN-2.png" alt="" title="Example app - showing events from extension" width="320" height="480" class="alignleft size-full wp-image-339" /></a></p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2011/12/AIR_app_APN-3.png"><img src="http://flashsimulations.com/wp-content/uploads/2011/12/AIR_app_APN-3.png" alt="" title="Example app - showing remote notification" width="320" height="480" class="alignleft size-full wp-image-340" /></a></p>
<p><iframe src="http://player.vimeo.com/video/33873158?title=0&amp;byline=0&amp;portrait=0" width="400" height="300" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
<p><a href="http://vimeo.com/33873158">Apple Push Notifications in Adobe AIR iOS application</a> from <a href="http://vimeo.com/pkoscierzynski">Piotr Koscierzynski</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<div class="shr-publisher-335"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F12%2F16%2Fapple-push-notification-service-native-extension-for-adobe-air%2F' data-shr_title='Apple+Push+Notification+Service+native+extension+for+Adobe+AIR'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F12%2F16%2Fapple-push-notification-service-native-extension-for-adobe-air%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F12%2F16%2Fapple-push-notification-service-native-extension-for-adobe-air%2F' data-shr_title='Apple+Push+Notification+Service+native+extension+for+Adobe+AIR'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F12%2F16%2Fapple-push-notification-service-native-extension-for-adobe-air%2F' data-shr_title='Apple+Push+Notification+Service+native+extension+for+Adobe+AIR'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://flashsimulations.com/2011/12/16/apple-push-notification-service-native-extension-for-adobe-air/feed/</wfw:commentRss>
		<slash:comments>47</slash:comments>
		</item>
		<item>
		<title>iOS native extension for Adobe AIR. In-app mail composer</title>
		<link>http://flashsimulations.com/2011/11/30/ios-native-extension-for-adobe-air-in-app-mail-composer/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ios-native-extension-for-adobe-air-in-app-mail-composer</link>
		<comments>http://flashsimulations.com/2011/11/30/ios-native-extension-for-adobe-air-in-app-mail-composer/#comments</comments>
		<pubDate>Wed, 30 Nov 2011 22:11:50 +0000</pubDate>
		<dc:creator>Piotr Koscierzynski</dc:creator>
				<category><![CDATA[adobe air]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[air 3.1]]></category>
		<category><![CDATA[flash builder]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[native extensions]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://flashsimulations.com/?p=252</guid>
		<description><![CDATA[In this tutorial I will show how to create an iOS native extension for Adobe AIR. My extension enables sending an e-mail by invoking MFMailComposeViewController on iOS. This way you can send an e-mail without leaving you app, attachments are supported, &#8230; <a href="http://flashsimulations.com/2011/11/30/ios-native-extension-for-adobe-air-in-app-mail-composer/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F11%2F30%2Fios-native-extension-for-adobe-air-in-app-mail-composer%2F' data-shr_title='iOS+native+extension+for+Adobe+AIR.+In-app+mail+composer'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F11%2F30%2Fios-native-extension-for-adobe-air-in-app-mail-composer%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F11%2F30%2Fios-native-extension-for-adobe-air-in-app-mail-composer%2F' data-shr_title='iOS+native+extension+for+Adobe+AIR.+In-app+mail+composer'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F11%2F30%2Fios-native-extension-for-adobe-air-in-app-mail-composer%2F' data-shr_title='iOS+native+extension+for+Adobe+AIR.+In-app+mail+composer'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p><a href="http://flashsimulations.com/wp-content/uploads/2011/11/native-ios-library-flash-builder.png"><br />
</a>In this tutorial I will show how to create an iOS native extension for Adobe AIR. My extension enables sending an e-mail by invoking MFMailComposeViewController on iOS. This way you can send an e-mail without leaving you app, attachments are supported, too.</p>
<p>Grab the source from github: <a title="iOS in-app mail native extension for Adobe AIR" href="https://github.com/pkoscierzynski/NativeMailExtension">iOS In-app mail Native Extension for Adobe AIR</a></p>
<h2>How to use iOS mail extension</h2>
<p>Create an intance of class pl.randori.air.nativeextensions.ios.MailExtension and call method<br />
sendMail(subject:String, messageBody:String, toRecipients:String, ccRecipients:String = &#8221;&#8221;, bccRecipients:String = &#8221;&#8221;, attachmentsData:Array = null):void</p>
<p>To add an attachment from application bundle:</p>
<ul>filename|bundle|file_mimetype|name_of_file_to_be_shown_in_mail</ul>
<p>to  add an attachment from application documents directory use</p>
<ul>filename|documents|file_mimetype|name_of_file_to_be_shown_in_mail</ul>
<p>sendMail method implementation should make it more clear</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param subject Mail subject<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param messageBody Mail body (can include HTML)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param toRecipients To: recipients in format: &quot;mail@example.com,mail2@example.com&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param ccRecipients Cc: recipients in format: &quot;mail@example.com,mail2@example.com&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param bccRecipients Bcc: recipients in format: &quot;mail@example.com,mail2@example.com&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param attachmentsData Attachments in format: ['filename|bundle|mimetype|name of file to display in attachment']<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* example: [&quot;Default.png|bundle|image/png|Application splash screen.png&quot;,&quot;Example file.dat|documents|text/xml|A file saved in Adobe AIR iOS app.txt&quot;]<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> sendMail<span style="color: #000000;">&#40;</span>subject<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> messageBody<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> toRecipients<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ccRecipients<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">''</span><span style="color: #000066; font-weight: bold;">,</span> bccRecipients<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">''</span><span style="color: #000066; font-weight: bold;">,</span> attachmentsData<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; extensionContext<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">StatusEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">STATUS</span><span style="color: #000066; font-weight: bold;">,</span> onStatusEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; extensionContext<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;sendMailWithOptions&quot;</span><span style="color: #000066; font-weight: bold;">,</span> subject<span style="color: #000066; font-weight: bold;">,</span> messageBody<span style="color: #000066; font-weight: bold;">,</span> toRecipients<span style="color: #000066; font-weight: bold;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ccRecipients<span style="color: #000066; font-weight: bold;">,</span> bccRecipients<span style="color: #000066; font-weight: bold;">,</span> attachmentsData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>MailExtension dispatches MainExtensionEvent.MAIL_COMPOSER_EVENT to let you know what&#8217;s going on. You will be notified if the user has sent the mail, saved it, canceled, etc.<br />
Also there will be notifications WILL_SHOW_MAIL_COMPOSER and WILL_HIDE_MAIL_COMPOSER so you could know when the mail composer is shown and dismissed.<br />
This can be used to stop / resume task in AIR while the mail composer is present on the screen</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Creating an native extension for Adobe AIR requires some iOS/Objective-C knowledge so don&#8217;t worry if not everything&#8217;s clear at the beginning.</p>
<p>I divided the process of development to three steps</p>
<p>1. Creating a native library in Xcode<br />
2. Creating an ActionScript library which will act as a middleware between Adobe AIR and iOS<br />
3. Creating an example Adobe AIR app</p>
<p>My development environtment was Flash Builder 4.5 with Flex SDK 4.5.1 and AIR SDK 3.1 and Xcode 4.2 and iOS SDK 5. Flash Builder 4.5 doesn&#8217;t support native extensions development, so I&#8217;ve used ANT to compile and package everything.</p>
<p><span style="text-decoration: underline; color: #ff9900;">Before starting be sure to merge Flex SDK with Adobe AIR SDK.<br />
</span></p>
<h2>Creating the native library in Xcode for AIR an iOS</h2>
<p>A native library can be written in Objective-C, C/C++ or Java depending on the target platform. Currently extensions for iOS, Android, BlackBerry PlayBook and AIR TV are supported. The library exposes an API that the Adobe AIR application can use, which can include functionalities that are not available in the current release of Adobe AIR or make use of performance of native code (math, physics computations; image processing, etc.).</p>
<p>On iOS Adobe AIR cannot access to such APIs as: Game Center, In-App Purchase, Twitter or Bluetooth. With native extensions we can create a fully featured iOS app.</p>
<p>In Xcode create a new static library project and set the project setting as follows:</p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2011/11/xcode_adobe_air_native_extension-1.png"><img class="aligncenter size-full wp-image-267" title="xcode_adobe_air_native_extension-1" src="http://flashsimulations.com/wp-content/uploads/2011/11/xcode_adobe_air_native_extension-1.png" alt="" width="739" height="279" /></a></p>
<p>&nbsp;</p>
<p>Set &#8220;Enable Linking with Shared Libraries&#8221; to NO if when packaging your app into an ipa archive you see in console a message that looks like:<br />
<span class="Apple-style-span" style="font-family: monospace; font-size: 12px; line-height: 18px; white-space: pre; color: #ff9900;">ld warning: unexpected srelocation type 9</span></p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2011/11/xcode_adobe_air_native_extension-2.png"><img class="aligncenter size-full wp-image-268" title="xcode_adobe_air_native_extension-2" src="http://flashsimulations.com/wp-content/uploads/2011/11/xcode_adobe_air_native_extension-2.png" alt="" width="740" height="294" /></a><br />
<strong>Add FlashRuntimeExtensions.h and implement required methods</strong><br />
Next, you need to add FlashRuntimeExtensions.h to your project. This file can be found in FLEX_SDK\include. This file will provide necessary data types definitions and functions that will be used for communication between native code and AIR app.</p>
<p>Native extension written using C API (which iOS extension are) requires four methods to be implemented:</p>
<ul>
<li>extension initializer</li>
<li>extension finalizer</li>
<li>context initializer</li>
<li>context finalizer</li>
</ul>
<p>In MailExtension.m those functions are: ExtInitializer, ExtFinalizer, ContextInitializer, ContextFinalizer. Those are just the names I used, they can actually be named anything you want, but you must provide those functions&#8217; names in configuration xmls.</p>
<p>My main extension file MailExtension.m looks like this:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;height:600px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br />150<br />151<br />152<br />153<br />154<br />155<br />156<br />157<br />158<br />159<br />160<br />161<br />162<br />163<br />164<br />165<br />166<br />167<br />168<br />169<br />170<br />171<br />172<br />173<br />174<br />175<br />176<br />177<br />178<br />179<br />180<br />181<br />182<br />183<br />184<br />185<br />186<br />187<br />188<br />189<br />190<br />191<br />192<br />193<br />194<br />195<br />196<br />197<br />198<br />199<br />200<br />201<br />202<br />203<br />204<br />205<br />206<br />207<br />208<br />209<br />210<br />211<br />212<br />213<br />214<br />215<br />216<br />217<br />218<br />219<br />220<br />221<br />222<br />223<br />224<br />225<br />226<br />227<br />228<br />229<br />230<br />231<br />232<br />233<br />234<br />235<br />236<br />237<br />238<br />239<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;MailExtension.m</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;MailExtension</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;Created by Piotr Kościerzyński on 11-11-29.</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;Copyright (c) 2011 Randori. All rights reserved.</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<br />
<span style="color: #6e371a;">#import &quot;MailExtension.h&quot;</span><br />
<br />
<br />
<span style="color: #a61390;">@implementation</span> MailExtension<br />
<br />
<span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>attachmentsSeparator <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;----&quot;</span>;<br />
<span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>event_name <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MAIL_COMPOSER_EVENT&quot;</span>;<br />
<br />
FREContext g_ctx;<br />
MailComposerHelper <span style="color: #002200;">*</span>mailComposerHelper;<br />
<br />
<span style="color: #002200;">-</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">id</span><span style="color: #002200;">&#41;</span>init<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>self<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Initialization code here.</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> self;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">int</span> canSendMail<span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #a61390;">BOOL</span> result <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//On pre iOS 3.0 devices MFMailComposeViewController does not exists</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">Class</span> mailClass <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>NSClassFromString<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MFMailComposeViewController&quot;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>mailClass <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// We must always check whether the current device is configured for sending emails</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>mailClass canSendMail<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result <span style="color: #002200;">=</span> <span style="color: #a61390;">YES</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//this will never happen since Adobe AIR requires at least iOS 4.0</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; result <span style="color: #002200;">=</span> <span style="color: #a61390;">NO</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span>result;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #11740a; font-style: italic;">//Can we invoke in-app mail ?</span><br />
FREObject PKIsMailComposerAvailable<span style="color: #002200;">&#40;</span>FREContext ctx, <span style="color: #a61390;">void</span><span style="color: #002200;">*</span> funcData, uint32_t argc, FREObject argv<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">BOOL</span> ret <span style="color: #002200;">=</span> canSendMail<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; FREObject retVal;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; FRENewObjectFromBool<span style="color: #002200;">&#40;</span>ret, <span style="color: #002200;">&amp;</span>retVal<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> retVal; &nbsp; &nbsp;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #11740a; font-style: italic;">//Send mail</span><br />
FREObject PKSendMailWithOptions<span style="color: #002200;">&#40;</span>FREContext ctx, <span style="color: #a61390;">void</span><span style="color: #002200;">*</span> funcData, uint32_t argc, FREObject argv<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">&#41;</span><br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">BOOL</span> ret <span style="color: #002200;">=</span> canSendMail<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span>ret<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; FREDispatchStatusEventAsync<span style="color: #002200;">&#40;</span>ctx, <span style="color: #002200;">&#40;</span>uint8_t<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>event_name UTF8String<span style="color: #002200;">&#93;</span>, <span style="color: #002200;">&#40;</span>uint8_t<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MAIL_COMPOSER_NOT_AVAILABLE&quot;</span> UTF8String<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #a61390;">NULL</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span><span style="color: #002200;">&#40;</span>argc&lt;<span style="color: #2400d9;">3</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; FREDispatchStatusEventAsync<span style="color: #002200;">&#40;</span>ctx, <span style="color: #002200;">&#40;</span>uint8_t<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>event_name UTF8String<span style="color: #002200;">&#93;</span>, <span style="color: #002200;">&#40;</span>uint8_t<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;NOT_ENOUGH_PARAMETERS_PROVIDED&quot;</span> UTF8String<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #a61390;">NULL</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//Subject</span><br />
&nbsp; &nbsp; uint32_t subjectLength;<br />
&nbsp; &nbsp; <span style="color: #a61390;">const</span> uint8_t <span style="color: #002200;">*</span>subjectCString;<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//To Recipients</span><br />
&nbsp; &nbsp; uint32_t toRecipientsLength;<br />
&nbsp; &nbsp; <span style="color: #a61390;">const</span> uint8_t <span style="color: #002200;">*</span>toRecipientsCString;<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//CC Recipients</span><br />
&nbsp; &nbsp; uint32_t ccRecipientsLength;<br />
&nbsp; &nbsp; <span style="color: #a61390;">const</span> uint8_t <span style="color: #002200;">*</span>ccRecipientsCString;<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//Bcc Recipients</span><br />
&nbsp; &nbsp; uint32_t bccRecipientsLength;<br />
&nbsp; &nbsp; <span style="color: #a61390;">const</span> uint8_t <span style="color: #002200;">*</span>bccRecipientsCString;<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//Message Body</span><br />
&nbsp; &nbsp; uint32_t messageBodyLength;<br />
&nbsp; &nbsp; <span style="color: #a61390;">const</span> uint8_t <span style="color: #002200;">*</span>messageBodyCString;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #400080;">NSMutableString</span> <span style="color: #002200;">*</span>attachmentsString <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;<br />
&nbsp; &nbsp; <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>subjectString <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;<br />
&nbsp; &nbsp; <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>toRecipientsString <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;<br />
&nbsp; &nbsp; <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>ccRecipientsString <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;<br />
&nbsp; &nbsp; <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>bccRecipientsString <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;<br />
&nbsp; &nbsp; <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>messageBodyString <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//Create NSStrings from CStrings</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>FRE_OK <span style="color: #002200;">==</span> FREGetObjectAsUTF8<span style="color: #002200;">&#40;</span>argv<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>, <span style="color: #002200;">&amp;</span>subjectLength, <span style="color: #002200;">&amp;</span>subjectCString<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; subjectString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithUTF8String<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">char</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>subjectCString<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>FRE_OK <span style="color: #002200;">==</span> FREGetObjectAsUTF8<span style="color: #002200;">&#40;</span>argv<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>, <span style="color: #002200;">&amp;</span>messageBodyLength, <span style="color: #002200;">&amp;</span>messageBodyCString<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; messageBodyString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithUTF8String<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">char</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>messageBodyCString<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>FRE_OK <span style="color: #002200;">==</span> FREGetObjectAsUTF8<span style="color: #002200;">&#40;</span>argv<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span>, <span style="color: #002200;">&amp;</span>toRecipientsLength, <span style="color: #002200;">&amp;</span>toRecipientsCString<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; toRecipientsString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithUTF8String<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">char</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>toRecipientsCString<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>argc &gt;<span style="color: #002200;">=</span> <span style="color: #2400d9;">4</span> <span style="color: #002200;">&amp;&amp;</span> <span style="color: #002200;">&#40;</span>FRE_OK <span style="color: #002200;">==</span> FREGetObjectAsUTF8<span style="color: #002200;">&#40;</span>argv<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">3</span><span style="color: #002200;">&#93;</span>, <span style="color: #002200;">&amp;</span>ccRecipientsLength, <span style="color: #002200;">&amp;</span>ccRecipientsCString<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; ccRecipientsString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithUTF8String<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">char</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>ccRecipientsCString<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>argc &gt;<span style="color: #002200;">=</span> <span style="color: #2400d9;">5</span> <span style="color: #002200;">&amp;&amp;</span> <span style="color: #002200;">&#40;</span>FRE_OK <span style="color: #002200;">==</span> FREGetObjectAsUTF8<span style="color: #002200;">&#40;</span>argv<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">4</span><span style="color: #002200;">&#93;</span>, <span style="color: #002200;">&amp;</span>bccRecipientsLength, <span style="color: #002200;">&amp;</span>bccRecipientsCString<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; bccRecipientsString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithUTF8String<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">char</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>bccRecipientsCString<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp;uint32_t attachmentsArrayLength <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>;<br />
&nbsp; &nbsp; <br />
<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//argv[5] is a an array of strings</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>argc &gt;<span style="color: #002200;">=</span> <span style="color: #2400d9;">6</span> <span style="color: #002200;">&amp;&amp;</span> <span style="color: #002200;">&#40;</span>FRE_OK <span style="color: #002200;">!=</span> FREGetArrayLength<span style="color: #002200;">&#40;</span>argv<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">5</span><span style="color: #002200;">&#93;</span>, <span style="color: #002200;">&amp;</span>attachmentsArrayLength<span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//No valid array of attachments provided.</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>attachmentsArrayLength &gt;<span style="color: #002200;">=</span> <span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; attachmentsString <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSMutableString</span> alloc <span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; uint32_t attachmentEntryLength;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">const</span> uint8_t <span style="color: #002200;">*</span>attachmentEntryCString;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span> i <span style="color: #002200;">=</span> <span style="color: #2400d9;">0</span>; i &lt; attachmentsArrayLength; i<span style="color: #002200;">++</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FREObject arrayElement;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FREGetArrayElementAt<span style="color: #002200;">&#40;</span>argv<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">5</span><span style="color: #002200;">&#93;</span>, i, <span style="color: #002200;">&amp;</span>arrayElement<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FREGetObjectAsUTF8<span style="color: #002200;">&#40;</span>arrayElement, <span style="color: #002200;">&amp;</span>attachmentEntryLength, <span style="color: #002200;">&amp;</span>attachmentEntryCString<span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>attachmentsString appendString<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSString</span> stringWithUTF8String<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">char</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>attachmentEntryCString<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>i&lt;<span style="color: #002200;">&#40;</span>attachmentsArrayLength<span style="color: #002200;">-</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>attachmentsString appendString<span style="color: #002200;">:</span>attachmentsSeparator<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>mailComposerHelper<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; mailComposerHelper <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MailComposerHelper alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>mailComposerHelper setContext<span style="color: #002200;">:</span>ctx<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>mailComposerHelper sendMailWithSubject<span style="color: #002200;">:</span>subjectString <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;toRecipients<span style="color: #002200;">:</span>toRecipientsString <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ccRecipients<span style="color: #002200;">:</span>ccRecipientsString<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bccRecipients<span style="color: #002200;">:</span>bccRecipientsString <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; messageBody<span style="color: #002200;">:</span>messageBodyString <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; attachmentsData<span style="color: #002200;">:</span>attachmentsString<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>attachmentsString <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>attachmentsString release<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span> <span style="color: #a61390;">NULL</span>; &nbsp; &nbsp;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<br />
<span style="color: #11740a; font-style: italic;">//------------------------------------</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// Required Methods.</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">//------------------------------------</span><br />
<br />
<span style="color: #11740a; font-style: italic;">// ContextInitializer()</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// The context initializer is called when the runtime creates the extension context instance.</span><br />
<span style="color: #a61390;">void</span> ContextInitializer<span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">*</span> extData, <span style="color: #a61390;">const</span> uint8_t<span style="color: #002200;">*</span> ctxType, FREContext ctx, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uint32_t<span style="color: #002200;">*</span> numFunctionsToTest, <span style="color: #a61390;">const</span> FRENamedFunction<span style="color: #002200;">**</span> functionsToSet<span style="color: #002200;">&#41;</span> <br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//we expose two methods to ActionScript</span><br />
&nbsp; &nbsp; <span style="color: #002200;">*</span>numFunctionsToTest <span style="color: #002200;">=</span> <span style="color: #2400d9;">2</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; FRENamedFunction<span style="color: #002200;">*</span> func <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span>FRENamedFunction<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> <span style="color: #a61390;">malloc</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">sizeof</span><span style="color: #002200;">&#40;</span>FRENamedFunction<span style="color: #002200;">&#41;</span> <span style="color: #002200;">*</span> <span style="color: #2400d9;">2</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; func<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>.name <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">const</span> uint8_t<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> <span style="color: #bf1d1a;">&quot;sendMailWithOptions&quot;</span>;<br />
&nbsp; &nbsp; func<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>.functionData <span style="color: #002200;">=</span> <span style="color: #a61390;">NULL</span>;<br />
&nbsp; &nbsp; func<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>.function <span style="color: #002200;">=</span> <span style="color: #002200;">&amp;</span>PKSendMailWithOptions;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; func<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>.name <span style="color: #002200;">=</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">const</span> uint8_t<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> <span style="color: #bf1d1a;">&quot;isMailComposerAvailable&quot;</span>;<br />
&nbsp; &nbsp; func<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>.functionData <span style="color: #002200;">=</span> <span style="color: #a61390;">NULL</span>;<br />
&nbsp; &nbsp; func<span style="color: #002200;">&#91;</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>.function <span style="color: #002200;">=</span> <span style="color: #002200;">&amp;</span>PKIsMailComposerAvailable;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #002200;">*</span>functionsToSet <span style="color: #002200;">=</span> func;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; g_ctx <span style="color: #002200;">=</span> ctx;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #11740a; font-style: italic;">// ContextFinalizer()</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// The context finalizer is called when the extension's ActionScript code</span><br />
<span style="color: #11740a; font-style: italic;">// calls the ExtensionContext instance's dispose() method.</span><br />
<span style="color: #11740a; font-style: italic;">// If the AIR runtime garbage collector disposes of the ExtensionContext instance, the runtime also calls</span><br />
<span style="color: #11740a; font-style: italic;">// ContextFinalizer().</span><br />
<br />
<span style="color: #a61390;">void</span> ContextFinalizer<span style="color: #002200;">&#40;</span>FREContext ctx<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>mailComposerHelper setContext<span style="color: #002200;">:</span><span style="color: #a61390;">NULL</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>mailComposerHelper release<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; mailComposerHelper <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #11740a; font-style: italic;">// ExtInitializer()</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// The extension initializer is called the first time the ActionScript side of the extension</span><br />
<span style="color: #11740a; font-style: italic;">// calls ExtensionContext.createExtensionContext() for any context.</span><br />
<span style="color: #a61390;">void</span> ExtInitializer<span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">**</span> extDataToSet, FREContextInitializer<span style="color: #002200;">*</span> ctxInitializerToSet, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FREContextFinalizer<span style="color: #002200;">*</span> ctxFinalizerToSet<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #002200;">*</span>extDataToSet <span style="color: #002200;">=</span> <span style="color: #a61390;">NULL</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">*</span>ctxInitializerToSet <span style="color: #002200;">=</span> <span style="color: #002200;">&amp;</span>ContextInitializer;<br />
&nbsp; &nbsp; <span style="color: #002200;">*</span>ctxFinalizerToSet <span style="color: #002200;">=</span> <span style="color: #002200;">&amp;</span>ContextFinalizer;<br />
<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #11740a; font-style: italic;">// ExtFinalizer()</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// The extension finalizer is called when the runtime unloads the extension. However, it is not always called.</span><br />
<span style="color: #a61390;">void</span> ExtFinalizer<span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">*</span> extData<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #a61390;">return</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>MailExtension.m is responsible for instantiating the extension and invoking the methods called from ActionScript.</p>
<p>Second part of Objective-C code is MailComposerHelper class which does all the work needed to send the mail.<br />
This class manages MFMailComposeViewController and dispatches events back to ActionScript. </p>
<p>MailComposerHelper implementation looks like this:</p>
<div class="codecolorer-container objc default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;height:600px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br />106<br />107<br />108<br />109<br />110<br />111<br />112<br />113<br />114<br />115<br />116<br />117<br />118<br />119<br />120<br />121<br />122<br />123<br />124<br />125<br />126<br />127<br />128<br />129<br />130<br />131<br />132<br />133<br />134<br />135<br />136<br />137<br />138<br />139<br />140<br />141<br />142<br />143<br />144<br />145<br />146<br />147<br />148<br />149<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;MailComposerHelper.m</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;NativeMail iOS extension for Adobe AIR</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;Created by Piotr Kościerzyński on 11-11-28.</span><br />
<span style="color: #11740a; font-style: italic;">// &nbsp;Copyright (c) 2011 Randori. All rights reserved.</span><br />
<span style="color: #11740a; font-style: italic;">//</span><br />
<br />
<span style="color: #6e371a;">#import &quot;MailComposerHelper.h&quot;</span><br />
<br />
<span style="color: #a61390;">@implementation</span> MailComposerHelper<br />
<br />
<span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>attachmentPropertySeparator <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;|&quot;</span>;<br />
<span style="color: #a61390;">static</span> <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>attachmentsSeparator <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;----&quot;</span>;<br />
<span style="color: #11740a; font-style: italic;">//Event name</span><br />
<span style="color: #a61390;">static</span> &nbsp;<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>event_name <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MAIL_COMPOSER_EVENT&quot;</span>;<br />
<br />
<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> sendMailWithSubject<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>subject <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;toRecipients<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>toRecipients <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ccRecipients<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>ccRecipients <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bccRecipients<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>bccRecipients <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; messageBody<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>messageBody <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; attachmentsData<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>attachmentsData<br />
<span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; FREDispatchStatusEventAsync<span style="color: #002200;">&#40;</span>context, <span style="color: #002200;">&#40;</span>uint8_t<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>event_name UTF8String<span style="color: #002200;">&#93;</span>, <span style="color: #002200;">&#40;</span>uint8_t<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;WILL_SHOW_MAIL_COMPOSER&quot;</span> UTF8String<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; MFMailComposeViewController <span style="color: #002200;">*</span>mailComposer <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>MFMailComposeViewController alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; mailComposer.mailComposeDelegate <span style="color: #002200;">=</span> self;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>subject <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>mailComposer setSubject<span style="color: #002200;">:</span> subject<span style="color: #002200;">&#93;</span>; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>messageBody <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span><span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>mailComposer setMessageBody<span style="color: #002200;">:</span>messageBody isHTML<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>toRecipients <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span> <span style="color: #002200;">&amp;&amp;</span> <span style="color: #002200;">&#91;</span>toRecipients rangeOfString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;@&quot;</span><span style="color: #002200;">&#93;</span>.location <span style="color: #002200;">!=</span> NSNotFound<span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>mailComposer setToRecipients<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>toRecipients componentsSeparatedByString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;,&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>ccRecipients <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span> <span style="color: #002200;">&amp;&amp;</span> <span style="color: #002200;">&#91;</span>ccRecipients rangeOfString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;@&quot;</span><span style="color: #002200;">&#93;</span>.location <span style="color: #002200;">!=</span> NSNotFound<span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>mailComposer setCcRecipients<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>ccRecipients componentsSeparatedByString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;,&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>bccRecipients <span style="color: #002200;">!=</span> <span style="color: #a61390;">nil</span> <span style="color: #002200;">&amp;&amp;</span> <span style="color: #002200;">&#91;</span>bccRecipients rangeOfString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;@&quot;</span><span style="color: #002200;">&#93;</span>.location <span style="color: #002200;">!=</span> NSNotFound<span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>mailComposer setBccRecipients<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>bccRecipients componentsSeparatedByString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;,&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//Add attachments (if any)</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>attachmentsData<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span> &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>paths <span style="color: #002200;">=</span> NSSearchPathForDirectoriesInDomains<span style="color: #002200;">&#40;</span>NSDocumentDirectory, NSUserDomainMask, <span style="color: #a61390;">YES</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>documentsDirectory <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>paths objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>filePath;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>attachmentProperties;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>fileName;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>fileExtension;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>fileSearchSource;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>fileMimeType;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>fileAttachName;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #400080;">NSArray</span> <span style="color: #002200;">*</span>attachments <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>attachmentsData componentsSeparatedByString<span style="color: #002200;">:</span>attachmentsSeparator<span style="color: #002200;">&#93;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">for</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>attachmentEntry <span style="color: #a61390;">in</span> attachments<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; attachmentProperties <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>attachmentEntry componentsSeparatedByString<span style="color: #002200;">:</span>attachmentPropertySeparator<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fileName <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>attachmentProperties objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span> componentsSeparatedByString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;.&quot;</span><span style="color: #002200;">&#93;</span> objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fileExtension <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>attachmentProperties objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span> componentsSeparatedByString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;.&quot;</span><span style="color: #002200;">&#93;</span> objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fileSearchSource <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>attachmentProperties objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span> lowercaseString<span style="color: #002200;">&#93;</span>;<span style="color: #11740a; font-style: italic;">//bundle or documents</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fileMimeType <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>attachmentProperties objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">2</span><span style="color: #002200;">&#93;</span>;<span style="color: #11740a; font-style: italic;">//mime type of file</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fileAttachName <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>attachmentProperties objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">3</span><span style="color: #002200;">&#93;</span>;<span style="color: #11740a; font-style: italic;">//how to name the file</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//search for file in app bundle</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>fileSearchSource isEqualToString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;bundle&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filePath <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSBundle</span> mainBundle<span style="color: #002200;">&#93;</span> pathForResource<span style="color: #002200;">:</span>fileName ofType<span style="color: #002200;">:</span>fileExtension<span style="color: #002200;">&#93;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//search for file in Documents</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>fileSearchSource isEqualToString<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;documents&quot;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; filePath <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>documentsDirectory stringByAppendingPathComponent<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>attachmentProperties objectAtIndex<span style="color: #002200;">:</span><span style="color: #2400d9;">0</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">else</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//ERROR - ignoring</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">continue</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSFileManager</span> defaultManager<span style="color: #002200;">&#93;</span> fileExistsAtPath<span style="color: #002200;">:</span>filePath<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #400080;">NSData</span> <span style="color: #002200;">*</span>fileData <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #400080;">NSData</span> alloc<span style="color: #002200;">&#93;</span> initWithContentsOfFile<span style="color: #002200;">:</span>filePath<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span>fileData<span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>mailComposer addAttachmentData<span style="color: #002200;">:</span> fileData mimeType<span style="color: #002200;">:</span>fileMimeType fileName<span style="color: #002200;">:</span>fileAttachName<span style="color: #002200;">&#93;</span>; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#91;</span>fileData release<span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//show mail composer</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span> keyWindow<span style="color: #002200;">&#93;</span> rootViewController<span style="color: #002200;">&#93;</span> presentModalViewController<span style="color: #002200;">:</span>mailComposer animated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;<br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span>mailComposer release<span style="color: #002200;">&#93;</span>;<br />
<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #11740a; font-style: italic;">// Dismisses the email composition interface when users tap Cancel or Send.</span><br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> mailComposeController<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>MFMailComposeViewController<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>controller didFinishWithResult<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span>MFMailComposeResult<span style="color: #002200;">&#41;</span>result error<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span><span style="color: #400080;">NSError</span><span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>error<br />
<span style="color: #002200;">&#123;</span> &nbsp; <br />
&nbsp; &nbsp; <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>event_info <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;&quot;</span>;<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">// Notifies users about errors associated with the interface</span><br />
&nbsp; &nbsp; <span style="color: #a61390;">switch</span> <span style="color: #002200;">&#40;</span>result<span style="color: #002200;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> MFMailComposeResultCancelled<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event_info <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MAIL_CANCELED&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> MFMailComposeResultSaved<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event_info <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MAIL_SAVED&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> MFMailComposeResultSent<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event_info <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MAIL_SENT&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">case</span> MFMailComposeResultFailed<span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event_info <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MAIL_FAILED&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">default</span><span style="color: #002200;">:</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event_info <span style="color: #002200;">=</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MAIL_UNKNOWN&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a61390;">break</span>;<br />
&nbsp; &nbsp; <span style="color: #002200;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; FREDispatchStatusEventAsync<span style="color: #002200;">&#40;</span>context, <span style="color: #002200;">&#40;</span>uint8_t<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>event_name UTF8String<span style="color: #002200;">&#93;</span>, <span style="color: #002200;">&#40;</span>uint8_t<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>event_info UTF8String<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; FREDispatchStatusEventAsync<span style="color: #002200;">&#40;</span>context, <span style="color: #002200;">&#40;</span>uint8_t<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span>event_name UTF8String<span style="color: #002200;">&#93;</span>, <span style="color: #002200;">&#40;</span>uint8_t<span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#91;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;WILL_HIDE_MAIL_COMPOSER&quot;</span> UTF8String<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span>;<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; context <span style="color: #002200;">=</span> <span style="color: #a61390;">nil</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #11740a; font-style: italic;">//hide mail composer</span><br />
&nbsp; &nbsp; <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIApplication sharedApplication<span style="color: #002200;">&#93;</span> keyWindow<span style="color: #002200;">&#93;</span> rootViewController<span style="color: #002200;">&#93;</span> dismissModalViewControllerAnimated<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span>setContext<span style="color: #002200;">:</span><span style="color: #002200;">&#40;</span>FREContext<span style="color: #002200;">&#41;</span>ctx <span style="color: #002200;">&#123;</span><br />
&nbsp; &nbsp; context <span style="color: #002200;">=</span> ctx;<br />
<span style="color: #002200;">&#125;</span><br />
<br />
<br />
<span style="color: #a61390;">@end</span></div></td></tr></tbody></table></div>
<p>Native iOS code can dispatch events for ActionScript &#8211; it&#8217;s done by calling FREDispatchStatusEventAsync. This will be seen as a StatusEvent.STATUS in Adobe AIR. I used it to let my application know whether the mail composer can be shown and to inform about the mail compose result and status.</p>
<p>When you build the static library you will get libMailExtension.a file in &#8216;build&#8217; directory.<br />
This file will be needed in &#8216;NativeMail-iOS&#8217; library project to create .swc and .ane files.</p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2011/11/xcode-library-mailextension.png"><img class="aligncenter size-full wp-image-291" title="xcode-library-mailextension" src="http://flashsimulations.com/wp-content/uploads/2011/11/xcode-library-mailextension.png" alt="" width="284" height="267" /></a></p>
<p>&nbsp;</p>
<h2>Creating Adobe Native Extension project</h2>
<p>In Flash Builder create a new ActionScript Library project. The project will contain ActionScript classes responsible for calling iOS code.</p>
<p>My project&#8217;s structure &#8211; you can see the libMailExtension.a file present</p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2011/11/native-ios-library-flash-builder.png"><img title="native-ios-library-flash-builder" src="http://flashsimulations.com/wp-content/uploads/2011/11/native-ios-library-flash-builder.png" alt="" width="196" height="238" /></a></p>
<p>&nbsp;</p>
<p>Since I used command line tools to create the extension there are  lot of configuration files and ANT scripts, if you&#8217;re using Flash Builder 4.6 it should be much simpler.</p>
<p>&nbsp;</p>
<p>iOS library methods are invoked by calling extensionContext.call method.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;height:600px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #9900cc; font-weight: bold;">package</span> pl<span style="color: #000066; font-weight: bold;">.</span>randori<span style="color: #000066; font-weight: bold;">.</span>air<span style="color: #000066; font-weight: bold;">.</span>nativeextensions<span style="color: #000066; font-weight: bold;">.</span>ios<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">EventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IEventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">StatusEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.external</span><span style="color: #000066; font-weight: bold;">.</span>ExtensionContext<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp;* An iOS native extension for Adobe AIR 3.1 for sending mail.<br />
&nbsp; &nbsp; &nbsp;* Implements MFMailComposeViewController in iOS<br />
&nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp;* @author Piotr Kościerzyński, piotr@flashsimulations.com<br />
&nbsp; &nbsp; &nbsp;* www.flashsimulations.com<br />
&nbsp; &nbsp; &nbsp;* www.randori.pl<br />
&nbsp; &nbsp; &nbsp;* <br />
&nbsp; &nbsp; &nbsp;* */</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> MailExtension <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">EventDispatcher</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">protected</span> <span style="color: #6699cc; font-weight: bold;">var</span> extensionContext<span style="color: #000066; font-weight: bold;">:</span>ExtensionContext<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> static const EXTENSION_ID <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;pl.randori.air.nativeextensions.ios.MailExtension&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> MailExtension<span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">IEventDispatcher</span>=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">target</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; extensionContext = ExtensionContext<span style="color: #000066; font-weight: bold;">.</span>createExtensionContext<span style="color: #000000;">&#40;</span> EXTENSION_ID<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param subject Mail subject<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param messageBody Mail body (can include HTML)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param toRecipients To: recipients in format: &quot;mail@example.com,mail2@example.com&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param ccRecipients Cc: recipients in format: &quot;mail@example.com,mail2@example.com&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param bccRecipients Bcc: recipients in format: &quot;mail@example.com,mail2@example.com&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @param attachmentsData Attachments in format: ['filename|bundle|mimetype|name of file to display in attachment']<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* example: [&quot;Default.png|bundle|image/png|Application splash screen.png&quot;,&quot;Example file.dat|documents|text/xml|A file saved in Adobe AIR iOS app.txt&quot;]<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> sendMail<span style="color: #000000;">&#40;</span>subject<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> messageBody<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> toRecipients<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ccRecipients<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">''</span><span style="color: #000066; font-weight: bold;">,</span> bccRecipients<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">''</span><span style="color: #000066; font-weight: bold;">,</span> attachmentsData<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; extensionContext<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">StatusEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">STATUS</span><span style="color: #000066; font-weight: bold;">,</span> onStatusEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; extensionContext<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;sendMailWithOptions&quot;</span><span style="color: #000066; font-weight: bold;">,</span> subject<span style="color: #000066; font-weight: bold;">,</span> messageBody<span style="color: #000066; font-weight: bold;">,</span> toRecipients<span style="color: #000066; font-weight: bold;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ccRecipients<span style="color: #000066; font-weight: bold;">,</span> bccRecipients<span style="color: #000066; font-weight: bold;">,</span> attachmentsData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* @private<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Handle mail compose result. <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* When the native mail composer finished an result event will be dispatched.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Event will contain the result information.<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span> &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onStatusEvent<span style="color: #000000;">&#40;</span> event <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">StatusEvent</span> <span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">code</span> == MailExtensionEvent<span style="color: #000066; font-weight: bold;">.</span>MAIL_COMPOSER_EVENT<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> MailExtensionEvent<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">code</span><span style="color: #000066; font-weight: bold;">,</span> event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">level</span> <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Can the in-app mail composer be invoked?<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span> &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> isMailComposerAvailable<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">Boolean</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> extensionContext<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">call</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;isMailComposerAvailable&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Boolean</span><span style="color: #000066; font-weight: bold;">;</span>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/**<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;* Clean up<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; extensionContext<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">StatusEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">STATUS</span><span style="color: #000066; font-weight: bold;">,</span> onStatusEvent <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; extensionContext<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>ANT script used for creating .ane and .swc files:</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;NativeMail iOS for Adobe AIR Extension&quot;</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;build-extension&quot;</span> <span style="color: #000066;">basedir</span>=<span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;local.properties&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;build.properties&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;clean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${app.builddir}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${app.releasedir}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${app.builddir}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${app.releasedir}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${app.rootdir}/library.swf&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${app.rootdir}/${app.swcfilename}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;build-extension&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;clean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exec</span> <span style="color: #000066;">executable</span>=<span style="color: #ff0000;">&quot;${ACOMPC}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -output ${app.builddir}/${app.swcfilename}</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -load-config+=${app.configfile}</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +configname=airmobile</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -swf-version=14</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exec<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;copy</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${app.builddir}/${app.swcfilename}&quot;</span> <span style="color: #000066;">tofile</span>=<span style="color: #ff0000;">&quot;${app.rootdir}/${app.swcfilename}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;unzip</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;${app.builddir}/${app.swcfilename}&quot;</span> <span style="color: #000066;">dest</span>=<span style="color: #ff0000;">&quot;${app.rootdir}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${app.rootdir}/catalog.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exec</span> <span style="color: #000066;">executable</span>=<span style="color: #ff0000;">&quot;${ADT}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -package -target ane ${app.releasedir}/iOS_MailExtension.ane ${app.extensionxmlfile} </span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -swc ${app.swcfilename}</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -platform iPhone-ARM library.swf libMailExtension.a</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -platformoptions ios-platformoptions.xml</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exec<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${app.rootdir}/library.swf&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${app.rootdir}/${app.swcfilename}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<p><strong>Native extensions ADT parameters</strong></p>
<p>One of the most important parameter in this script is  -platformoptions ios-platformoptions.xml . Why?<br />
My extension uses iOS frameworks that are not linked by ADT packager by default, as a result the linker won&#8217;t fine MFMailComposeViewController definition and will fail.<br />
Sadly, the documentation is very poor and I haven&#8217;t found any examples except from this one <a href="http://blogs.adobe.com/rajorshi/2011/11/16/ios5-support-for-airusing-external-sdks-to-package-apps/" title="iOS5 support for AIR/Using external SDKs to package apps" target="_blank">Adobe Blogs: iOS5 support for AIR/Using external SDKs to package apps</a></p>
<p>MFMailComposeViewController requires MessageUI.framework so adding it to ADT&#8217;s linker solves the problem.</p>
<p>Also, note that -swf-version is set to 14 because we&#8217;re targeting for AIR 3.1. See: <a href="http://help.adobe.com/en_US/air/extensions/WS99209310cacd98cc2d13931c1300f2c84c7-8000.html" title="Building the ActionScript library of a native extension" target="_blank">Adobe Docs: Building the ActionScript library of a native extension</a></p>
<p>ios-platformoptions.xml looks like this:</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;platform</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://ns.adobe.com/air/extension/3.1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sdkVersion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>5.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sdkVersion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;linkerOptions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!-- to use the MessageUI framework --&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>-framework MessageUI<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/option<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/linkerOptions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/platform<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<p>Another new parameter is extensions.xml file. It holds information about native libraries we want to include. Here we define the id of extension and the names of extension&#8217;s initializer and finalizer methods. See that the names of functions in &lt;initializer&gt; and finalizer match the names of functions in MailExtension.m</p>
<p>Here&#8217;s extension.xml</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;extension</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://ns.adobe.com/air/extension/3.1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>pl.randori.air.nativeextensions.ios.MailExtension<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;versionNumber<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.0.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/versionNumber<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;platforms<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;platform</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;iPhone-ARM&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;applicationDeployment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;nativeLibrary<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>libMailExtension.a<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/nativeLibrary<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;initializer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ExtInitializer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/initializer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;finalizer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ExtFinalizer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/finalizer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/applicationDeployment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/platform<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/platforms<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/extension<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<p>After running ANT script we will have two new files: NativeMail_iOS.swc in &#8216;build&#8217; directory and iOS_MailExtension.ane in &#8216;release&#8217; directory.<br />
iOS_MailExtension.ane is the AIR native extension we wanted to create.</p>
<p>&nbsp;</p>
<h2>Example &#8211; using native extension in Adobe AIR application</h2>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2011/12/air_native_extension_example_app-1.png"><img class="aligncenter size-full wp-image-306" title="air_native_extension_example_app-1" src="http://flashsimulations.com/wp-content/uploads/2011/12/air_native_extension_example_app-1.png" alt="" width="318" height="482" /></a></p>
<p>&nbsp;</p>
<p>&#8216;Can I send mail?&#8217; button calls MailExtension.isMailComposerAvailable() method which returns true / false.<br />
This method will return false if iOS mail client hasn&#8217;t been properly configured. This check is also done before sending the mail to prevent the app from crashing.</p>
<p>&#8216;Send mail&#8217; button calls MailExtension.sendMail method. In the example all available mail fields are filled and two attachments are added.</p>
<p>&nbsp;</p>
<p>Invoked mail composer view</p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2011/12/air-ios-in-app-mail-app.png"><img class="aligncenter size-full wp-image-312" title="air-ios-in-app-mail-app" src="http://flashsimulations.com/wp-content/uploads/2011/12/air-ios-in-app-mail-app.png" alt="" width="321" height="483" /></a></p>
<p>&nbsp;</p>
<p>Example app project structure:</p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2011/12/air-example-app-project-structure.png"><img class="aligncenter size-full wp-image-315" title="air-example-app-project-structure" src="http://flashsimulations.com/wp-content/uploads/2011/12/air-example-app-project-structure.png" alt="" width="255" height="375" /></a></p>
<p>Copy &#8216;iOS_MailExtension.ane&#8217; file to &#8216;extensions&#8217; directory.</p>
<p>&nbsp;<br />
One last thing left to is to add the following information you you application descriptor file. extensionID has to match our extension&#8217;s id. Otherwise ADT will fail to package the app.</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;extensions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;extensionID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>pl.randori.air.nativeextensions.ios.MailExtension<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/extensionID<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/extensions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<p>Packaging application is done by following ANT script:</p>
<div class="codecolorer-container xml default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;height:600px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;project</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;NativeMail iOS extension for Adobe AIR example app&quot;</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">&quot;publish-ios&quot;</span> <span style="color: #000066;">basedir</span>=<span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;local.properties&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;build.properties&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;clean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${app.builddir}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;delete</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${app.releasedir}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${app.builddir}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mkdir</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${app.releasedir}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;copy&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;clean&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;copy</span> <span style="color: #000066;">todir</span>=<span style="color: #ff0000;">&quot;${app.builddir}&quot;</span> <span style="color: #000066;">preservelastmodified</span>=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #000066;">verbose</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${app.sourcedir}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;patternset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;assets/**&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;*.png&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;*.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;*.ane&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/patternset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;compile&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;copy&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exec</span> <span style="color: #000066;">executable</span>=<span style="color: #ff0000;">&quot;${MXMLC}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +configname=airmobile </span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -output ${app.builddir}/${build.swfname}</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ${app.sourcedir}/NativeMail.mxml </span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -source-path+=${app.rootdir}/src</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -load-config+=NativeMail_app.config</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -swf-version=14</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exec<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;publish-ios&quot;</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">&quot;compile&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;copy</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${app.builddir}/${build.swfname}&quot;</span> <span style="color: #000066;">tofile</span>=<span style="color: #ff0000;">&quot;${app.rootdir}/${build.swfname}&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;copy</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${app.sourcedir}/NativeMail-app.xml&quot;</span> <span style="color: #000066;">tofile</span>=<span style="color: #ff0000;">&quot;${app.rootdir}/NativeMail-app.xml&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exec</span> <span style="color: #000066;">executable</span>=<span style="color: #ff0000;">&quot;${ADT}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;arg</span> <span style="color: #000066;">line</span>=<span style="color: #ff0000;">&quot;-package</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -target ipa-test-interpreter</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -provisioning-profile ${build.mobileprofile}</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -storetype ${build.storetype}</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -keystore ${build.keystore}</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -storepass YOUR_PASSWORD</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ${app.releasedir}/${build.name}</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ${app.descriptor}</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ${build.swfname}</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -extdir extensions</span><br />
<span style="color: #009900;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -C ${app.builddir} Default.png Default@2x.png&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/exec<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<p>Notice &#8216;-swf-version=14&#8242; and &#8216;-extdir extensions&#8217; parameters</p>
<p>That&#8217;s it.</p>
<p>Worth reading:<br />
<a href="http://blogs.adobe.com/rajorshi/2011/11/16/ios5-support-for-airusing-external-sdks-to-package-apps/" title="iOS5 support for AIR/Using external SDKs to package apps" target="_blank">Adobe Blogs: iOS5 support for AIR/Using external SDKs to package apps</a><br />
<a href="http://developer.apple.com/library/ios/#documentation/MessageUI/Reference/MFMailComposeViewController_class/Reference/Reference.html" title="MFMailComposeViewController Class Reference" target="_blank">MFMailComposeViewController Class Reference</a><br />
<a href="http://help.adobe.com/en_US/air/extensions/WS99209310cacd98cc2d13931c1300f2c84c7-8000.html" title="Building the ActionScript library of a native extension" target="_blank">Adobe Docs: Building the ActionScript library of a native extension</a><br />
<a href="http://www.liquid-photo.com/2011/10/28/native-extension-for-adobe-air-and-ios-101/" title="Native Alert iOS native extension tutorial" target="_blank">Native Alert iOS native extension tutorial</a><br />
<a href="http://custardbelly.com/blog/2011/09/21/air-native-extension-example-ibattery-for-ios/" title="AIR Native Extension Example: iBattery for iOS" target="_blank">AIR Native Extension Example: iBattery for iOS</a><br />
<a href="http://www.riaspace.com/2011/09/as3c2dm-air-native-extension-to-push-notifications-with-c2dm/" title="as3c2dm – AIR native extension to push notifications with C2DM" target="_blank">as3c2dm – AIR native extension to push notifications with C2DM</a></p>
<div class="shr-publisher-252"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F11%2F30%2Fios-native-extension-for-adobe-air-in-app-mail-composer%2F' data-shr_title='iOS+native+extension+for+Adobe+AIR.+In-app+mail+composer'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F11%2F30%2Fios-native-extension-for-adobe-air-in-app-mail-composer%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F11%2F30%2Fios-native-extension-for-adobe-air-in-app-mail-composer%2F' data-shr_title='iOS+native+extension+for+Adobe+AIR.+In-app+mail+composer'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F11%2F30%2Fios-native-extension-for-adobe-air-in-app-mail-composer%2F' data-shr_title='iOS+native+extension+for+Adobe+AIR.+In-app+mail+composer'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://flashsimulations.com/2011/11/30/ios-native-extension-for-adobe-air-in-app-mail-composer/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>SupAIR Pong &#8211; Adobe AIR 2.6 for iOS in action</title>
		<link>http://flashsimulations.com/2011/04/25/supair-pong-testing-adobe-air-2-6-for-mobile-devices/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=supair-pong-testing-adobe-air-2-6-for-mobile-devices</link>
		<comments>http://flashsimulations.com/2011/04/25/supair-pong-testing-adobe-air-2-6-for-mobile-devices/#comments</comments>
		<pubDate>Mon, 25 Apr 2011 21:18:22 +0000</pubDate>
		<dc:creator>Piotr Koscierzynski</dc:creator>
				<category><![CDATA[adobe air]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[adobe air 2.6]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[ipad]]></category>

		<guid isPermaLink="false">http://flashsimulations.com/?p=237</guid>
		<description><![CDATA[When newest version of Adobe AIR came out I needed to give it a try, of course. It has been a while since I&#8217;ve done some coding in AIR, beacause for the last few months I focused on developing native &#8230; <a href="http://flashsimulations.com/2011/04/25/supair-pong-testing-adobe-air-2-6-for-mobile-devices/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F04%2F25%2Fsupair-pong-testing-adobe-air-2-6-for-mobile-devices%2F' data-shr_title='SupAIR+Pong+-+Adobe+AIR+2.6+for+iOS+in+action'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F04%2F25%2Fsupair-pong-testing-adobe-air-2-6-for-mobile-devices%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F04%2F25%2Fsupair-pong-testing-adobe-air-2-6-for-mobile-devices%2F' data-shr_title='SupAIR+Pong+-+Adobe+AIR+2.6+for+iOS+in+action'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F04%2F25%2Fsupair-pong-testing-adobe-air-2-6-for-mobile-devices%2F' data-shr_title='SupAIR+Pong+-+Adobe+AIR+2.6+for+iOS+in+action'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><div id="attachment_245" class="wp-caption aligncenter" style="width: 330px"><a href="http://flashsimulations.com/wp-content/uploads/2011/04/IMG_0077.png"><img class="size-full wp-image-245" title="SupAIR Pong icon on iPhone 3Gs Home Screen" src="http://flashsimulations.com/wp-content/uploads/2011/04/IMG_0077.png" alt="" width="320" height="480" /></a><p class="wp-caption-text">SupAIR Pong&#39;s icon</p></div>
<p><a href="http://flashsimulations.com/2011/04/25/supair-pong-testing-adobe-air-2-6-for-mobile-devices/"><em>Click here to view the embedded video.</em></a></p>
<div id="attachment_240" class="wp-caption aligncenter" style="width: 490px"><a href="http://flashsimulations.com/wp-content/uploads/2011/04/IMG_0081.png"><img class="size-full wp-image-240" title="SupAIR Pong splash screen" src="http://flashsimulations.com/wp-content/uploads/2011/04/IMG_0081.png" alt="SupAIR Pong splash screen" width="480" height="320" /></a><p class="wp-caption-text">SupAIR Pong splash screen</p></div>
<div id="attachment_241" class="wp-caption aligncenter" style="width: 490px"><a href="http://flashsimulations.com/wp-content/uploads/2011/04/IMG_0079.png"><img class="size-full wp-image-241" title="SupAIR Pong - the game" src="http://flashsimulations.com/wp-content/uploads/2011/04/IMG_0079.png" alt="" width="480" height="320" /></a><p class="wp-caption-text">I can&#39;t play pong</p></div>
<p style="text-align: center;">
<p style="text-align: left;">When newest version of Adobe AIR came out I needed to give it a try, of course.<br />
It has been a while since I&#8217;ve done some coding in AIR, beacause for the last few months I focused on developing native iOS applications (Objective-C, C++, Xcode) and wrote only a small AIR app for BlackBerry PlayBook to check out the tools and workflow (sadly, it&#8217;s not developer-friendly).</p>
<p style="text-align: left;">Adobe AIR 2.6 doesn&#8217;t user PFI (Packager for iPhone) anymone, now it&#8217;s using the same tool for generating mobile iOS and Android applications. Also, iPhone 2G and 3G are no longer supported, due to &#8220;<em>armv7&#8243;</em> and &#8220;<em>opengles-2&#8243;</em> requirements for the target runtime (<span style="font-family: Consolas, Monaco, 'Courier New', Courier, monospace; line-height: 18px; white-space: pre;">UIRequiredDeviceCapabilities)</span>.</p>
<p style="text-align: left;">The packaging process is faster than with PFI / AIR 2.5 (AIR 2.6: 45-50 seconds, AIR 2.5: 2-4 minutes).  My pong clone runs smoothly on iPhone 3Gs 30fps and it&#8217;s a highly addictive game. The AIR 2.6 apps support iOS 4 features like multitasking, so you can save and resume your applications&#8217; state.  The game has a super-feature: you can change the colors (see the video).</p>
<p style="text-align: left;">SupAIR Pong will be available  on the App Store soon (if it gets accepted <img src='http://flashsimulations.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>AIR 2.6 mobile workflow is way better than AIR for BlackBerry PlayBook (BBP), because you can test your app in the simulator and with BBP Tablet it&#8217;s not that easy</p>
<ul>
<li>you need VM Ware to run the BBP simulator (30day trial then you need to buy it) / standard adt simulator doesn&#8217;t have required APIs (QNX) will crash with most apps</li>
<li>the BBP simulator doesn&#8217;t support orientation change / you need to use your imagination to test portrait mode</li>
<li>the BBP simulator doesn&#8217;t support cameras /  you need to use your imagination and then pray for the code to work</li>
<li>you need to use command line quite often &#8211; it&#8217;s not possible to remove an application from the simulator in any other way</li>
<li>QNX components are really ugly &#8211; check out the green preloader icon. Skinning them is a slow and tedious task. QNX components use Tweener internally (strange choice, since TweenMax/TweenLite is a lot faster)</li>
</ul>
<p style="text-align: left;">
<p style="text-align: left;">Few things to remember:</p>
<ol>
<li>You cannot use &lt;img&gt; tag inside TextField&#8217;s htmlText property due to Adobe AIR&#8217;s security policy</li>
<li>Use cacheAsBitmap on static textfields (boosts performance)</li>
<li>doubleClickEnabled property doesn&#8217;t work, user flash.utils.getTimer instead (the same thing happens on BlackBerry PlayBook)</li>
<li>When embedding fonts set embedAsCFF=&#8221;false&#8221; (when using font with AS3 TextFields)</li>
<li>stage.stageWidth and stage.stageHeight properties contain wrong screen dimensions. On my iPhone 3Gs (480&#215;320 fullscreen) and in the simulator the size was 500&#215;375. (a bug ? ). Wasted some time wondering why graphics aren&#8217;t positioned correctly.</li>
<li>Clicks on html links inside TextFields are working really bad on the device (3Gs), it was very hard to get a TextEvent.LINK event to fire. In the simulator everything&#8217;s fine. Had to change this approach to oridinary Sprites to act as buttons.</li>
</ol>
<div class="shr-publisher-237"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F04%2F25%2Fsupair-pong-testing-adobe-air-2-6-for-mobile-devices%2F' data-shr_title='SupAIR+Pong+-+Adobe+AIR+2.6+for+iOS+in+action'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F04%2F25%2Fsupair-pong-testing-adobe-air-2-6-for-mobile-devices%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F04%2F25%2Fsupair-pong-testing-adobe-air-2-6-for-mobile-devices%2F' data-shr_title='SupAIR+Pong+-+Adobe+AIR+2.6+for+iOS+in+action'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2011%2F04%2F25%2Fsupair-pong-testing-adobe-air-2-6-for-mobile-devices%2F' data-shr_title='SupAIR+Pong+-+Adobe+AIR+2.6+for+iOS+in+action'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://flashsimulations.com/2011/04/25/supair-pong-testing-adobe-air-2-6-for-mobile-devices/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Preview versions of mobile Flex &quot;Hero&quot; and Flash Builder &quot;Burrito&quot; released</title>
		<link>http://flashsimulations.com/2010/10/25/preview-versions-of-mobile-flex-hero-and-flash-builder-burrito-released/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=preview-versions-of-mobile-flex-hero-and-flash-builder-burrito-released</link>
		<comments>http://flashsimulations.com/2010/10/25/preview-versions-of-mobile-flex-hero-and-flash-builder-burrito-released/#comments</comments>
		<pubDate>Mon, 25 Oct 2010 19:08:38 +0000</pubDate>
		<dc:creator>Piotr Koscierzynski</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[air 2.5]]></category>
		<category><![CDATA[burrito]]></category>
		<category><![CDATA[hero]]></category>

		<guid isPermaLink="false">http://flashsimulations.com/?p=228</guid>
		<description><![CDATA[Today Adobe released preview version of Flex &#8216;Hero&#8217; optimized for mobile devices and a preview version of next version of Flash Builder &#8211; codenamed &#8216;Burrito&#8217;. &#8216;Burrito&#8217; comes with mobile Flex SDK and Air 2.5 SDK &#8211; the IDE has many &#8230; <a href="http://flashsimulations.com/2010/10/25/preview-versions-of-mobile-flex-hero-and-flash-builder-burrito-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F25%2Fpreview-versions-of-mobile-flex-hero-and-flash-builder-burrito-released%2F' data-shr_title='Preview+versions+of+mobile+Flex+%26quot%3BHero%26quot%3B+and+Flash+Builder+%26quot%3BBurrito%26quot%3B+released'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F25%2Fpreview-versions-of-mobile-flex-hero-and-flash-builder-burrito-released%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F25%2Fpreview-versions-of-mobile-flex-hero-and-flash-builder-burrito-released%2F' data-shr_title='Preview+versions+of+mobile+Flex+%26quot%3BHero%26quot%3B+and+Flash+Builder+%26quot%3BBurrito%26quot%3B+released'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F25%2Fpreview-versions-of-mobile-flex-hero-and-flash-builder-burrito-released%2F' data-shr_title='Preview+versions+of+mobile+Flex+%26quot%3BHero%26quot%3B+and+Flash+Builder+%26quot%3BBurrito%26quot%3B+released'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Today Adobe released preview version of Flex &#8216;Hero&#8217; optimized for mobile devices and a preview version of next version of Flash Builder &#8211; codenamed &#8216;Burrito&#8217;.</p>
<p>&#8216;Burrito&#8217; comes with mobile Flex SDK and Air 2.5 SDK &#8211; the IDE has many interesting features that will make development for multiple platforms and different screen sizes much easier.<br />
It&#8217;s the first release of Air 2.5, so anyone who didn&#8217;t apply to Air Prelease can now start creating mobile applications for Android.</p>
<p>Spark family of components have been optimized for mobile devices (i.e. &#8211; all of the skins have been coded in ActionScript, the components can now respond to touch screens events ).<br />
The list of changes and new features is pretty impressive, so check them out Adobe Flash Builder &#8220;Burrito&#8221;</p>
<div class="shr-publisher-228"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F25%2Fpreview-versions-of-mobile-flex-hero-and-flash-builder-burrito-released%2F' data-shr_title='Preview+versions+of+mobile+Flex+%26quot%3BHero%26quot%3B+and+Flash+Builder+%26quot%3BBurrito%26quot%3B+released'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F25%2Fpreview-versions-of-mobile-flex-hero-and-flash-builder-burrito-released%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F25%2Fpreview-versions-of-mobile-flex-hero-and-flash-builder-burrito-released%2F' data-shr_title='Preview+versions+of+mobile+Flex+%26quot%3BHero%26quot%3B+and+Flash+Builder+%26quot%3BBurrito%26quot%3B+released'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F25%2Fpreview-versions-of-mobile-flex-hero-and-flash-builder-burrito-released%2F' data-shr_title='Preview+versions+of+mobile+Flex+%26quot%3BHero%26quot%3B+and+Flash+Builder+%26quot%3BBurrito%26quot%3B+released'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://flashsimulations.com/2010/10/25/preview-versions-of-mobile-flex-hero-and-flash-builder-burrito-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to create iOS applications with Adobe AIR</title>
		<link>http://flashsimulations.com/2010/10/25/how-to-create-ios-applications-with-adobe-air/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-create-ios-applications-with-adobe-air</link>
		<comments>http://flashsimulations.com/2010/10/25/how-to-create-ios-applications-with-adobe-air/#comments</comments>
		<pubDate>Sun, 24 Oct 2010 23:43:46 +0000</pubDate>
		<dc:creator>Piotr Koscierzynski</dc:creator>
				<category><![CDATA[adobe air]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[air 2.0]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://flashsimulations.com/?p=200</guid>
		<description><![CDATA[
 <a href="http://flashsimulations.com/2010/10/25/how-to-create-ios-applications-with-adobe-air/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F25%2Fhow-to-create-ios-applications-with-adobe-air%2F' data-shr_title='How+to+create+iOS+applications+with+Adobe+AIR'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F25%2Fhow-to-create-ios-applications-with-adobe-air%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F25%2Fhow-to-create-ios-applications-with-adobe-air%2F' data-shr_title='How+to+create+iOS+applications+with+Adobe+AIR'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F25%2Fhow-to-create-ios-applications-with-adobe-air%2F' data-shr_title='How+to+create+iOS+applications+with+Adobe+AIR'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p>On 9th September<a title="Statement by Apple on App Store Review Guidelines" href="http://www.apple.com/pr/library/2010/09/09statement.html" target="_blank"> Apple revoked the restrictions</a> for technologies that are allowed to be used for creating iPhoneOs (iOS) applications. This means that you can use Flash, Unity3D, Titanium Developer or any other tools to make an mobile application for Apple devices.<br />
As a result of this decision Adobe will resume work on <a href="http://labs.adobe.com/technologies/packagerforiphone/">Packager for iPhone</a> which has been on hold since April this year (as a result of sections 3  of iOS Developer Program license).</p>
<p>Latest version of the packager has been released on 11th October, so let&#8217;s give it a try.<br />
This approach for developing iPhone / iPad / iPod applications is a great way to reuse you ActionScript code but there are some Flash features that are not available or are known not to work properly &#8211; see <a href="http://labs.adobe.com/wiki/index.php/Packager_for_iPhone:Release_Notes#Known_Issues_in_the_Packager_for_iPhone">&#8216;Known Issues&#8217; section</a> and <a href="http://download.macromedia.com/pub/labs/packagerforiphone/packagerforiphone_devguide.pdf">&#8216;Packager for iPhone developer guide&#8217;</a> on Adobe Labs to be aware of those limitations.</p>
<p>There are two ways of creating native iOS applications with Adobe Flash platform:</p>
<ul>
<li> using Adobe Flash CS5</li>
<li> using Packager for iPhone from the command line</li>
</ul>
<p><strong>Create iPhone / iPod / iPad application &#8211; step by step</strong></p>
<p>1. Download &#8216;Packager for iPhone&#8217; (PFI). Flex SDK is also required.</p>
<p>2. PFI requires 32-bit Java runtime environment, be sure to have it installed.</p>
<p>3. Create and Adobe Air project using ActionScript, not MXML.</p>
<p>In FlashDevelop create  &#8216;AIR AS3 Projector&#8217; project.<br />
In Flash Builder create &#8216;Flex Project&#8217;, but set the main application extension to &#8216;.as&#8217;.</p>
<p>4. Modify the Adobe Air application descriptor xml.</p>
<p>It should look something like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span> <span style="color: #000066; font-weight: bold;">?&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;</span>application xmlns=<span style="color: #990000;">&quot;http://ns.adobe.com/air/application/2.0&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;</span>id<span style="color: #000066; font-weight: bold;">&gt;</span>com<span style="color: #000066; font-weight: bold;">.</span>flashsimulations<span style="color: #000066; font-weight: bold;">.</span>mobile<span style="color: #000066; font-weight: bold;">.</span>ios<span style="color: #000066; font-weight: bold;">.</span>Hello<span style="color: #000066; font-weight: bold;">&lt;/</span>id<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>version<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">1.0</span><span style="color: #000066; font-weight: bold;">&lt;/</span>version<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>filename<span style="color: #000066; font-weight: bold;">&gt;</span>HelloIOS<span style="color: #000066; font-weight: bold;">&lt;/</span>filename<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>name<span style="color: #000066; font-weight: bold;">&gt;</span>Hello iOS<span style="color: #000066; font-weight: bold;">&lt;/</span>name<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>description<span style="color: #000066; font-weight: bold;">&gt;</span>Just a test<span style="color: #000066; font-weight: bold;">&lt;/</span>description<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>copyright<span style="color: #000066; font-weight: bold;">&gt;</span>Piotr Koscierzynski<span style="color: #000066; font-weight: bold;">&lt;/</span>copyright<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;</span>initialWindow<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>title<span style="color: #000066; font-weight: bold;">&gt;</span>Hello iOS<span style="color: #000066; font-weight: bold;">&lt;/</span>title<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>content<span style="color: #000066; font-weight: bold;">&gt;</span>HelloIOS<span style="color: #000066; font-weight: bold;">.</span>swf<span style="color: #000066; font-weight: bold;">&lt;/</span>content<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>systemChrome<span style="color: #000066; font-weight: bold;">&gt;</span>standard<span style="color: #000066; font-weight: bold;">&lt;/</span>systemChrome<span style="color: #000066; font-weight: bold;">&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;</span>transparent<span style="color: #000066; font-weight: bold;">&gt;</span>false<span style="color: #000066; font-weight: bold;">&lt;/</span>transparent<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>visible<span style="color: #000066; font-weight: bold;">&gt;</span>true<span style="color: #000066; font-weight: bold;">&lt;/</span>visible<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>minimizable<span style="color: #000066; font-weight: bold;">&gt;</span>true<span style="color: #000066; font-weight: bold;">&lt;/</span>minimizable<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>autoOrients<span style="color: #000066; font-weight: bold;">&gt;</span>true<span style="color: #000066; font-weight: bold;">&lt;/</span>autoOrients<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>resizable<span style="color: #000066; font-weight: bold;">&gt;</span>true<span style="color: #000066; font-weight: bold;">&lt;/</span>resizable<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>renderMode<span style="color: #000066; font-weight: bold;">&gt;</span>gpu<span style="color: #000066; font-weight: bold;">&lt;/</span>renderMode<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>fullScreen<span style="color: #000066; font-weight: bold;">&gt;</span>true<span style="color: #000066; font-weight: bold;">&lt;/</span>fullScreen<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>aspectRatio<span style="color: #000066; font-weight: bold;">&gt;</span>portrait<span style="color: #000066; font-weight: bold;">&lt;/</span>aspectRatio<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;/</span>initialWindow<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;</span>supportedProfiles<span style="color: #000066; font-weight: bold;">&gt;</span>mobileDevice desktop<span style="color: #000066; font-weight: bold;">&lt;/</span>supportedProfiles<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;</span>iPhone<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>infoAdditions<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span>
			<span style="color: #000066; font-weight: bold;">&lt;</span>key<span style="color: #000066; font-weight: bold;">&gt;</span>UIStatusBarStyle<span style="color: #000066; font-weight: bold;">&lt;/</span>key<span style="color: #000066; font-weight: bold;">&gt;</span>
			<span style="color: #000066; font-weight: bold;">&lt;</span>string<span style="color: #000066; font-weight: bold;">&gt;</span>UIStatusBarStyleBlackOpaque<span style="color: #000066; font-weight: bold;">&lt;/</span>string<span style="color: #000066; font-weight: bold;">&gt;</span>
			<span style="color: #000066; font-weight: bold;">&lt;</span>key<span style="color: #000066; font-weight: bold;">&gt;</span>UIRequiresPersistentWiFi<span style="color: #000066; font-weight: bold;">&lt;/</span>key<span style="color: #000066; font-weight: bold;">&gt;</span>
			<span style="color: #000066; font-weight: bold;">&lt;</span>string<span style="color: #000066; font-weight: bold;">&gt;</span>NO<span style="color: #000066; font-weight: bold;">&lt;/</span>string<span style="color: #000066; font-weight: bold;">&gt;</span>
			<span style="color: #000066; font-weight: bold;">&lt;</span>key<span style="color: #000066; font-weight: bold;">&gt;</span>UIDeviceFamily<span style="color: #000066; font-weight: bold;">&lt;/</span>key<span style="color: #000066; font-weight: bold;">&gt;</span>
			<span style="color: #000066; font-weight: bold;">&lt;</span>array<span style="color: #000066; font-weight: bold;">&gt;</span>
			<span style="color: #000066; font-weight: bold;">&lt;</span>string<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">&lt;/</span>string<span style="color: #000066; font-weight: bold;">&gt;</span>
			<span style="color: #000066; font-weight: bold;">&lt;</span>string<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000066; font-weight: bold;">&lt;/</span>string<span style="color: #000066; font-weight: bold;">&gt;</span>
			<span style="color: #000066; font-weight: bold;">&lt;/</span>array<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;/</span>infoAdditions<span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;/</span>iPhone<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">&lt;/</span>application<span style="color: #000066; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>The descriptor is almost the same as the one for Android apps, but there are some differences</p>
<ul>
<li> iOS apps must use Air 2.0 (line 1), Android uses Air 2.5</li>
<li>iOS apps use &lt;version&gt; not &lt;versionNumber&gt; for specifying version of application. But value should be in the same format &#8211; numbers only XX.XX.XX or XX.XX</li>
<li> the information for operating system is defined between &lt;iPhone&gt; tag. This may look new, but those parameters are the same that can be found in Info.plist file when developing iOS apps in XCode. For full list of available options visit <a href="http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW1">Information Property List Key Reference for UIKit</a> e.g. UIDeviceFamily defines on which devices the application can run &#8211; 1 is for iPhone / iPod, 2 is for iPad.</li>
</ul>
<p>5. Register in iPhone Developer Program. Get a certificate and provisioning profile from Apple ($99-$300 per year). You also need to convert the<br />
certificate into a P12 certificate. See the &#8220;Obtaining developer files from Apple&#8221; section, page 4 of <a href="http://download.macromedia.com/pub/labs/packagerforiphone/packagerforiphone_devguide.pdf">&#8216;Packager for iPhone developer guide&#8217;</a>. This process could take few days or even a week (Apple needs to verify information you provided) and can be complicated.</p>
<p>There is a second &#8211; &#8216;non-Apple&#8217; &#8211; way. Well, you don&#8217;t really need to buy anything, but you won&#8217;t be able to submit your application to AppStore and you won&#8217;t be able to test on the &#8216;non-jailbroken&#8217; iOS device. All you have to do is to find a &#8216;special&#8217; certificate &#8216;.p12&#8242; and &#8216;.mobileprovision&#8217; files &#8211; Google will help you. Use those files to pack your application.</p>
<p>6. Configure and run the packaging batch &#8216;Package_iOS_Application.bat&#8217; (if on Windows) or run the packager from the command line using this syntax:<br />
pfi -package -target [ipa-test ipa-debug ipa-app-store ipa-ad-hoc] -provisioning-profile PROFILE_PATH SIGNING_OPTIONS TARGET_IPA_FILE APP_DESCRIPTOR SOURCE_FILES</p>
<p>7. Install you application on the device / submit to AppStore.</p>
<p><strong>Adobe Air into native iOS &#8211; How does it work<br />
</strong><br />
The packager creates an native iOS application &#8211; it&#8217;s not Adobe Air application, because Apple forbids Just-In-Time compilation on their devices &#8211; that means no ActionScript Virtual Machine available &#8211; you won&#8217;t be able to run ActionScript code from external .swf files. Packager uses the <a href="http://llvm.org/">LLVM compiler</a> to translate ActionScript into Objective-C bytecode, it&#8217;s the same technology that&#8217;s behind <a href="http://labs.adobe.com/technologies/alchemy/">Adobe Alchemy</a>.</p>
<p><strong>Example project</strong></p>
<p>This project is exactly the same as my &#8216;Hello World&#8217; example for Android. The project&#8217;s file structure looks like this</p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2010/10/Hello_iOS_structure.png"><img class="alignnone size-full wp-image-223" title="Hello iOS project structure" src="http://flashsimulations.com/wp-content/uploads/2010/10/Hello_iOS_structure.png" alt="Hello iOS project structure" width="206" height="245" /></a></p>
<p>Packaging batch file</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
</pre></td><td class="code"><pre class="batch" style="font-family:monospace;">@echo off
&nbsp;
:: iPhone application packaging script - based on FlashDevelop's AIR AS3 template.
:: Modified by Piotr Koscierzynski, flashsimulations.com
&nbsp;
:: Flex SDK path
set PATH=%PATH%;&quot;C:\Program Files (x86)\FlashDevelop\Tools\flexsdk\bin&quot;
&nbsp;
:: Directory containing 'Packager for iPhone', version released on 11th October 2010
set PFI_DIR=&quot;G:\piotr\SDK\packagerforiphone_v2_win_101110&quot;
&nbsp;
:: Packager for iPhone requires 32-bit Java runtime. The run parameters taken from PFI .bat file.
set JAVA_32BIT_RUNTIME_PATH=&quot;C:\Program Files (x86)\Java\jre6\bin\java&quot; -Xms256m -Xmx1024m
&nbsp;
:: You should use a valid certificate from Apple Developer Program.
:: You can also generate it by yourself - (see 'CreateCertificate.bat').
:: Certificate file path
set CERTIFICATE=pkoscierzynski.p12
&nbsp;
:: Provisioning Profile from Apple Developer Program, required.
set MOBILE_PROVISION_FILE=pkoscierzynski.mobileprovision
&nbsp;
:: Certificate and provisioning profile part
set SIGNING_OPTIONS=-provisioning-profile %MOBILE_PROVISION_FILE% -storetype pkcs12 -keystore %CERTIFICATE%
&nbsp;
if not exist %CERTIFICATE% goto certificate
&nbsp;
:: ---- Output ------------
if not exist ipa md ipa
&nbsp;
:: iPhone IPA file
set IPA_FILE=&quot;ipa/HelloIOS.ipa&quot;
:: IPA target type
set IPA_TARGET_TYPE=ipa-test
&nbsp;
:: --- Input -----------
:: Application descriptor
set APP_XML=&quot;Hello-iOS-app.xml&quot;
&nbsp;
:: Application main swf
set FILE_OR_DIR=-C bin HelloIOS.swf
&nbsp;
echo Packaging iPhone application using certificate %CERTIFICATE%
echo This process will take a few minutes. Please wait...
&nbsp;
:: Package command
call %JAVA_32BIT_RUNTIME_PATH% -jar %PFI_DIR%\lib\pfi.jar -package -target %IPA_TARGET_TYPE% %SIGNING_OPTIONS% %IPA_FILE% %APP_XML% %FILE_OR_DIR%
&nbsp;
if errorlevel 1 goto failed
&nbsp;
echo.
echo SUCCESS! iPhone IPA installer created: %IPA_FILE%
echo.
goto end
&nbsp;
:certificate
echo Certificate not found: %CERTIFICATE%
echo.
echo Troubleshotting:
echo A certificate is required, generate one using 'CreateCertificate.bat'
echo.
goto end
&nbsp;
:failed
echo iPhone packaging FAILED.
echo.
echo Troubleshotting:
echo Please check Flex SDK and PFI path in this Batch file.
echo.
&nbsp;
:end
pause</pre></td></tr></table></div>

<div class="shr-publisher-200"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F25%2Fhow-to-create-ios-applications-with-adobe-air%2F' data-shr_title='How+to+create+iOS+applications+with+Adobe+AIR'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F25%2Fhow-to-create-ios-applications-with-adobe-air%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F25%2Fhow-to-create-ios-applications-with-adobe-air%2F' data-shr_title='How+to+create+iOS+applications+with+Adobe+AIR'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F25%2Fhow-to-create-ios-applications-with-adobe-air%2F' data-shr_title='How+to+create+iOS+applications+with+Adobe+AIR'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://flashsimulations.com/2010/10/25/how-to-create-ios-applications-with-adobe-air/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Creating first app for Android using Adobe Air</title>
		<link>http://flashsimulations.com/2010/10/22/creating-first-app-for-android-using-adobe-air/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=creating-first-app-for-android-using-adobe-air</link>
		<comments>http://flashsimulations.com/2010/10/22/creating-first-app-for-android-using-adobe-air/#comments</comments>
		<pubDate>Thu, 21 Oct 2010 23:30:43 +0000</pubDate>
		<dc:creator>Piotr Koscierzynski</dc:creator>
				<category><![CDATA[adobe air]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[tutorials]]></category>

		<guid isPermaLink="false">http://flashsimulations.com/?p=172</guid>
		<description><![CDATA[To illustrate the workflow of developing Android apps in Adobe Air I created a very simple application that can react to screen orientation changes, gestures and touches &#8211; it&#8217;s written in ActionScript. The user interface consists of checkbox, label and &#8230; <a href="http://flashsimulations.com/2010/10/22/creating-first-app-for-android-using-adobe-air/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F22%2Fcreating-first-app-for-android-using-adobe-air%2F' data-shr_title='Creating+first+app+for+Android+using+Adobe+Air'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F22%2Fcreating-first-app-for-android-using-adobe-air%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F22%2Fcreating-first-app-for-android-using-adobe-air%2F' data-shr_title='Creating+first+app+for+Android+using+Adobe+Air'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F22%2Fcreating-first-app-for-android-using-adobe-air%2F' data-shr_title='Creating+first+app+for+Android+using+Adobe+Air'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p>To illustrate the workflow of developing Android apps in Adobe Air I created a very simple application that can react to screen orientation changes, gestures and touches &#8211; it&#8217;s written in ActionScript.</p>
<p>The user interface consists of checkbox, label and a button.<br />
If the user clicks the button or make a swipe gesture the background color will change to a random color.<br />
Checkbox enables the screen orientation &#8211; this is an interesting feature since we can decide whether or not to let the screen rotate.</p>
<p>I used a set of <a href="http://blog.kevinhoyt.org/?p=548">Android-like components</a> created by Kevin Hoyt, Adobe&#8217;s Platform Evengelist. They are very easy to use and mimic the Android look &amp; feel pretty good.</p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2010/10/hello_androair_screen.png"><img title="Hello Android Air screen" src="http://flashsimulations.com/wp-content/uploads/2010/10/hello_androair_screen.png" alt="Hello Android Air screen" width="630" /></a></p>
<p>The process is made of following steps</p>
<ul>
<li>create Flex Project</li>
<li>generate the certificate</li>
<li>package the Air application into an apk file</li>
<li>install the apk to device / emulator</li>
</ul>
<p>I assume that you have all the necessary dependencies already installed (Flex SDK with AIR 2.5 , Android SDK and an emulator /device), if not then check my previous post.</p>
<p><strong>Creating Flex Builder project</strong></p>
<p>1. Create a new Flex Project. Be sure to use Flex SDK merged with AIR 2.5 SDK.</p>
<p><img class="size-full wp-image-173 alignnone" title="Adobe Air app wizard - Flash Builder step 1" src="http://flashsimulations.com/wp-content/uploads/2010/10/android_air_flash_builder_01.png" alt="Adobe Air app wizard - Flash Builder step 1" width="594" height="677" /></p>
<p>In the second step change the main application file extention from &#8216;.mxml&#8217; to &#8220;.as&#8221;, since we won&#8217;t be using Flex framework, only ActionScript 3.</p>
<p>Using Flex for mobile applications is possible but the performance would suffer. Until <a href="http://labs.adobe.com/technologies/flex/mobile/">mobile version of Flex 4.5</a> isn&#8217;t released (should be available later this year) it&#8217;s better to stick to ActionScript only.</p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2010/10/android_air_flash_builder_02.png"><img class="size-full wp-image-174 alignnone" title="Adobe Air app wizard - Flash Builder step 2" src="http://flashsimulations.com/wp-content/uploads/2010/10/android_air_flash_builder_02.png" alt="Adobe Air app wizard - Flash Builder step 2" width="625" height="741" /></a></p>
<p><strong>Modify application&#8217;s descriptor xml</strong></p>
<p>Flash Builder has generated all the necessary files, there are only few thing to modify in the xml descriptor  - set the &lt;visible&gt; tag to &#8220;true&#8221; and specify Android manifest &#8211; if your application is going to use Android APIs (camera, wifi, file access, etc.). If you don&#8217;t specify the functionality you need, the application won&#8217;t work properly.</p>
<p>The application main class looks like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
</pre></td><td class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>greensock<span style="color: #000066; font-weight: bold;">.</span>TweenMax<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>greensock<span style="color: #000066; font-weight: bold;">.</span>easing<span style="color: #000066; font-weight: bold;">.</span>Cubic<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">StageAlign</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">StageScaleMode</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span>StageOrientationEvent<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span>TransformGestureEvent<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.geom</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Point</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLRequest</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">navigateToURL</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #3f5fbf;">/**
	 * Adobe AIR Android application example
	 *
	 * @author Piotr Koscierzynski, flashsimulations.com
	 *
	 * */</span>
	<span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">backgroundColor</span>=<span style="color: #990000;">'0xf8f8f8'</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">frameRate</span>=<span style="color: #990000;">'31'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> HelloAndroid <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #009966; font-style: italic;">/* Android style components by Kevin Hoyt */</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> superButton<span style="color: #000066; font-weight: bold;">:</span>Button<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> autoOrientCheckbox<span style="color: #000066; font-weight: bold;">:</span>CheckBox<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> footerLabel<span style="color: #000066; font-weight: bold;">:</span>Label<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #009900; font-style: italic;">//</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> uiCreated<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">labels</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span><span style="color: #990000;">'Click me!'</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;Welcome to Android world!&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">'Life is like a box of chocolates.'</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">'Have a nice day.'</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> counter<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> static const TWEEN_TIME<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0.6</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> tweenFunction<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Function</span> = com<span style="color: #000066; font-weight: bold;">.</span>greensock<span style="color: #000066; font-weight: bold;">.</span>easing<span style="color: #000066; font-weight: bold;">.</span>Cubic<span style="color: #000066; font-weight: bold;">.</span>easeInOut<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> backgroundSprite<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> HelloAndroid<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADDED_TO_STAGE</span><span style="color: #000066; font-weight: bold;">,</span> onAdded<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> final <span style="color: #339966; font-weight: bold;">function</span> onAdded<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
			<span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADDED_TO_STAGE</span><span style="color: #000066; font-weight: bold;">,</span> onAdded<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Stage resize handler.
		 * */</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> final <span style="color: #339966; font-weight: bold;">function</span> onResize<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">//no stage instance available</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span><span style="color: #004993;">stage</span><span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">//ui not instantiated</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>uiCreated<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">stageWidth</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageWidth</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">stageHeight</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">stageHeight</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">//background</span>
			backgroundSprite<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> = <span style="color: #004993;">stageWidth</span><span style="color: #000066; font-weight: bold;">;</span>
			backgroundSprite<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> = <span style="color: #004993;">stageHeight</span><span style="color: #000066; font-weight: bold;">;</span>
			backgroundSprite<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
			backgroundSprite<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
&nbsp;
&nbsp;
			<span style="color: #009900; font-style: italic;">//checkbox position</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> autoOrientCheckbox_x<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = autoOrientCheckbox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">30</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> autoOrientCheckbox_y<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> =  <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			TweenMax<span style="color: #000066; font-weight: bold;">.</span>killTweensOf<span style="color: #000000;">&#40;</span>autoOrientCheckbox<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			TweenMax<span style="color: #000066; font-weight: bold;">.</span>to<span style="color: #000000;">&#40;</span>autoOrientCheckbox<span style="color: #000066; font-weight: bold;">,</span> TWEEN_TIME<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000;">&#123;</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">:</span>autoOrientCheckbox_x<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">:</span> autoOrientCheckbox_y<span style="color: #000066; font-weight: bold;">,</span> ease<span style="color: #000066; font-weight: bold;">:</span>tweenFunction<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">//center the button</span>
			superButton<span style="color: #000066; font-weight: bold;">.</span>setWidth<span style="color: #000000;">&#40;</span><span style="color: #004993;">stageWidth</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">20</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> superButton_x<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000;">&#40;</span><span style="color: #004993;">stageWidth</span> <span style="color: #000066; font-weight: bold;">-</span> superButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> superButton_y<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000;">&#40;</span><span style="color: #004993;">stageHeight</span> <span style="color: #000066; font-weight: bold;">-</span> superButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			TweenMax<span style="color: #000066; font-weight: bold;">.</span>killTweensOf<span style="color: #000000;">&#40;</span>superButton<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			TweenMax<span style="color: #000066; font-weight: bold;">.</span>to<span style="color: #000000;">&#40;</span>superButton<span style="color: #000066; font-weight: bold;">,</span> TWEEN_TIME<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000;">&#123;</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">:</span>superButton_x<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">:</span> superButton_y<span style="color: #000066; font-weight: bold;">,</span> ease<span style="color: #000066; font-weight: bold;">:</span>tweenFunction<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #6699cc; font-weight: bold;">var</span> footerLabel_x<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000;">&#40;</span><span style="color: #004993;">stageWidth</span> <span style="color: #000066; font-weight: bold;">-</span> footerLabel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> footerLabel_y<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000;">&#40;</span><span style="color: #004993;">stageHeight</span> <span style="color: #000066; font-weight: bold;">-</span> footerLabel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			TweenMax<span style="color: #000066; font-weight: bold;">.</span>killTweensOf<span style="color: #000000;">&#40;</span>footerLabel<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			TweenMax<span style="color: #000066; font-weight: bold;">.</span>to<span style="color: #000000;">&#40;</span>footerLabel<span style="color: #000066; font-weight: bold;">,</span> TWEEN_TIME<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000;">&#123;</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">:</span>footerLabel_x<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">:</span> footerLabel_y<span style="color: #000066; font-weight: bold;">,</span> ease<span style="color: #000066; font-weight: bold;">:</span>tweenFunction<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * If the &lt;autoOrients&gt;true&lt;/autoOrients&gt; tag is set to true then the application will receive this event.
		 * We can block the screen rotation by calling e.preventDefault().
		 *
		 * */</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> final <span style="color: #339966; font-weight: bold;">function</span> onOrientationChanging<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span>StageOrientationEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">//prevent the screen from rotating</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>autoOrientCheckbox<span style="color: #000066; font-weight: bold;">.</span>selected == <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">preventDefault</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Init stage align and listeners.
		 *
		 * */</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> final <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
			buildUI<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">stage</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
				<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">align</span> = <span style="color: #004993;">StageAlign</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TOP_LEFT</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">scaleMode</span> = <span style="color: #004993;">StageScaleMode</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">NO_SCALE</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">RESIZE</span><span style="color: #000066; font-weight: bold;">,</span> onResize<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>StageOrientationEvent<span style="color: #000066; font-weight: bold;">.</span>ORIENTATION_CHANGING<span style="color: #000066; font-weight: bold;">,</span> onOrientationChanging<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
				<span style="color: #004993;">stage</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>TransformGestureEvent<span style="color: #000066; font-weight: bold;">.</span>GESTURE_SWIPE<span style="color: #000066; font-weight: bold;">,</span> onSwipe<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
			<span style="color: #009900; font-style: italic;">//set UI elements positions</span>
			onResize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Handle screen swipe - change the background of the screen.
		 *
		 * */</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> final <span style="color: #339966; font-weight: bold;">function</span> onSwipe<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span>TransformGestureEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
&nbsp;
				changeBgColor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #3f5fbf;">/**
		 * Build the user interface
		 * */</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> final <span style="color: #339966; font-weight: bold;">function</span> buildUI<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">//background</span>
			backgroundSprite = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			backgroundSprite<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0xFFFFFF<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			backgroundSprite<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			backgroundSprite<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			backgroundSprite<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">mouseChildren</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
			backgroundSprite<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">mouseEnabled</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addChildAt</span><span style="color: #000000;">&#40;</span>backgroundSprite<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">//button</span>
			superButton = <span style="color: #0033ff; font-weight: bold;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #004993;">labels</span><span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">300</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			superButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> handleButtonClick<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>superButton<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
&nbsp;
			<span style="color: #009900; font-style: italic;">//checkbox - auto orientation enabled</span>
			autoOrientCheckbox = <span style="color: #0033ff; font-weight: bold;">new</span> CheckBox<span style="color: #000000;">&#40;</span><span style="color: #990000;">'Auto orient screen'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			autoOrientCheckbox<span style="color: #000066; font-weight: bold;">.</span>selected = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>autoOrientCheckbox<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			<span style="color: #009900; font-style: italic;">//label for footer</span>
			footerLabel = <span style="color: #0033ff; font-weight: bold;">new</span> Label<span style="color: #000000;">&#40;</span><span style="color: #990000;">'flashsimulations.com'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			footerLabel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> handleFooterClick<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			footerLabel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">buttonMode</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
			footerLabel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">mouseChildren</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>footerLabel<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
			uiCreated = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> changeBgColor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
&nbsp;
&nbsp;
			TweenMax<span style="color: #000066; font-weight: bold;">.</span>to<span style="color: #000000;">&#40;</span>backgroundSprite<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0.4</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000;">&#123;</span>tint<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">random</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">*</span>0xFFFFFF<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> final <span style="color: #339966; font-weight: bold;">function</span> handleButtonClick<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			superButton<span style="color: #000066; font-weight: bold;">.</span>label = <span style="color: #004993;">labels</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">++</span>counter<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">%</span><span style="color: #004993;">labels</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
			changeBgColor<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> final <span style="color: #339966; font-weight: bold;">function</span> handleFooterClick<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">navigateToURL</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'http://flashsimulations.com'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000066;">standalone</span>=<span style="color: #ff0000;">&quot;no&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;application</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://ns.adobe.com/air/application/2.5&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.flashsimulations.air.HelloAndroid<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>HelloAndroid<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filename<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Hello AndroAir<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;versionNumber<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1.0.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/versionNumber<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>This application demonstrates the new Flash API for mobile devices (gestures, screen orientation). Created using Adobe AIR 2.5.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/description<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;copyright<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Piotr Koscierzynski, flashsimulations.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/copyright<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;supportedProfiles<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>mobileDevice<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/supportedProfiles<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!-- Settings for the application's initial window. Required. --&gt;</span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;initialWindow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;content<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>[This value will be overwritten by Flash Builder in the output app.xml]<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/content<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;visible<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/visible<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;autoOrients<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/autoOrients<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/initialWindow<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;android<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;manifestAdditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
			<span style="color: #339933;">&lt;![CDATA[ &lt;manifest&gt;</span>
<span style="color: #339933;">								&lt;uses-permission android:name=&quot;android.permission.ACCESS_COARSE_LOCATION&quot; /&gt;</span>
<span style="color: #339933;">								&lt;uses-permission android:name=&quot;android.permission.ACCESS_FINE_LOCATION&quot; /&gt;</span>
<span style="color: #339933;">								&lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot; /&gt;</span>
<span style="color: #339933;">								&lt;uses-permission android:name=&quot;android.permission.ACCESS_WIFI_STATE&quot; /&gt;</span>
<span style="color: #339933;">								&lt;uses-permission android:name=&quot;android.permission.CAMERA&quot; /&gt;</span>
<span style="color: #339933;">								&lt;uses-permission android:name=&quot;android.permission.DISABLE_KEYGUARD&quot; /&gt;</span>
<span style="color: #339933;">								&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;</span>
<span style="color: #339933;">								&lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot; /&gt;</span>
<span style="color: #339933;">								&lt;uses-permission android:name=&quot;android.permission.RECORD_AUDIO&quot; /&gt;</span>
<span style="color: #339933;">								&lt;uses-permission android:name=&quot;android.permission.WAKE_LOCK&quot; /&gt;</span>
<span style="color: #339933;">								&lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot; /&gt;</span>
<span style="color: #339933;">			&lt;/manifest&gt;</span>
<span style="color: #339933;">			]]&gt;</span>
			<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/manifestAdditions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/android<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>2. Create an apk file and deploy it to the device / emulator.</p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2010/10/packaging_air_app_android.png"><img class="alignnone size-full wp-image-184" title="Packaging Adobe Air for Android" src="http://flashsimulations.com/wp-content/uploads/2010/10/packaging_air_app_android.png" alt="Packaging Adobe Air for Android" width="700" height="348" /></a></p>
<p>Copy &#8216;HelloAndroid.swf&#8217; and &#8216;HelloAndroid-app.xml&#8217; into FLEX_SDK\bin directory, then run these commands</p>
<pre lang="" line="1">
cd /Users/piotr/SDK/flex_sdk_4.1_air_2.5/bin
./adt -certificate -cn flashsimulations -ou piotrkoscierzynski -c PL -validityPeriod 25 2048-RSA android_cert.p12 SecretPassword
./adt -package -target apk-emulator -storetype pkcs12 -keystore android_cert.p12  -storepass SecretPassword HelloAndroid-emu.apk HelloAndroid-app.xml HelloAndroid.swf
cp HelloAndroid-emu.apk /Users/piotr/SDK/Android_SDK/tools
cd /Users/piotr/SDK/Android_SDK/tools
./adb devices
./adb -e install -r HelloAndroid-emu.apk
</pre>
<p>The application looks like this</p>
<p>Sources: <a href="http://flashsimulations.com/wp-content/uploads/2010/10/Hello_AndroAir.zip">Hello Android Air Flash Builder project</a></p>
<div class="shr-publisher-172"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F22%2Fcreating-first-app-for-android-using-adobe-air%2F' data-shr_title='Creating+first+app+for+Android+using+Adobe+Air'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F22%2Fcreating-first-app-for-android-using-adobe-air%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F22%2Fcreating-first-app-for-android-using-adobe-air%2F' data-shr_title='Creating+first+app+for+Android+using+Adobe+Air'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F22%2Fcreating-first-app-for-android-using-adobe-air%2F' data-shr_title='Creating+first+app+for+Android+using+Adobe+Air'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://flashsimulations.com/2010/10/22/creating-first-app-for-android-using-adobe-air/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Developing Android applications with Adobe AIR &#8211; setting up the environment</title>
		<link>http://flashsimulations.com/2010/10/19/developing-android-applications-with-adobe-air/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=developing-android-applications-with-adobe-air</link>
		<comments>http://flashsimulations.com/2010/10/19/developing-android-applications-with-adobe-air/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 22:58:35 +0000</pubDate>
		<dc:creator>Piotr Koscierzynski</dc:creator>
				<category><![CDATA[adobe air]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://flashsimulations.com/?p=150</guid>
		<description><![CDATA[Since July 2010 I&#8217;ve been playing with Adobe AIR for Android. I got the prerelease version of the runtime and started investigating the new APIs for mobile devices. Adobe AIR hit the Android Market on 9th October 2010, so it&#8217;s &#8230; <a href="http://flashsimulations.com/2010/10/19/developing-android-applications-with-adobe-air/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F19%2Fdeveloping-android-applications-with-adobe-air%2F' data-shr_title='Developing+Android+applications+with+Adobe+AIR+-+setting+up+the+environment'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F19%2Fdeveloping-android-applications-with-adobe-air%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F19%2Fdeveloping-android-applications-with-adobe-air%2F' data-shr_title='Developing+Android+applications+with+Adobe+AIR+-+setting+up+the+environment'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F19%2Fdeveloping-android-applications-with-adobe-air%2F' data-shr_title='Developing+Android+applications+with+Adobe+AIR+-+setting+up+the+environment'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Since July 2010 I&#8217;ve been playing with Adobe AIR for Android. I got the prerelease version of the runtime and started investigating the new APIs for mobile devices. Adobe AIR hit the Android Market on 9th October 2010, so it&#8217;s time for the AIR developers to get to work. There are few things that if found difficult at the begining, especially the configuration and building the Android APK archive.</p>
<h2>Setup your development environment</h2>
<p>Here&#8217;s how I setup my Adobe AIR for Android environment (both MacOS X and Windows)</p>
<p><strong>Setup &#8211; Adobe AIR / Flex part</strong></p>
<p>FLEX_DIR (MacOs) = /Users/piotr/SDK/flex_sdk_4.1_air_2.5<br />
FLEX_DIR (Windows) = C:\SDK\flex_sdk_4.1_air_2.5</p>
<p>1. Download Flex SDK (version 3.5 and newer &#8211; I used 4.1) and put it in directory FLEX_DIR</p>
<p>2. Get the Adobe AIR 2.5 SDK &#8211; it&#8217;s a zip file like Flex SDK 3. Extract AIR 2.5 SDK and copy all the files to FLEX_DIR &#8211; overwrite all the files in FLEX_DIR that might overlap 4. In FLEX_DIR you now have the Flex SDK combined with AIR 2.5</p>
<p><strong>Setup &#8211; Android part</strong></p>
<p>ANDROID_DIR (MacOs) = /Users/piotr/SDK/android<br />
ANDROID_DIR (Windows) = C:\SDK\android</p>
<p>3. Download Android SDK and put it in ANDROID_DIR</p>
<p>4. Get Android 2.2 libraries and emulator using &#8220;Android SDK and AVD manager&#8221;<br />
- goto ANDROID_DIR\tools<br />
- run android (Windows) or  ./android (MacOs X)</p>
<p>5. Create an virtual device (for emulator) with Android 2.2 system (if you don&#8217;t have an Android 2.2 device)</p>
<p>You could add the FLEX_SDK\bin and ANDROID_SDK\tools directories to your system&#8217;s PATH variables to make the development process faster, but I&#8217;m not going to cover this topic here.<br />
I will keep it simple to illustrate the whole process.</p>
<p>6. To be able to test you application you need to install Adobe AIR runtime for Android.<br />
The AIR prerelease comes with two versions of the runtime &#8211; one for the device and one for the emulator.</p>
<p>The runtime for the device is Runtime_Device_Froyo_20100930.apk</p>
<p>The runtime for the emulator is Runtime_Emulator_Froyo_20100930.apk</p>
<p><strong>Creating Android 2.2 virtual device for emulator</strong></p>
<p>I created an Android 2.2 emulator (virtual device) with name &#8220;Android_22&#8243; and the install process looks like this:</p>
<p>I&#8217;ll use the ANDROID_EMULATOR_NAME for &#8220;Android_22&#8243; &#8211; my virtual device name. If you created a virtual device with a different name, then it would be the device&#8217;s name.</p>
<p>First, you need to make sure that the emulator is up and running.<br />
Goto ANDROID_SDK\tools by typing: cd ANDROID_SDK\tools<br />
Run the emulator:</p>
<p>(MacOS) ./emulator -avd ANDROID_EMULATOR_NAME or ./emulator @ANDROID_EMULATOR_NAME</p>
<p>(Windows) emulator -avd ANDROID_EMULATOR_NAME or emulator @ANDROID_EMULATOR_NAME</p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2010/10/Android_starting_emulator.png"><img class="alignleft size-full wp-image-156" title="Android - starting emulator with virtual device" src="http://flashsimulations.com/wp-content/uploads/2010/10/Android_starting_emulator.png" alt="Android - starting emulator with virtual device" width="600" /></a></p>
<p><strong>Install Adobe AIR for Android runtime</strong></p>
<p><strong><em>(Important)</em></strong> Copy both Runtime_Device_Froyo_20100930.apk and Runtime_Device_Froyo_20100930.apk into ANDROID_SDK\tools.</p>
<p><strong>To install the AIR runtime on the emulator: </strong><br />
(MacOS X): ./adb -e install -r Runtime_Emulator_Froyo_20100930.apk<br />
(Windows) adb -e install -r Runtime_Emulator_Froyo_20100930.apk</p>
<p><strong>To install the AIR runtime on the device: </strong></p>
<p>(MacOS X) ./adb  install -r Runtime_Device_Froyo_20100930.apk<br />
(Windows): adb install -r Runtime_Device_Froyo_20100930.apk</p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2010/10/Android_installing_Adobe_AIR.png"><img class="alignleft size-full wp-image-157" title="Installing Adobe AIR on Android" src="http://flashsimulations.com/wp-content/uploads/2010/10/Android_installing_Adobe_AIR.png" alt="Installing Adobe AIR on Android" width="600" /></a></p>
<p><strong>Potential problems</strong></p>
<p>If you get the &#8220;device not found&#8221; message you might need to restart the adb service.<br />
I had that problem but it worked after running these commands:</p>
<p>adb kill-server<br />
adb start-server</p>
<p>After the adb has restarted give the runtime install another try, it should work.</p>
<p><strong>You rock</strong></p>
<p>If you see &#8220;Adobe AIR&#8221; under Settings -&gt; Applications -&gt; Manage Applications than congratulations &#8211; you are ready to develop AIR apps for Android.</p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2010/10/Adobe_AIR_on_Android_apps.png"><img class="alignleft size-full wp-image-155" title="Adobe AIR runtime on Android apps list" src="http://flashsimulations.com/wp-content/uploads/2010/10/Adobe_AIR_on_Android_apps.png" alt="Adobe AIR runtime on Android apps list" width="630" /></a></p>
<p><strong>Add Flex + AIR 2.5 SDK to your IDE</strong><br />
One last thing is to add the FLEX_DIR into your IDE (Flash Builder or other like FlashDevelop)</p>
<p><a href="http://flashsimulations.com/wp-content/uploads/2010/10/Flash_Builder_SDKs_Android_AIR.png"><img class="alignleft size-full wp-image-163" title="Flash_Builder_SDKs_Android_AIR" src="http://flashsimulations.com/wp-content/uploads/2010/10/Flash_Builder_SDKs_Android_AIR.png" alt="Flash_Builder_SDKs_Android_AIR" width="630" /></a></p>
<p>In the next part of this series I&#8217;ll show how to create and deploy and Adobe AIR project and Android.</p>
<p><strong>Other posts that you might find useful</strong></p>
<p><a href="http://blog.digitalbackcountry.com/2010/10/publishing-air-apps-to-the-android-market/ " target="_blank">http://blog.digitalbackcountry.com/2010/10/publishing-air-apps-to-the-android-market/</a><a href="http://www.adobe.com/newsletters/edge/august2010/articles/article1/ " target="_blank"> http://www.adobe.com/newsletters/edge/august2010/articles/article1/</a><a href="http://unitedmindset.com/jonbcampos/2010/07/20/creating-a-flash-builder-android-project/" target="_blank"> http://unitedmindset.com/jonbcampos/2010/07/20/creating-a-flash-builder-android-project/</a></p>
<div class="shr-publisher-150"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F19%2Fdeveloping-android-applications-with-adobe-air%2F' data-shr_title='Developing+Android+applications+with+Adobe+AIR+-+setting+up+the+environment'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F19%2Fdeveloping-android-applications-with-adobe-air%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F19%2Fdeveloping-android-applications-with-adobe-air%2F' data-shr_title='Developing+Android+applications+with+Adobe+AIR+-+setting+up+the+environment'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F10%2F19%2Fdeveloping-android-applications-with-adobe-air%2F' data-shr_title='Developing+Android+applications+with+Adobe+AIR+-+setting+up+the+environment'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://flashsimulations.com/2010/10/19/developing-android-applications-with-adobe-air/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling image loading in TLF TextFlow and TextField</title>
		<link>http://flashsimulations.com/2010/09/10/handling-image-loading-in-tlf-textflow-and-textfield/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=handling-image-loading-in-tlf-textflow-and-textfield</link>
		<comments>http://flashsimulations.com/2010/09/10/handling-image-loading-in-tlf-textflow-and-textfield/#comments</comments>
		<pubDate>Fri, 10 Sep 2010 20:43:32 +0000</pubDate>
		<dc:creator>Piotr Koscierzynski</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[fp10]]></category>
		<category><![CDATA[Text Layout Framework]]></category>
		<category><![CDATA[tlf]]></category>

		<guid isPermaLink="false">http://flashsimulations.com/?p=121</guid>
		<description><![CDATA[Recently, I was building a cms driven (Drupal 6 to be precise) website and faced the problem of detecting whether the content of TextField or TFL TextFlow has completed loading. This example is based on TLF Editor from Tour de &#8230; <a href="http://flashsimulations.com/2010/09/10/handling-image-loading-in-tlf-textflow-and-textfield/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F09%2F10%2Fhandling-image-loading-in-tlf-textflow-and-textfield%2F' data-shr_title='Handling+image+loading+in+TLF+TextFlow+and+TextField'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F09%2F10%2Fhandling-image-loading-in-tlf-textflow-and-textfield%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F09%2F10%2Fhandling-image-loading-in-tlf-textflow-and-textfield%2F' data-shr_title='Handling+image+loading+in+TLF+TextFlow+and+TextField'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F09%2F10%2Fhandling-image-loading-in-tlf-textflow-and-textfield%2F' data-shr_title='Handling+image+loading+in+TLF+TextFlow+and+TextField'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Recently, I was building a cms driven (Drupal 6 to be precise) website and faced the problem of detecting whether the content of TextField or TFL TextFlow has completed loading.<br />
This example is based on TLF Editor from Tour de Flex, which I used as a base for the created editor/display component.</p>
<p><strong>1. TLF TextFlow solution</strong></p>
<p>The solution I used is actually very simple.</p>
<p>First, you need to analyze the TextFlow markup to get the number of images in text.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900; font-style: italic;">//total images counter</span><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> totalImages<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #009900; font-style: italic;">//number of loaded images</span><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> imagesLoaded<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> initTextFlowImagesCounter<span style="color: #000000;">&#40;</span>textFlowMarkup<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
<span style="color: #009900; font-style: italic;">//&lt;img &nbsp;source=&quot;http://image_url.jpg&quot; /&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> source_AttributeRegExp<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">RegExp</span> = <span style="color: #009966; font-style: italic;">/source=&quot;[^&quot;]+&quot;/gi</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> result<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = source_AttributeRegExp<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">exec</span><span style="color: #000000;">&#40;</span>textFlowMarkup<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>result <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> image_source<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #004993;">String</span><span style="color: #000000;">&#40;</span>result<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; totalImages<span style="color: #000066; font-weight: bold;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result = source_AttributeRegExp<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">exec</span><span style="color: #000000;">&#40;</span>textFlowMarkup<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Then, create a TextFlow instance and setup the necessary listeners.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">initTextFlowImagesCounter<span style="color: #000000;">&#40;</span>markup<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> activeFlow<span style="color: #000066; font-weight: bold;">:</span>TextFlow = TextConverter<span style="color: #000066; font-weight: bold;">.</span>importToFlow<span style="color: #000000;">&#40;</span>markup<span style="color: #000066; font-weight: bold;">,</span> TextConverter<span style="color: #000066; font-weight: bold;">.</span>TEXT_LAYOUT_FORMAT<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
activeFlow<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>StatusChangeEvent<span style="color: #000066; font-weight: bold;">.</span>INLINE_GRAPHIC_STATUS_CHANGE<span style="color: #000066; font-weight: bold;">,</span>recomposeOnLoadComplete<span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></td></tr></tbody></table></div>
<p>We handle all StatusChangeEvent.INLINE_GRAPHIC_STATUS_CHANGE events in recomposeOnLoadComplete function.<br />
Basicaly, this function updates the &#8216;imagesLoaded&#8217; counter, but there are few things worth mentioning.<br />
The whole image loading process in TLF is quite different than flash TextField approach, we need to manually handle the states of image elements.<br />
When the status is InlineGraphicElementStatus.SIZE_PENDING then the image has finished loaded, but the TLF didn&#8217;t actually render it, because the controller didn&#8217;t know the dimensions of  the image &#8211; so we need to call activeFlow.flowComposer.updateAllControllers(). This situation will happen only when an <img> tag doesn&#8217;t have declared &#8216;width&#8217; and &#8216;height&#8217; explicitly to a number.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> recomposeOnLoadComplete<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span>StatusChangeEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//image load error</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">status</span> == InlineGraphicElementStatus<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ERROR</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imagesLoaded<span style="color: #000066; font-weight: bold;">--;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span>element<span style="color: #000066; font-weight: bold;">.</span>getTextFlow<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> == activeFlow<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//image has loaded - we need to recalculate the size of the TLF container</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">status</span> == InlineGraphicElementStatus<span style="color: #000066; font-weight: bold;">.</span>SIZE_PENDING<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; activeFlow<span style="color: #000066; font-weight: bold;">.</span>flowComposer<span style="color: #000066; font-weight: bold;">.</span>updateAllControllers<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//image has been loaded and updated</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">status</span> == InlineGraphicElementStatus<span style="color: #000066; font-weight: bold;">.</span>READY<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imagesLoaded<span style="color: #000066; font-weight: bold;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; checkIfLoaded<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> checkIfLoaded<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
<br />
<span style="color: #009900; font-style: italic;">//all images loaded</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>totalImages == imagesLoaded<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; updateSizeInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">//just an option</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>The content displayed on the website has a lot of images, so need to know the height of the TextFlow object to be able to scroll it.<br />
This is done by this handy function.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> updateSizeInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> <span style="color: #000000;">&#123;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>activeFlow<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> cont<span style="color: #000066; font-weight: bold;">:</span>ContainerController = activeFlow<span style="color: #000066; font-weight: bold;">.</span>flowComposer<span style="color: #000066; font-weight: bold;">.</span>getControllerAt<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>cont<span style="color: #000066; font-weight: bold;">.</span>container<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
<span style="color: #009900; font-style: italic;">//height of the TextFlow instance</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">textHeight</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ceil</span><span style="color: #000000;">&#40;</span>cont<span style="color: #000066; font-weight: bold;">.</span>getContentBounds<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">textHeight</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p><strong>2. TextField solution</strong></p>
<p>The whole idea is the same, but we need to setup a Loader instance for each image to handle errors and load events. We can get the height of TextField content from the textHeight attribute.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> initTextFieldImagesLoading<span style="color: #000000;">&#40;</span><span style="color: #004993;">htmlText</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
<span style="color: #009900; font-style: italic;">//search for the 'id' attribute of 'img' tag</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> idAttributeRegExp<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">RegExp</span> = <span style="color: #009966; font-style: italic;">/id=&quot;[^&quot;]+&quot;/gi</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> result<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = idAttributeRegExp<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">exec</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">htmlText</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">while</span> <span style="color: #000000;">&#40;</span>result <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> imageId<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #004993;">String</span><span style="color: #000000;">&#40;</span>result<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; imageId = imageId<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">replace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'id=&quot;'</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">''</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; imageId = imageId<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">replace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'&quot;'</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">''</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//create an Loader instance for each image - txtDescription is our TextField with htmlText</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> ldr<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Loader</span> = txtDescription<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getImageReference</span><span style="color: #000000;">&#40;</span>imageId<span style="color: #000000;">&#41;</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Loader</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>ldr <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; totalImages<span style="color: #000066; font-weight: bold;">++;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ldr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentLoaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">INIT</span><span style="color: #000066; font-weight: bold;">,</span> onTextFieldImageLoaded<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ldr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentLoaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IO_ERROR</span><span style="color: #000066; font-weight: bold;">,</span> onTextFieldIOError<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; result = idAttributeRegExp<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">exec</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">htmlText</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onTextFieldImageLoaded<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">INIT</span><span style="color: #000066; font-weight: bold;">,</span> onTextFieldImageLoaded<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IO_ERROR</span><span style="color: #000066; font-weight: bold;">,</span> onTextFieldIOError<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imagesLoaded<span style="color: #000066; font-weight: bold;">++;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; checkIfLoaded<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onTextFieldIOError<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">INIT</span><span style="color: #000066; font-weight: bold;">,</span> onTextFieldImageLoaded<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IO_ERROR</span><span style="color: #000066; font-weight: bold;">,</span> onTextFieldIOError<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; totalImages<span style="color: #000066; font-weight: bold;">--;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; checkIfLoaded<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<div class="shr-publisher-121"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F09%2F10%2Fhandling-image-loading-in-tlf-textflow-and-textfield%2F' data-shr_title='Handling+image+loading+in+TLF+TextFlow+and+TextField'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F09%2F10%2Fhandling-image-loading-in-tlf-textflow-and-textfield%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F09%2F10%2Fhandling-image-loading-in-tlf-textflow-and-textfield%2F' data-shr_title='Handling+image+loading+in+TLF+TextFlow+and+TextField'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2010%2F09%2F10%2Fhandling-image-loading-in-tlf-textflow-and-textfield%2F' data-shr_title='Handling+image+loading+in+TLF+TextFlow+and+TextField'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://flashsimulations.com/2010/09/10/handling-image-loading-in-tlf-textflow-and-textfield/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>3d physics in Flash with Jiglibflash and Away3DLite</title>
		<link>http://flashsimulations.com/2009/12/21/3d-physics-in-flash-with-jiglibflash-and-away3dlite/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=3d-physics-in-flash-with-jiglibflash-and-away3dlite</link>
		<comments>http://flashsimulations.com/2009/12/21/3d-physics-in-flash-with-jiglibflash-and-away3dlite/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 01:02:51 +0000</pubDate>
		<dc:creator>Piotr Koscierzynski</dc:creator>
				<category><![CDATA[3d]]></category>
		<category><![CDATA[away3dlite]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[jiglibflash]]></category>

		<guid isPermaLink="false">http://91.205.74.118/flashsimulations.com/wordpress/?p=46</guid>
		<description><![CDATA[Newest experiment using Jiglibflash and Away3DLite, requires Flash Player 10. The speed boost in comparison to PV3D and FP9 version of Jiglib is unbelieveable (over 3500 triangles and realtime collision detection). It&#8217;s a work in progress, but you can take &#8230; <a href="http://flashsimulations.com/2009/12/21/3d-physics-in-flash-with-jiglibflash-and-away3dlite/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F21%2F3d-physics-in-flash-with-jiglibflash-and-away3dlite%2F' data-shr_title='3d+physics+in+Flash+with+Jiglibflash+and+Away3DLite'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F21%2F3d-physics-in-flash-with-jiglibflash-and-away3dlite%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F21%2F3d-physics-in-flash-with-jiglibflash-and-away3dlite%2F' data-shr_title='3d+physics+in+Flash+with+Jiglibflash+and+Away3DLite'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F21%2F3d-physics-in-flash-with-jiglibflash-and-away3dlite%2F' data-shr_title='3d+physics+in+Flash+with+Jiglibflash+and+Away3DLite'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Newest experiment using Jiglibflash and Away3DLite, requires Flash Player 10. The speed boost in comparison to PV3D and FP9 version of Jiglib is unbelieveable (over 3500 triangles and realtime collision detection). It&#8217;s a work in progress, but you can take a look <a href="http://flashsimulations.com/jiglibcar/" target="_blank">here: Letters and car 3d physics demo.</a><br />
</br >Using jiglib car physics in Away3DLite is pretty hard, I don&#8217;t know why it differs so much from the PV3D version. If the car starts to behave &#8216;crazy&#8217; or gets stuck, press the &#8216;r&#8217; key to reset it. You can also throw a snowball by pressing &#8216;b&#8217; key.<br />
Use arrows to steer the car and space bar for handbrake.</p>
<div class="shr-publisher-46"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F21%2F3d-physics-in-flash-with-jiglibflash-and-away3dlite%2F' data-shr_title='3d+physics+in+Flash+with+Jiglibflash+and+Away3DLite'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F21%2F3d-physics-in-flash-with-jiglibflash-and-away3dlite%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F21%2F3d-physics-in-flash-with-jiglibflash-and-away3dlite%2F' data-shr_title='3d+physics+in+Flash+with+Jiglibflash+and+Away3DLite'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F21%2F3d-physics-in-flash-with-jiglibflash-and-away3dlite%2F' data-shr_title='3d+physics+in+Flash+with+Jiglibflash+and+Away3DLite'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://flashsimulations.com/2009/12/21/3d-physics-in-flash-with-jiglibflash-and-away3dlite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How it&#039;s made? Blender + Papervision3D = Flash car drive</title>
		<link>http://flashsimulations.com/2009/12/16/how-its-made-blender-papervision3d-car-drive-in-flash/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-its-made-blender-papervision3d-car-drive-in-flash</link>
		<comments>http://flashsimulations.com/2009/12/16/how-its-made-blender-papervision3d-car-drive-in-flash/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 21:54:05 +0000</pubDate>
		<dc:creator>Piotr Koscierzynski</dc:creator>
				<category><![CDATA[3d]]></category>
		<category><![CDATA[blender]]></category>
		<category><![CDATA[experiments]]></category>
		<category><![CDATA[papervision3d]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[papervision]]></category>
		<category><![CDATA[polonez]]></category>

		<guid isPermaLink="false">http://91.205.74.118/flashsimulations.com/wordpress/?p=19</guid>
		<description><![CDATA[Welcome to flashsimulations.com! Hello. If you&#8217;ve been to this website before, you might be suprised, because it has changed significantly. I decided to run a blog under flashsimulations.com to archive my experiments involving various technologies. If you&#8217;re looking for the &#8230; <a href="http://flashsimulations.com/2009/12/16/how-its-made-blender-papervision3d-car-drive-in-flash/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F16%2Fhow-its-made-blender-papervision3d-car-drive-in-flash%2F' data-shr_title='How+it%26%23039%3Bs+made%3F+Blender+%2B+Papervision3D+%3D+Flash+car+drive'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F16%2Fhow-its-made-blender-papervision3d-car-drive-in-flash%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F16%2Fhow-its-made-blender-papervision3d-car-drive-in-flash%2F' data-shr_title='How+it%26%23039%3Bs+made%3F+Blender+%2B+Papervision3D+%3D+Flash+car+drive'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F16%2Fhow-its-made-blender-papervision3d-car-drive-in-flash%2F' data-shr_title='How+it%26%23039%3Bs+made%3F+Blender+%2B+Papervision3D+%3D+Flash+car+drive'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetTop Automatic --><div id="attachment_93" class="wp-caption aligncenter" style="width: 549px"><a href="http://flashsimulations.com/polonez"><img src="http://flashsimulations.com/wp-content/uploads/2009/12/PV3DPolonezPostImage.jpg" alt="How it&#039;s made? Blender + Papervision3D = Car drive in flash" title="PV3DPolonezPostImage" width="539" height="238" class="size-full wp-image-93" /></a><p class="wp-caption-text">Polonez Borewicz - click to drive it!</p></div>
<h2>Welcome to flashsimulations.com!</h2>
<p>Hello.</p>
<p>If you&#8217;ve been to this website before, you might be suprised, because it has changed significantly. I decided to run a blog under flashsimulations.com to archive my experiments involving various technologies.<br />
If you&#8217;re looking for the car demo that used to be the landing page, read on. You&#8217;ll find it and even more.<br />
This site&#8217;s name is flashsimulations.com, but it&#8217;s not going to cover only topics that have something to do with Adobe Flash Platform.</p>
<h2>Let&#8217;s start blogging !</h2>
<p>Long time ago, in April of 2008 while experimenting with 3d in flash, I created a car driving experiment that used to be under this address &#8211; you can find it <a href="http://flashsimulations.com/polonez2008">here</a>. In October 2008 my demo has been  selected as one of the 9 cool experiments on Papervision3D official blog, since then I got a lot of feedback and questions from enthusiasts of flash and 3d.</p>
<div id="attachment_25" class="wp-caption aligncenter" style="width: 260px"><a href="http://blog.papervision3d.org/2008/10/08/pv3d-showcase-9-cool-experiments-in-3d/" target="_blank"><img class="size-full wp-image-25 " title="Polonez Borewicz on PV3D blog (click to visit Papervision3D blog)" src="http://flashsimulations.com/wp-content/uploads/2009/12/flashsimulations-pv3d-blog.jpg" alt="flashsimulations-pv3d-blog" width="250" height="250" /></a><p class="wp-caption-text">Fig. 1: Polonez Borewicz showcased on PV3D blog, October 2008</p></div>
<p style="text-align: center;">
<p>I decided to write this tutorial after I got many e-mails from people asking how that car demo was made. Unfortunately, I didn&#8217;t have time to write everyone back, due to the complexity of this topic.</p>
<h2>1981 FSO Polonez &#8220;Borewicz&#8221;, the car</h2>
<p>Recently, I updated the original flash demo to work with the latest version of Papervision3D 2 and I slightly upgraded the car model itself. In this tutorial I will describe how you can export your model from Blender 2.49 to Flash and create a 3D car driving simulation using ActionScript 3 and Papervision3D engine.<br />
I guess that most of you aren&#8217;t familliar with the car that I&#8217;ve modeled, it&#8217;s the  1981 FSO Polonez, nicknamed &#8220;Borewicz&#8221;.</p>
<p>Here&#8217;s the test drive of Polonez by Jeremy Clarkson.<br />
<p><a href="http://flashsimulations.com/2009/12/16/how-its-made-blender-papervision3d-car-drive-in-flash/"><em>Click here to view the embedded video.</em></a></p></p>
<h2>Preparing the model in Blender</h2>
<p>First of all, you need to export model from the 3d application of your choice &#8211; Papervision 2 accepts formats such as: .3ds, Collada, .MD2 and a few other.</p>
<p>I created Polonez model using Blender 2.49 and exported it to Collada 1.4 (.dae). I admit &#8211; the model isn&#8217;t pretty, but it was the first model I ever did. My priority was to keep the number of triangles as low as possible, to get better rendering speed in flash.<br />
After many Papervision performance tests I managed to get a reasonable frame rate (at least 15) when the model had less than 2,000 triangles. Of course the performance of the application varies depending on the user&#8217;s processor  &#8211; I wanted this demo (in April 2008) to run smoothly even on low budget computers, so I tested it on Intel Core2Duo T 5250@1.50Ghz with 2GB RAM laptop. The performance is no longer such an issuse as it was back then, as Papervision has been improved and the performance increased.</p>
<p>Since we want to be able to control the car wheels to simulate steering and movement, we need to provide proper name to each element of the car. On the following picture you can see the names I gave to wheels and the &#8216;Transforn Properties&#8217; window (&#8216;N&#8217; key shotcut), where you enter the name.</p>
<div id="attachment_38" class="wp-caption aligncenter" style="width: 310px"><a href="http://flashsimulations.com/wp-content/uploads/2009/12/blender-polonez-model-elements-names1.jpg" target="_blank"><img class="size-medium wp-image-38 " title="Naming car model elements in Blender" src="http://91.205.74.118/flashsimulations.com/wordpress/wp-content/uploads/2009/12/blender-polonez-model-elements-names-300x141.jpg" alt="Naming car model elements in Blender" width="300" height="141" /></a><p class="wp-caption-text">Fig. 2: Naming car model elements in Blender</p></div>
<p>When the model is finished, it&#8217;s time to export it to Collada 1.4. Select File -&gt; Export -&gt; Collada 1.4(.dae) , set the plugin options like on the picture below; click &#8216;Export &amp; Close&#8217; and that&#8217;s it.</p>
<div id="attachment_39" class="wp-caption aligncenter" style="width: 256px"><img class="size-full wp-image-39 " title="Blender - Collada 1.4 export plugin options" src="http://flashsimulations.com/wp-content/uploads/2009/12/collada_export.jpg" alt="Blender - Collada 1.4 export plugin options" width="246" height="442" /><p class="wp-caption-text">Fig. 3: Blender - Collada 1.4 export plugin options</p></div>
<h2>Importing the model to Papervision</h2>
<p>When the model is ready, it&#8217;s time to do some coding. You&#8217;ll need the latest version of PV3D, get it <a href="http://code.google.com/p/papervision3d/" target="_blank">here</a>. The code of the car simulation  is pretty straightforward (I also commented it heavily), so I&#8217;m going to comment it just briefly.<br />
Main class is based on PV3D&#8217;s BasicView and here&#8217;s the init function, where we setup everything.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span> = <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADDED_TO_STAGE</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; initCameras<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; initTextures<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; initModel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//...</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//pv3d statistics and other UI stuff</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Initialize four cameras &#8211; their positions will be set in other function.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> initCameras<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; cameras<span style="color: #000000;">&#91;</span>CAMERA_DEFAULT<span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Camera3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; cameras<span style="color: #000000;">&#91;</span>CAMERA_DEFAULT<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">5</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; cameras<span style="color: #000000;">&#91;</span>CAMERA_DEFAULT<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">60</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; cameras<span style="color: #000000;">&#91;</span>CAMERA_DEFAULT<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">zoom</span> = <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span>cameras<span style="color: #000000;">&#91;</span>CAMERA_CAR_HOOD<span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Camera3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; cameras<span style="color: #000000;">&#91;</span>CAMERA_CAR_BEHIND<span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Camera3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; cameras<span style="color: #000000;">&#91;</span>CAMERA_CAR_WHEEL<span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Camera3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//set the camera to default</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>_camera = cameras<span style="color: #000000;">&#91;</span>CAMERA_DEFAULT<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Init material from embedded texture .jpg.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> initTextures<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; carModelTexture = <span style="color: #0033ff; font-weight: bold;">new</span> BitmapMaterial<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> carTextureAsset <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bitmapData</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//looks better, but the framerate drops</span><br />
&nbsp; &nbsp; carModelTexture<span style="color: #000066; font-weight: bold;">.</span>smooth = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>The loaded model will be parented to an empty container because we won&#8217;t apply any tranlations nor rotations to the model itself.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> initModel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; carModelParent = <span style="color: #0033ff; font-weight: bold;">new</span> DisplayObject3D<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; scene<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>carModelParent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//car texture</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> mats<span style="color: #000066; font-weight: bold;">:</span>MaterialsList = <span style="color: #0033ff; font-weight: bold;">new</span> MaterialsList<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; mats<span style="color: #000066; font-weight: bold;">.</span>addMaterial<span style="color: #000000;">&#40;</span>carModelTexture<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;all&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>carModel = <span style="color: #0033ff; font-weight: bold;">new</span> DAE<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//initial position</span><br />
&nbsp; &nbsp; carModelParent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; carModelParent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; carModelParent<span style="color: #000066; font-weight: bold;">.</span>z = <span style="color: #000000; font-weight:bold;">1050</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; carModelParent<span style="color: #000066; font-weight: bold;">.</span>rotationY = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">35</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span>FileLoadEvent<span style="color: #000066; font-weight: bold;">.</span>LOAD_COMPLETE<span style="color: #000066; font-weight: bold;">,</span> onLoad<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">XML</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> carModelAsset<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">,</span> mats<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">//we add the Collada model to the parent DO3D</span><br />
&nbsp; &nbsp; carModelParent<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>carModel<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>To control the wheels roll and steer angle we have to create a series of instances of DisplayObject3D class that will hold the reference to each part of the car &#8211; that&#8217;s the moment when the knowledge car elements&#8217; names comes in handy. The same rule applies to our defined cameras and their targets.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> onLoad<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">scale</span> = <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; viewport<span style="color: #000066; font-weight: bold;">.</span>getChildLayer<span style="color: #000000;">&#40;</span>carModel<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>layerIndex = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//set references to car wheels;</span><br />
&nbsp; &nbsp; wheelFrontRight = carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Wheel_Front_Right&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; wheelFrontLeft = carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Wheel_Front_Left&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; wheelRearLeft = carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Wheel_Rear_Left&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; wheelRearRight = carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Wheel_Rear_Right&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//set targets for all cameras</span><br />
&nbsp; &nbsp; cameraTargets<span style="color: #000000;">&#91;</span>CAMERA_CAR_HOOD<span style="color: #000000;">&#93;</span> = carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Camera_Hood_Target&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; cameraTargets<span style="color: #000000;">&#91;</span>CAMERA_DEFAULT<span style="color: #000000;">&#93;</span> = carModelParent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; cameraTargets<span style="color: #000000;">&#91;</span>CAMERA_CAR_BEHIND<span style="color: #000000;">&#93;</span> = carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Licence_Plate_Front&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; cameraTargets<span style="color: #000000;">&#91;</span>CAMERA_CAR_WHEEL<span style="color: #000000;">&#93;</span> = carModel<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getChildByName</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Camera_Wheel_Target&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>enableListeners<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//KEY_UP, KEY_DOWN and ENTER_FRAME</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Here&#8217;s the  ENTER_FRAME handler</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> tick<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; updateCamerasPositions<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; camera<span style="color: #000066; font-weight: bold;">.</span>lookAt<span style="color: #000000;">&#40;</span>cameraTargets<span style="color: #000000;">&#91;</span>currentCamera<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; driveCar<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; updateCarState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; singleRender<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>The last thing I&#8217;m going to describe is the updateCarStateFunction. All the coefficients that you can see have been matched by trial &amp; error method. Change them to get different car behaviour.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> updateCarState<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> movingForward<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span> = speed <span style="color: #000066; font-weight: bold;">&amp;</span>gt<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//adjust the angular velocity of the wheel</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> wheelRoll<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.7</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> speed<span style="color: #000066; font-weight: bold;">;</span>wheelFrontRight<span style="color: #000066; font-weight: bold;">.</span>rotationY &nbsp;<span style="color: #000066; font-weight: bold;">-</span>= wheelRoll<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; wheelFrontLeft<span style="color: #000066; font-weight: bold;">.</span>rotationY <span style="color: #000066; font-weight: bold;">+</span>= wheelRoll<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; wheelRearLeft<span style="color: #000066; font-weight: bold;">.</span>rotationY <span style="color: #000066; font-weight: bold;">-</span>= &nbsp;wheelRoll<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; wheelRearRight<span style="color: #000066; font-weight: bold;">.</span>rotationY <span style="color: #000066; font-weight: bold;">-</span>= &nbsp;wheelRoll<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//90 and -90 are here to fix the rotation - normal vectors of front wheels must be opposite</span><br />
&nbsp; &nbsp; wheelFrontRight<span style="color: #000066; font-weight: bold;">.</span>rotationZ = <span style="color: #000000; font-weight:bold;">90</span><span style="color: #000066; font-weight: bold;">-</span>wheelAngle<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; wheelFrontLeft<span style="color: #000066; font-weight: bold;">.</span>rotationZ = <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">90</span><span style="color: #000066; font-weight: bold;">-</span>wheelAngle<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; carModelParent<span style="color: #000066; font-weight: bold;">.</span>yaw<span style="color: #000000;">&#40;</span>speed <span style="color: #000066; font-weight: bold;">*</span> wheelAngle <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.002</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">0.0004</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #004993;">Number</span><span style="color: #000000;">&#40;</span>movingForward<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// we use different speed for car rotation around it's Z axis</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//(lower value when the car is reversing - simple technique, but adds a bit of realism</span><br />
&nbsp; &nbsp; carModelParent<span style="color: #000066; font-weight: bold;">.</span>moveBackward<span style="color: #000000;">&#40;</span> speed <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0.9</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">0.2</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #004993;">Number</span><span style="color: #000000;">&#40;</span>movingForward<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p><a href="http://flashsimulations.com/wp-content/uploads/2009/12/PolonezBorewiczPV3D1.zip">Get this project sources (FlashDevelop AS3 project)</a>. Requires Flex 3.4 SDK.</p>
<div class="shr-publisher-19"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F16%2Fhow-its-made-blender-papervision3d-car-drive-in-flash%2F' data-shr_title='How+it%26%23039%3Bs+made%3F+Blender+%2B+Papervision3D+%3D+Flash+car+drive'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F16%2Fhow-its-made-blender-papervision3d-car-drive-in-flash%2F'></a><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F16%2Fhow-its-made-blender-papervision3d-car-drive-in-flash%2F' data-shr_title='How+it%26%23039%3Bs+made%3F+Blender+%2B+Papervision3D+%3D+Flash+car+drive'></a><a class='shareaholic-tweetbutton' data-shr_count='none' data-shr_href='http%3A%2F%2Fflashsimulations.com%2F2009%2F12%2F16%2Fhow-its-made-blender-papervision3d-car-drive-in-flash%2F' data-shr_title='How+it%26%23039%3Bs+made%3F+Blender+%2B+Papervision3D+%3D+Flash+car+drive'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://flashsimulations.com/2009/12/16/how-its-made-blender-papervision3d-car-drive-in-flash/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

