<?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>Spreading Funkyness</title>
	<atom:link href="http://spreadingfunkyness.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://spreadingfunkyness.com</link>
	<description>RIAbilitating the Internet with web apps, ria, iphone and ipad apps.</description>
	<lastBuildDate>Tue, 06 Jul 2010 21:37:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
<cloud domain='spreadingfunkyness.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>How Pomodoro Improved my life as a Freelancer</title>
		<link>http://spreadingfunkyness.com/how-pomodoro-improved-my-life-as-a-freelancer/</link>
		<comments>http://spreadingfunkyness.com/how-pomodoro-improved-my-life-as-a-freelancer/#comments</comments>
		<pubDate>Mon, 03 May 2010 11:52:35 +0000</pubDate>
		<dc:creator>Cesare</dc:creator>
				<category><![CDATA[freelancing]]></category>

		<guid isPermaLink="false">http://spreadingfunkyness.com/?p=320</guid>
		<description><![CDATA[I heard about Pomodoro a while ago. I have to he honest: I was skeptical. My first reaction? &#8220;Com&#8217;on, I am able to manage my time, I don&#8217;t need any technique&#8221;. I was wrong. While it is true that I am perfectly able to manage my time, it is also true that there can better ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin: 0px 10px 0px 0px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fspreadingfunkyness.com%2Fhow-pomodoro-improved-my-life-as-a-freelancer%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fspreadingfunkyness.com%2Fhow-pomodoro-improved-my-life-as-a-freelancer%2F&amp;source=_funkyboy&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p><img src="http://spreadingfunkyness.com/wp-content/uploads/2010/04/pomodoro-300x225.jpg" alt="" title="pomodoro" width="300" height="225" class="alignnone size-medium wp-image-323" align="right" /></p>
<p>I heard about Pomodoro a while ago. I have to he honest: I was skeptical. My first reaction? </p>
<blockquote><p><em>&#8220;Com&#8217;on, I am able to manage my time, I don&#8217;t need any technique&#8221;. </em></p></blockquote>
<p>I was wrong. While it is true that I am perfectly able to manage my time, it is also true that there can better ways to do it. A while ago I was really overwhelmed with projects and duties so I thought: &#8220;why I don&#8217;t give Pomodoro a try? Just one week. If it does not work, no worries.&#8221;</p>
<h2>How pomodoro technique works?</h2>
<p><em>Here I report just a few key aspects of the technique. To know more visit Pomodoro website (links below).</em></p>
<p>What do you do to wake up in the morning? Set up a clock. I do it, otherwise I sleep until midday. To be really concise, Pomodoro is all about this: <em>setting up a clock</em>. Pomodoro is a time management techique which recommends to shred your time in chunks, each lasting 25 minutes. Every chunk of 25 minutes is equivalent to 1 Pomodoro, that is a time span of uninterrupted work. After completing a Pomodoro you can take a 5 minute break. You might think: &#8220;I can do more than that!&#8221;. Sure thing. But &#8230; Let&#8217;s suppose you work 4 hours in a row. Then take a break (lunch). Answer the following questions:</p>
<ul>
<li>Can you see the progress? Always? </li>
<li>What did you do in 4 hours? </li>
<li>Do you remember everything you did? </li>
<li>Can you tell how much you have been productive?</li>
</ul>
<p>I have been in this situation many times. Why didn&#8217;t the design progress? too much facebook? too much time to find the perfect glow effect? I wasn&#8217;t able to remember why I did not feel the progress. When a Pomodoro ends I am prone to measure my productivity and, if not satisfied, improve it. It is much easier to remember and check the activity of 25 minutes than the one of 4 hours. This is just one advantage of time chucking.</p>
<h2>Time chucking</h2>
<p>It is a well known technique. Chunk your project in tasks, chunk tasks in subtasks, chunk your time in spans. The advantages are terrific.<br />
First of all you are forced to <b>stay focused on one thing at a time</b>. Tempted to check the twitter? You can do it when the pomodoro ends. I am not saying tomorrow, I am saying in at most 25 minutes. It&#8217;s not that much.<br />
The second advantage is about motivation. How many times you get bored about a task? Check the timer: pomodoro ends in 12 minutes, you can resist. The prize: five minutes of rest and (probably) another nicer task.<br />
The most valuable advantage to me is about naming a Pomodoro. There are many applications that help you to adopt the Pomodoro technique. I downloaded <a href="pomodoro.ugolandini.com">Pomodoro</a> which allows you to set a timer and to provide a title. How many times I started one task and ended up working on another one? By means of this technique you are &#8220;forced&#8221; to state: </p>
<blockquote><p>&#8220;Ok, now for the next 25 minutes I will work on X&#8221;. </p></blockquote>
<p>Get lost for some reason? Look at the timer and you&#8217;ll find it out! Moreover, providing a title means that you have already some plan about your duties of the day, and those duties are already pre-organized in chunks of 25 minutes. This is invaluable, because you know where you are and you know where you want to be at the end of the day. A task does not fit 25 minutes? Shred it or use more than one pomodoro. A task is too short? Group it with similar ones.<br />
What if you get interrupted? No worries, there are ways to deal with this situation. In essence you can try to postpone the interruption (you colleague/wife will not die for less than 25 minutes) or interrupt the Pomodoro if the deal is really urgent. Just keep a log about it, because at the end of the day you can check what depends on you and what does not. </p>
<h2>What I achieved by means of Pomodoro?</h2>
<ul>
<li>Developed an <a href="http://www.hugetweetsapp.com/">iPad application</a> in less than planned</li>
<li>Speed up my micro tasks, update this, do that, etc</li>
<li>Reduced the time spent reading too much</li>
<li>Gained some spare time</li>
<li>Reduced procrastination</li>
<li>I am writing a <a href="http://www.datavisualizationflashbuilder.com/">book</a> with no paranoia about the time spent</li>
<li>Learned to assign priorities</li>
</ul>
<h1>Conclusion</h1>
<p>I am not saying this technique will solve everybody&#8217;s problems. Just try Pomodoro out. One week. If it does not work, you have just &#8216;lost&#8217; one week. If it does you have found a way to improve your personal and professional life. </p>
<h2>Links</h2>
<ul>
<li><a href="http://www.pomodorotechnique.com/">Pomodoro Website</a></li>
<li>Photo by <a href="http://www.flickr.com/photos/elgiulio/3748834603/">elgiulio</a></li>
</ul>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://spreadingfunkyness.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://spreadingfunkyness.com/how-pomodoro-improved-my-life-as-a-freelancer/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Apple vs Adobe: do I need really to choose?</title>
		<link>http://spreadingfunkyness.com/apple-vs-adobe-do-i-need-really-to-choose/</link>
		<comments>http://spreadingfunkyness.com/apple-vs-adobe-do-i-need-really-to-choose/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 11:09:13 +0000</pubDate>
		<dc:creator>Cesare</dc:creator>
				<category><![CDATA[adobe]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://spreadingfunkyness.com/?p=321</guid>
		<description><![CDATA[My opinion about the Apple vs Adobe fight: I feel I don't need to choose at the moment.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin: 0px 10px 0px 0px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fspreadingfunkyness.com%2Fapple-vs-adobe-do-i-need-really-to-choose%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fspreadingfunkyness.com%2Fapple-vs-adobe-do-i-need-really-to-choose%2F&amp;source=_funkyboy&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>There is a lot of buzz around Apple <em>vs</em> Adobe recently. It all started few years ago, when Flash was forbidden on the iPhone. <a href="http://innerdaemon.wordpress.com/2010/04/10/sorry-adobe-you-screwed-yourself/">Somebody claims</a> that it started even before. I really don&#8217;t want to get into the chronology of the issue. I am just wondering: <strong>do I really need to choose</strong>?<br />
Many people <a href="http://theflashblog.com/?p=1888">took it personal</a> and, as long as the are allowed (by laws and by companies&#8217; policy) they are free to express their opinion. I understand their viewpoint. If you believe in a company, you invested your time by using/learning/building-on-top-of their tools, you get angry when these conflicts happen. And if you are angry you can have reactions like changing your hardware and software in favor of another producer.<br />
I am writing this post because I feel weird about this situation, for I am not angry (yet :). I started my career with Flash, since MX 2004 version. The Flash platform enabled me to pay my bills and it still does, cause I <a href="http://www.studiomagnolia.com/services/#ria">develop, consult, teach</a> and <a href="http://www.datavisualizationflashbuilder.com">write</a> about the Flash platform. Probably I did a good move a while ago by qualifying myself as &#8220;designer and developer of web, ria and mobile applications&#8221;. This is my short description, that you&#8217;ll find anywhere my logo appears. As you can see there is no commitment to any specific technology. Though I might have preferences about development tools, I think what clients need is a solution to their problems, not a list of complicated techie explanations about what is under the hood. Probably another good move I did almost three years ago was to expand my knowledge of the mobile industry, and specifically of the design and development of iPhone applications. I was fascinated by the tool and especially by the &#8220;ecosystem&#8221; of iTunes, &#8217;cause the biggest obstacle for me has been commercializing, and not developing, my products. Although I have played with <a href="http://www.appcelerator.com/products/titanium-mobile-application-development/">Titanium</a> (and I liked it)  I always stuck with Objective-c, because I felt I had more control on the development process and the final result. There are many support tools (debugger, leak hunter) and overall I like XCode.<br />
I built applications for clients and I recently released <a href="http://www.hugetweetsapp.com/">HugeTweets</a>, an app for the IPad in less time than planned (launch deadlines help :). So far I just I feel I have to say thanks, to both Adobe and Apple. As long as they will run on MacOsX I will use Adobe tools to design and develop. As long as Apple will produce MacOsX and will keep the current ratio for developers&#8217; gain on the iTunes store, I will work on the iPhone/iPad.<br />
<strong>In few words I don&#8217;t feel the need to say: &#8220;I am with &#8230;&#8221;</strong>.<br />
Honestly, I also feel I am taking advantage of the recent <a href="http://daringfireball.net/2010/04/why_apple_changed_section_331">3.3.1 clause </a>. I am NOT saying I am happy of a restrictive rule, I DO like open platforms, but at the moment my investment on the iphone/ipad market acquires value, &#8217;cause <strong>there are less potential iphone developers</strong>, all those which invested on &#8220;third party&#8221; dev tools. Should I raise my hourly rate? :)<br />
The main reason I didn&#8217;t fully switch to those tools is the lack of debug/measurement tools. Since I spend part of my time improving performance and memory usage of iphone/ipad apps (and Apple provides great tools to do it), I always wondered how can I do it in Flash/Titanium/OpenGap? Still wondering, if you have any idea drop a comment below &#8230;<br />
Summing up, I feel weird because I am still using what I think is the best of both worlds: Adobe&#8217;s tools to design/mockup and MacOsX to develop on the iphone/ipad platform and I don&#8217;t feel the need to boycott any company. </p>
<p>Out of curiosity: how does Apple find out when an application is not built with c/objective-c? Any hidden code put in the binary by the compiler?</p>
<p>UPDATE: <a href="http://www.tuaw.com/2010/04/14/360idev-ansca-mobiles-corona-sdk/">Even guys behind Corona are not worried</a>.</p>
<p>ps: wanna betatest upcoming versions of my iPad application? All you need is an iPad and a Twitter account. Drop a message to the support email here: <a href="http://www.hugetweetsapp.com/"> hugetweetsapp.com</a> or dm me on <a href="http://twitter.com/_funkyboy">Twitter</a>. You&#8217;ll receive instructions.</p>
]]></content:encoded>
			<wfw:commentRss>http://spreadingfunkyness.com/apple-vs-adobe-do-i-need-really-to-choose/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The tale of my Macbook Pro battery</title>
		<link>http://spreadingfunkyness.com/the-tale-of-my-macbook-pro-battery/</link>
		<comments>http://spreadingfunkyness.com/the-tale-of-my-macbook-pro-battery/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 11:36:52 +0000</pubDate>
		<dc:creator>Cesare</dc:creator>
				<category><![CDATA[apple]]></category>

		<guid isPermaLink="false">http://spreadingfunkyness.com/?p=312</guid>
		<description><![CDATA[I was going to write an angry post after some recent experience with Apple customer care service. Now I am writing a happy ending tale with a strong suggestion as final moral: unplug the cable only when necessary or when you need to calibrate the battery. Here is why. After eleven months of usage my ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin: 0px 10px 0px 0px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fspreadingfunkyness.com%2Fthe-tale-of-my-macbook-pro-battery%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fspreadingfunkyness.com%2Fthe-tale-of-my-macbook-pro-battery%2F&amp;source=_funkyboy&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>I was going to write an angry post after some recent experience with Apple customer care service. Now I am writing a happy ending tale with a strong suggestion as final moral: <em>unplug the cable only when necessary or when you need to calibrate the battery</em>. Here is why.</p>
<p><img src="http://spreadingfunkyness.com/wp-content/uploads/2010/03/battery.gif" alt="Service Battery" title="Service Battery" width="249" height="183" class="aligncenter size-full wp-image-313" align="left" />After eleven months of usage my Macbook Pro notifies a &#8220;service battery&#8221; message like in the picture. Before contacting the customer service I started investigating on the internet. Many people on Apple&#8217;s forum <a href="http://discussions.apple.com/thread.jspa?threadID=2139186&#038;tstart=0&#038;start=15">had a similar issue</a>, which has been reported after the upgrade to Snow Leopard. Since I upgraded as well I thought my machine was falling into the same category, so I adopted the same solutions proposed in the forum: recalibrate, reset pram, <a href="http://support.apple.com/kb/HT3964?viewlocale=en_US">SCM reset</a>, etc. I didn&#8217;t solve. Then I installed <a href="http://www.coconut-flavour.com/coconutbattery/">coconut battery</a>, which reported 363 cycles. Finally I decided to contact Apple&#8217;s customer service. Since my mac is less than one year old the warranty is still valid. I went to the shop confident that they&#8217;d just change my battery with a new one. There I got the first shock.<br />
The live by a rule: <em>battery is a consumable</em>.<br />
&#8220;Agree, I am not denying the evidence, but my warranty is still valid and I expect you give me a new battery at no charge&#8221; I replied ingenuously.<br />
&#8220;Let&#8217;s see the number of cycles, if lesser than 300 we can change the battery at no charge&#8221;. They plugged in a usb key while I was figuring out 120 bucks flying from my pockets to theirs. The key confirmed the previous verdict: 363 cycles.<br />
I thought &#8220;DAMN&#8221; but I said: &#8220;Ok, I am not discussing your rules, just wondering where I can check them out. You know, when you buy a tool with a warranty you want to know its conditions.&#8221;<br />
They replied: &#8220;This is what I am told whenever I open a procedure about a battery, no free substitution if cycles are greater than 300, EVEN IF you have bought the Apple care. There should be something about that on the Apple&#8217;s web site.&#8221;<br />
Very said, I left my used battery at the shop an got home. During the trip I was mumbling: &#8220;This is not transparent, when I buy something I HAVE to know its policy about substitution.&#8221; I called the european office and they pointed me to <a href="http://www.apple.com/batteries/notebooks.html">this page</a>, which mentions the famous 300 cycles, but no details about substitution policies. Again, I am not happy, cause I think it should be written explicitly: &#8220;We do not change the battery, even if under warranty, if cycles are greater than 300.&#8221; Write in on the booklet, on the internet, somewhere in a public place.<br />
The angryness faded away during the weekend and got happiness when on monday I went to the shop and they told me that I did not need to pay, because &#8220;the procedure&#8221; did not require a payment for now. They will send back the old battery and, IF there is no argument, I will not pay.<br />
I also happily collected some hints from the guy at the shop. Here is a quick recap.</p>
<ul>
<li>This type of batteries has no memory effect.</li>
<li>Completely discharge and recharge only when you need to calibrate the battery.</li>
<li>When full, if you unplug and replug immediately, you will use battery power until it is 95% (even if the cable is plugged in). This counts as 1/20 of a cycle.</li>
</ul>
<p>The last tips is the most interesting to me. So here is a quiz. Let&#8217;s say I move my laptop from the office to the bedroom to watch a movie. Let&#8217;s assume that&#8217;s the only case I unplug and replug the battery charger. Considering each move is 1/20 of a cycle, how many movies can I watch before getting to the 300 cycles limit? (Hint: remember to take into account that the morning after I have to bring back the laptop to the office). </p>
<p>A <a href="http://www.marco.org/195827279">related post</a> from Marco Arment (with a more serious ending :).</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://spreadingfunkyness.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://spreadingfunkyness.com/the-tale-of-my-macbook-pro-battery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>6 Tutorials on Copy&amp;Paste and Drag&amp;Drop in Adobe Air</title>
		<link>http://spreadingfunkyness.com/6-tutorials-on-copypaste-and-dragdrop-in-adobe-air/</link>
		<comments>http://spreadingfunkyness.com/6-tutorials-on-copypaste-and-dragdrop-in-adobe-air/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 13:32:20 +0000</pubDate>
		<dc:creator>Cesare</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[adobeair]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://spreadingfunkyness.com/?p=308</guid>
		<description><![CDATA[I recently published a series of tutorials around the topic of &#8220;moving stuff&#8221; across Adobe Air applications (via copy&#038;paste and drag&#038;drop). Here is the complete list of all the tutorials. Native Drag and Drop in Adobe Air The first tutorial, to get started with drag and drop. Drag and Drop of Text in Adobe Air ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin: 0px 10px 0px 0px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fspreadingfunkyness.com%2F6-tutorials-on-copypaste-and-dragdrop-in-adobe-air%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fspreadingfunkyness.com%2F6-tutorials-on-copypaste-and-dragdrop-in-adobe-air%2F&amp;source=_funkyboy&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>I recently published a series of tutorials around the topic of &#8220;moving stuff&#8221; across Adobe Air applications (via copy&#038;paste and drag&#038;drop). Here is the complete list of all the tutorials.</p>
<ul>
<li><a href="http://spreadingfunkyness.com/native-drag-and-drop-in-adobe-air/">Native Drag and Drop in Adobe Air</a><br />
The first tutorial, to get started with drag and drop.</li>
<li><a href="http://spreadingfunkyness.com/drag-and-drop-of-text-in-adobe-air/">Drag and Drop of Text in Adobe Air</a><br />
An overview of how to drag and drop textual content in Adobe Air.</li>
<li><a href="http://spreadingfunkyness.com/drag-and-drop-of-images-in-adobe-air/">Drag and Drop of Images In Adobe Air</a><br />
A tutorial on drag and drop from OS to Adobe air and across Air apps.</li>
<li><a href="http://spreadingfunkyness.com/copy-and-paste-images-in-adobe-air/">Copy and Paste Images in Adobe Air</a><br />
The first tutorial on copy and paste, focused on images.</li>
<li><a href="http://spreadingfunkyness.com/copy-and-paste-a-complex-object-in-adobe-air/">Copy and Paste a complex object in Adobe Air</a><br />
Description of how to move a custom object across Adobe Air applications.
</li>
<li><a href="http://spreadingfunkyness.com/copy-and-paste-sets-of-complex-objects-in-adobe-air/">Copy and Paste Sets of Complex Objects in Adobe Air</a><br />
A tutorial about how to copy and paste arrays of custom objects.
</li>
</ul>
<p>I am planning to release more series about Adobe Air/Flex. Any topic your prefer? Leave a comment below or contact me.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://spreadingfunkyness.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://spreadingfunkyness.com/6-tutorials-on-copypaste-and-dragdrop-in-adobe-air/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Copy and Paste Sets of Complex Objects in Adobe Air</title>
		<link>http://spreadingfunkyness.com/copy-and-paste-sets-of-complex-objects-in-adobe-air/</link>
		<comments>http://spreadingfunkyness.com/copy-and-paste-sets-of-complex-objects-in-adobe-air/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 13:37:27 +0000</pubDate>
		<dc:creator>Cesare</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[adobeair]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://spreadingfunkyness.com/?p=306</guid>
		<description><![CDATA[This is a followup post to the <a href="http://spreadingfunkyness.com/copy-and-paste-a-complex-object-in-adobe-air/">previous one</a>, where we have seen how to copy and paste a complex object across two Adobe Air applications. We will see how to copy and paste more than one object from an Adobe Air application to another]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin: 0px 10px 0px 0px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fspreadingfunkyness.com%2Fcopy-and-paste-sets-of-complex-objects-in-adobe-air%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fspreadingfunkyness.com%2Fcopy-and-paste-sets-of-complex-objects-in-adobe-air%2F&amp;source=_funkyboy&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>This is a followup post to the <a href="http://spreadingfunkyness.com/copy-and-paste-a-complex-object-in-adobe-air/">previous one</a>, where we have seen how to copy and paste a complex object across two Adobe Air applications. We will see how to copy and paste more than one object from an Adobe Air application to another. First of all we have to enable multiple selection in our Datagrid, that&#8217;s easy.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:DataGrid id=<span style="color: #ff0000;">&quot;grid&quot;</span> 
	dataProvider=<span style="color: #ff0000;">&quot;{collection}&quot;</span>
	allowMultipleSelection=<span style="color: #ff0000;">&quot;true&quot;</span> <span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>We then modify the function that copies data to the clipboard. Instead of a single element we want the list of the selected items in the datagrid (line 3).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> copyToClipboard<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">selection</span>:ArrayCollection = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span>grid.<span style="color: #006600;">selectedItems</span><span style="color: #66cc66;">&#41;</span>;
	Clipboard.<span style="color: #006600;">generalClipboard</span>.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	Clipboard.<span style="color: #006600;">generalClipboard</span>.<span style="color: #006600;">setData</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myCustomFormat&quot;</span>, <span style="color: #0066CC;">selection</span><span style="color: #66cc66;">&#41;</span>;
	feedback.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Data copied to the clipboard&quot;</span>;
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>The rest of the code remains the same of the <a href="http://spreadingfunkyness.com/copy-and-paste-a-complex-object-in-adobe-air/">previous tutorial</a>. The destination application needs a bit more of tweaking to handle an array of items. We have to store data in an ArrayCollection (line 2,5). At this point we could set up a renderer and a repeater to populate the form, but let&#8217;s have some fun with actionscript (lines 8-31).</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
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> const <span style="color: #0066CC;">HEIGHT</span>:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">20</span>;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> myItems:ArrayCollection;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> pasteFromClipboard<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	myItems = Clipboard.<span style="color: #006600;">generalClipboard</span>.<span style="color: #006600;">getData</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myCustomFormat&quot;</span><span style="color: #66cc66;">&#41;</span> 
		as ArrayCollection;
&nbsp;
	<span style="color: #b1b100;">for</span> each <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> i <span style="color: #b1b100;">in</span> myItems<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">var</span> nameLabel:FormItem = <span style="color: #000000; font-weight: bold;">new</span> FormItem<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		nameLabel.<span style="color: #006600;">label</span> = <span style="color: #ff0000;">&quot;Name:&quot;</span>;
		<span style="color: #000000; font-weight: bold;">var</span> nameText:TextArea = <span style="color: #000000; font-weight: bold;">new</span> TextArea<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		nameText.<span style="color: #0066CC;">height</span> = <span style="color: #0066CC;">HEIGHT</span>;
		nameText.<span style="color: #0066CC;">text</span> = i.<span style="color: #0066CC;">name</span>;
&nbsp;
		<span style="color: #000000; font-weight: bold;">var</span> emailLabel:FormItem = <span style="color: #000000; font-weight: bold;">new</span> FormItem<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		emailLabel.<span style="color: #006600;">label</span> = <span style="color: #ff0000;">&quot;Email&quot;</span>;
		<span style="color: #000000; font-weight: bold;">var</span> emailText:TextArea = <span style="color: #000000; font-weight: bold;">new</span> TextArea<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		emailText.<span style="color: #0066CC;">height</span> = <span style="color: #0066CC;">HEIGHT</span>;
		emailText.<span style="color: #0066CC;">text</span> = i.<span style="color: #006600;">email</span>;
&nbsp;
		nameLabel.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>nameText<span style="color: #66cc66;">&#41;</span>;
		emailLabel.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>emailText<span style="color: #66cc66;">&#41;</span>;
&nbsp;
		pastedItems.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>nameLabel<span style="color: #66cc66;">&#41;</span>;
		pastedItems.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>emailLabel<span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #000000; font-weight: bold;">var</span> hr:HRule = <span style="color: #000000; font-weight: bold;">new</span> HRule<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		hr.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">40</span>;
		pastedItems.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>hr<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Here is an example of the final result.</p>
<p><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr_1116090935.swf' /><param name='flashvars' value='i=42503' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr_1116090935.swf' flashvars='i=42503' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></p>
<p><a href='http://spreadingfunkyness.com/wp-content/uploads/2010/01/ComplexMultiCopyPaste.zip'>Source code is available.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://spreadingfunkyness.com/copy-and-paste-sets-of-complex-objects-in-adobe-air/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Copy and Paste a complex object in Adobe Air</title>
		<link>http://spreadingfunkyness.com/copy-and-paste-a-complex-object-in-adobe-air/</link>
		<comments>http://spreadingfunkyness.com/copy-and-paste-a-complex-object-in-adobe-air/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 11:49:32 +0000</pubDate>
		<dc:creator>Cesare</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[adobeair]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://spreadingfunkyness.com/?p=304</guid>
		<description><![CDATA[In Adobe Air you can store data in the object to enable cross application data transfer. We have already had a look at how to copy and paste images. In this tutorial we will see how to copy complex objects. By complex objects we mean a type of object which is not the usual String, ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin: 0px 10px 0px 0px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fspreadingfunkyness.com%2Fcopy-and-paste-a-complex-object-in-adobe-air%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fspreadingfunkyness.com%2Fcopy-and-paste-a-complex-object-in-adobe-air%2F&amp;source=_funkyboy&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>In Adobe Air you can store data in the object to enable cross application data transfer. We have already had a look at <a href="http://spreadingfunkyness.com/copy-and-paste-images-in-adobe-air/">how to copy and paste images</a>. In this tutorial we will see how to copy complex objects. By complex objects we mean a type of object which is not the usual String, but something a bit more complicated, like an instance of Person.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Person <span style="color: #0066CC;">extends</span> <span style="color: #0066CC;">Object</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span>;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">var</span> email:<span style="color: #0066CC;">String</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Person<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span>, email:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">name</span> = <span style="color: #0066CC;">name</span>;
		<span style="color: #0066CC;">this</span>.<span style="color: #006600;">email</span> = email;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>We will create two Adobe Air apps: the first is the source from which we copy data, the second is the destination where we paste data in the clipboard. Let&#8217;s start with the source application. We create some instance of Person to populate an ArrayCollection which we feed into a DataGrid.</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
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:WindowedApplication 
	xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> 
	layout=<span style="color: #ff0000;">&quot;vertical&quot;</span> 
	creationComplete=<span style="color: #ff0000;">&quot;init()&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
&nbsp;
		<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> 
                <span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> collection:ArrayCollection = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			collection.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;John&quot;</span>, <span style="color: #ff0000;">&quot;john@john.com&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
			collection.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Mary&quot;</span>, <span style="color: #ff0000;">&quot;mary@mary.com&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:DataGrid id=<span style="color: #ff0000;">&quot;grid&quot;</span> 
		dataProvider=<span style="color: #ff0000;">&quot;{collection}&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;/</span>mx:DataGrid<span style="color: #66cc66;">&gt;</span>
&nbsp;
<span style="color: #66cc66;">&lt;/</span>mx:WindowedApplication<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>We will add a button to trigger the copy action of the selected item. Then we need a way to detect the selected item in the grid and store it into the clipboard. We do this in the copyToClipboard function.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> copyToClipboard<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">selection</span>:Person = grid.<span style="color: #006600;">selectedItem</span> as Person;
	Clipboard.<span style="color: #006600;">generalClipboard</span>.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	Clipboard.<span style="color: #006600;">generalClipboard</span>.<span style="color: #006600;">setData</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myCustomFormat&quot;</span>, <span style="color: #0066CC;">selection</span><span style="color: #66cc66;">&#41;</span>;
	feedback.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Data copied to the clipboard&quot;</span>;
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>Here we should remember to be consistent with the key, <code>myCustomFormat</code>, that we adopt to store data in the clipboard (line 5). We&#8217;ll use the same key when we want to retrieve data in the Destination application. Below is the complete code of the Source application.</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
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:WindowedApplication 
	xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> 
	layout=<span style="color: #ff0000;">&quot;vertical&quot;</span> 
	creationComplete=<span style="color: #ff0000;">&quot;init()&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
	<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">collections</span>.<span style="color: #006600;">ArrayCollection</span>;
&nbsp;
	<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> 
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> collection:ArrayCollection = <span style="color: #000000; font-weight: bold;">new</span> ArrayCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		collection.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;John&quot;</span>, <span style="color: #ff0000;">&quot;john@john.com&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		collection.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Mary&quot;</span>, <span style="color: #ff0000;">&quot;mary@mary.com&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> copyToClipboard<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">selection</span>:Person = grid.<span style="color: #006600;">selectedItem</span> as Person;
		Clipboard.<span style="color: #006600;">generalClipboard</span>.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		Clipboard.<span style="color: #006600;">generalClipboard</span>.<span style="color: #006600;">setData</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myCustomFormat&quot;</span>, <span style="color: #0066CC;">selection</span><span style="color: #66cc66;">&#41;</span>;
		feedback.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Data copied to the clipboard&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:DataGrid id=<span style="color: #ff0000;">&quot;grid&quot;</span> 
		dataProvider=<span style="color: #ff0000;">&quot;{collection}&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;/</span>mx:DataGrid<span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Copy to Clipboad&quot;</span> 
		<span style="color: #0066CC;">enabled</span>=<span style="color: #ff0000;">&quot;{grid.selectedItem != null}&quot;</span> 
		click=<span style="color: #ff0000;">&quot;copyToClipboard()&quot;</span><span style="color: #66cc66;">/&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Text</span> id=<span style="color: #ff0000;">&quot;feedback&quot;</span> <span style="color: #66cc66;">/&gt;</span>
&nbsp;
<span style="color: #66cc66;">&lt;/</span>mx:WindowedApplication<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Now let&#8217;s move to the Destination application, which we will have just a form and a button to paste data.</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
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:WindowedApplication 
	xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> 
	layout=<span style="color: #ff0000;">&quot;vertical&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
&nbsp;
	<span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span> 
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> myObj:<span style="color: #0066CC;">Object</span>;
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> pasteFromClipboard<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		myObj = Clipboard.<span style="color: #006600;">generalClipboard</span>.<span style="color: #006600;">getData</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myCustomFormat&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>mx:Form<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Name:&quot;</span><span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>mx:TextArea <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;{myObj.name}&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;20&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:FormItem label=<span style="color: #ff0000;">&quot;Email:&quot;</span><span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>mx:TextArea <span style="color: #0066CC;">text</span>=<span style="color: #ff0000;">&quot;{myObj.email}&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;20&quot;</span><span style="color: #66cc66;">/&gt;</span>
		<span style="color: #66cc66;">&lt;/</span>mx:FormItem<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:Form<span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Paste&quot;</span> click=<span style="color: #ff0000;">&quot;pasteFromClipboard()&quot;</span><span style="color: #66cc66;">/&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:WindowedApplication<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>As said above, to retrieve data in the clipboard we have to use the same key, <code>myCustomFormat</code>. The binding does the rest, populating our form. Here is a video of the result.</p>
<p><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr_1116090935.swf' /><param name='flashvars' value='i=41246' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr_1116090935.swf' flashvars='i=41246' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></p>
<p><a href='http://spreadingfunkyness.com/wp-content/uploads/2010/01/ComplexCopyPaste.zip'>Source code</a> is available.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://spreadingfunkyness.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://spreadingfunkyness.com/copy-and-paste-a-complex-object-in-adobe-air/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Copy and Paste Images in Adobe Air</title>
		<link>http://spreadingfunkyness.com/copy-and-paste-images-in-adobe-air/</link>
		<comments>http://spreadingfunkyness.com/copy-and-paste-images-in-adobe-air/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 12:30:31 +0000</pubDate>
		<dc:creator>Cesare</dc:creator>
				<category><![CDATA[actionscript]]></category>
		<category><![CDATA[adobeair]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://spreadingfunkyness.com/?p=298</guid>
		<description><![CDATA[How to copy and paste images in Adobe Air.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin: 0px 10px 0px 0px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fspreadingfunkyness.com%2Fcopy-and-paste-images-in-adobe-air%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fspreadingfunkyness.com%2Fcopy-and-paste-images-in-adobe-air%2F&amp;source=_funkyboy&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>After learning <a href="http://spreadingfunkyness.com/drag-and-drop-of-images-in-adobe-air/">drag</a> and <a href="http://spreadingfunkyness.com/drag-and-drop-of-text-in-adobe-air/">drop</a> we will dig into copy and paste. We have <a href="http://spreadingfunkyness.com/native-drag-and-drop-in-adobe-air/">already seen</a> how to use the clipboard class to temporary store data during the drag action. Now we will use the same class to copy and paste an image within an Adobe Air application. We will start with the following layout.</p>
<p><a href="http://spreadingfunkyness.com/wp-content/uploads/2010/01/layout.gif"><img src="http://spreadingfunkyness.com/wp-content/uploads/2010/01/layout.gif" alt="" title="Layout of the application" width="500" height="397" class="aligncenter size-full wp-image-299" align="center" /></a></p>
<p>This corresponds to the following mxml code.</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
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:WindowedApplication 
	xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> 
	<span style="color: #0066CC;">backgroundColor</span>=<span style="color: #ff0000;">&quot;#222222&quot;</span> <span style="color: #0066CC;">color</span>=<span style="color: #ff0000;">&quot;#f5f5f5&quot;</span> 
	layout=<span style="color: #ff0000;">&quot;vertical&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;!</span>-- Feedback --<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Text</span> id=<span style="color: #ff0000;">&quot;feedback&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;20&quot;</span><span style="color: #66cc66;">/&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;!</span>-- Image to <span style="color: #0066CC;">copy</span> --<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>mx:Image id=<span style="color: #ff0000;">&quot;im&quot;</span> source=<span style="color: #ff0000;">&quot;logo.png&quot;</span><span style="color: #66cc66;">/&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;!</span>-- Commands --<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>mx:HBox<span style="color: #66cc66;">&gt;</span>
	    <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;copy&quot;</span> 
	 	click=<span style="color: #ff0000;">&quot;copyToClipboard()&quot;</span><span style="color: #66cc66;">/&gt;</span>
	    <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;paste&quot;</span> 
		click=<span style="color: #ff0000;">&quot;pasteFromClipboard()&quot;</span><span style="color: #66cc66;">/&gt;</span>	
	    <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;clear&quot;</span> 
		click=<span style="color: #ff0000;">&quot;Clipboard.generalClipboard.clearData(ClipboardFormats.BITMAP_FORMAT)&quot;</span><span style="color: #66cc66;">/&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:HBox<span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:VBox id=<span style="color: #ff0000;">&quot;copies&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;{im.width}&quot;</span><span style="color: #66cc66;">/&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:WindowedApplication<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Let&#8217;s have a look at the copy mechanism. We want to be sure that, before copying, the clipboard has no bitmap (line 3). Then we create a BitmapData object to store the content of the image (lines 4-5) and we put it in the clipboard (line 6). We gently provide some feedback (line 7).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> copyToClipboard<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
    Clipboard.<span style="color: #006600;">generalClipboard</span>.<span style="color: #006600;">clearData</span><span style="color: #66cc66;">&#40;</span>ClipboardFormats.<span style="color: #006600;">BITMAP_FORMAT</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">data</span>:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>im.<span style="color: #0066CC;">width</span>, im.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #0066CC;">data</span>.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span>im<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// this copies the content in the clipboard</span>
    Clipboard.<span style="color: #006600;">generalClipboard</span>.<span style="color: #006600;">setData</span><span style="color: #66cc66;">&#40;</span>ClipboardFormats.<span style="color: #006600;">BITMAP_FORMAT</span>, <span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
    feedback.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Data have been copied&quot;</span>;
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>The paste mechanism is pretty similar to the one illustrated in <a href="http://spreadingfunkyness.com/drag-and-drop-of-text-in-adobe-air/">previous tutorials</a>.  We read data from the clipboard (line 3), create a new Image class to store the Bitmap and then add it to the duplicates area (lines 4-7).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> pasteFromClipboard<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">var</span> b:Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>Clipboard.<span style="color: #006600;">generalClipboard</span>.<span style="color: #006600;">getData</span><span style="color: #66cc66;">&#40;</span>ClipboardFormats.<span style="color: #006600;">BITMAP_FORMAT</span><span style="color: #66cc66;">&#41;</span> as BitmapData<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #000000; font-weight: bold;">var</span> i:Image = <span style="color: #000000; font-weight: bold;">new</span> Image<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    i.<span style="color: #0066CC;">height</span> = b.<span style="color: #0066CC;">height</span>;
    i.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">&#41;</span>;
    copies.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p>This is the intended result.</p>
<p><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr_1116090935.swf' /><param name='flashvars' value='i=40450' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr_1116090935.swf' flashvars='i=40450' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></p>
<p><a href='http://spreadingfunkyness.com/wp-content/uploads/2010/01/ImageCopyAndPaste.zip'>Source code</a>  is available.<br />
Next time we will see how to copy and paste a complex object.</p>
]]></content:encoded>
			<wfw:commentRss>http://spreadingfunkyness.com/copy-and-paste-images-in-adobe-air/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Drag and Drop of Images In Adobe Air</title>
		<link>http://spreadingfunkyness.com/drag-and-drop-of-images-in-adobe-air/</link>
		<comments>http://spreadingfunkyness.com/drag-and-drop-of-images-in-adobe-air/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 12:04:36 +0000</pubDate>
		<dc:creator>Cesare</dc:creator>
				<category><![CDATA[adobeair]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://spreadingfunkyness.com/?p=296</guid>
		<description><![CDATA[In this tutorial we will see how to show images dragged from the file system into an Adobe Air application. As we have seen in other tutorials to intercept when something is dragged and dropped on an Adobe Air application we need to specify two handlers: nativeDragEnter and nativeDragDrop. To accept the drag&#038;drop the content ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin: 0px 10px 0px 0px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fspreadingfunkyness.com%2Fdrag-and-drop-of-images-in-adobe-air%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fspreadingfunkyness.com%2Fdrag-and-drop-of-images-in-adobe-air%2F&amp;source=_funkyboy&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>In this tutorial we will see how to show images dragged from the file system into an Adobe Air application. As we have seen in <a href="http://spreadingfunkyness.com/drag-and-drop-of-text-in-adobe-air/">other</a> <a href="http://spreadingfunkyness.com/native-drag-and-drop-in-adobe-air/">tutorials</a> to intercept when something is dragged and dropped on an Adobe Air application we need to specify two handlers: <code>nativeDragEnter</code> and <code>nativeDragDrop</code>. To accept the drag&#038;drop the content of the clipboard has to be a list of files (line 12). When there is a drop we store the content in an array (line 18). For each element of the array we check the extension (png in our case) and we create an image object, which we add to a tile list (lines 20-26).</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
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:WindowedApplication xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> 
    layout=<span style="color: #ff0000;">&quot;vertical&quot;</span> 
    nativeDragEnter=<span style="color: #ff0000;">&quot;dragEnterHandler(event)&quot;</span> 
    nativeDragDrop=<span style="color: #ff0000;">&quot;dropHandler(event)&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
    <span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
&nbsp;
        <span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">controls</span>.<span style="color: #006600;">Image</span>;
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> dragEnterHandler<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:NativeDragEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">clipboard</span>.<span style="color: #006600;">hasFormat</span><span style="color: #66cc66;">&#40;</span>ClipboardFormats.<span style="color: #006600;">FILE_LIST_FORMAT</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		NativeDragManager.<span style="color: #006600;">acceptDragDrop</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
	    <span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> dropHandler<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:NativeDragEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	    <span style="color: #000000; font-weight: bold;">var</span> files:<span style="color: #0066CC;">Array</span> = <span style="color: #0066CC;">e</span>.<span style="color: #006600;">clipboard</span>.<span style="color: #006600;">getData</span><span style="color: #66cc66;">&#40;</span>ClipboardFormats.<span style="color: #006600;">FILE_LIST_FORMAT</span><span style="color: #66cc66;">&#41;</span> as <span style="color: #0066CC;">Array</span>;
&nbsp;
	    <span style="color: #b1b100;">for</span> each <span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">var</span> f:<span style="color: #0066CC;">Object</span> <span style="color: #b1b100;">in</span> files<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	  	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>f.<span style="color: #006600;">extension</span> == <span style="color: #ff0000;">&quot;png&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		    <span style="color: #000000; font-weight: bold;">var</span> image:Image = <span style="color: #000000; font-weight: bold;">new</span> Image<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		    image.<span style="color: #006600;">source</span> = <span style="color: #ff0000;">&quot;file:///&quot;</span> + f.<span style="color: #006600;">nativePath</span>
		    droppedImages.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>image<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	    <span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
&nbsp;
    <span style="color: #66cc66;">&lt;</span>mx:Tile id=<span style="color: #ff0000;">&quot;droppedImages&quot;</span> <span style="color: #66cc66;">/&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:WindowedApplication<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>The result should look something like this video.</p>
<p><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr_1116090935.swf' /><param name='flashvars' value='i=39801' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr_1116090935.swf' flashvars='i=39801' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></p>
<p><a href='http://spreadingfunkyness.com/wp-content/uploads/2010/01/NativeImageDragAndDrop.zip'>Source code</a> is available.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://spreadingfunkyness.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://spreadingfunkyness.com/drag-and-drop-of-images-in-adobe-air/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Drag and Drop of Text in Adobe Air</title>
		<link>http://spreadingfunkyness.com/drag-and-drop-of-text-in-adobe-air/</link>
		<comments>http://spreadingfunkyness.com/drag-and-drop-of-text-in-adobe-air/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 13:42:05 +0000</pubDate>
		<dc:creator>Cesare</dc:creator>
				<category><![CDATA[adobeair]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://spreadingfunkyness.com/?p=294</guid>
		<description><![CDATA[In a previous tutorial we have seen how to drag and drop images from a native application (Fireworks) to Adobe Air and between two air apps. In this post I will show how to drag and drop text from a document (pdf, html, txt) into a text area of an Adobe Air application. Our application ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin: 0px 10px 0px 0px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fspreadingfunkyness.com%2Fdrag-and-drop-of-text-in-adobe-air%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fspreadingfunkyness.com%2Fdrag-and-drop-of-text-in-adobe-air%2F&amp;source=_funkyboy&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>In a <a href="http://spreadingfunkyness.com/native-drag-and-drop-in-adobe-air/">previous tutorial</a> we have seen how to drag and drop images from a native application (Fireworks) to Adobe Air and between two air apps. In this post I will show how to drag and drop text from a document (pdf, html, txt) into a text area of an Adobe Air application.<br />
Our application has to specify two handlers: <code>nativeDragEnter</code> and <code>nativeDragDrop</code> (lines 3-4). In the first we will check whether the content in the clipboard is textual (lines 11-12), in the second we will dump the content in a Text component (line 17).</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
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:WindowedApplication xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> 
    layout=<span style="color: #ff0000;">&quot;vertical&quot;</span> 
    nativeDragEnter=<span style="color: #ff0000;">&quot;dragEnterHandler(event)&quot;</span> 
    nativeDragDrop=<span style="color: #ff0000;">&quot;dropHandler(event)&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
    <span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> dragEnterHandler<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:NativeDragEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	    <span style="color: #808080; font-style: italic;">// check whether content is textual</span>
	    <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">clipboard</span>.<span style="color: #006600;">hasFormat</span><span style="color: #66cc66;">&#40;</span>ClipboardFormats.<span style="color: #006600;">TEXT_FORMAT</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	 	NativeDragManager.<span style="color: #006600;">acceptDragDrop</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
	    <span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> dropHandler<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:NativeDragEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
	    droppedText.<span style="color: #0066CC;">text</span> = <span style="color: #0066CC;">e</span>.<span style="color: #006600;">clipboard</span>.<span style="color: #006600;">getData</span><span style="color: #66cc66;">&#40;</span>ClipboardFormats.<span style="color: #006600;">TEXT_FORMAT</span><span style="color: #66cc66;">&#41;</span> as <span style="color: #0066CC;">String</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
    <span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
&nbsp;
    <span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Text</span> id=<span style="color: #ff0000;">&quot;droppedText&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #66cc66;">/&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:WindowedApplication<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Let&#8217;s check whether it works!</p>
<p><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr_1116090935.swf' /><param name='flashvars' value='i=39210' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr_1116090935.swf' flashvars='i=39210' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></p>
<p>Happy drag&#038;dropping :)<br />
<a href='http://spreadingfunkyness.com/wp-content/uploads/2010/01/NativeTextDragAndDrop.zip'>Source code</a> is available.<br />
In the next tutorial we will see how to drag and drop images from the file system.<br />
Stay tuned.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://spreadingfunkyness.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://spreadingfunkyness.com/drag-and-drop-of-text-in-adobe-air/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Native Drag and Drop in Adobe Air</title>
		<link>http://spreadingfunkyness.com/native-drag-and-drop-in-adobe-air/</link>
		<comments>http://spreadingfunkyness.com/native-drag-and-drop-in-adobe-air/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 12:06:37 +0000</pubDate>
		<dc:creator>Cesare</dc:creator>
				<category><![CDATA[adobeair]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://spreadingfunkyness.com/?p=292</guid>
		<description><![CDATA[In this tutorial we will learn the basics of native drag and drop in Adobe Air. Specifically we will see two examples: drag an image from a native application (Fireworks) and drop it onto an air application drag an image from an air application and drop it onto another air application We will start by ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin: 0px 10px 0px 0px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fspreadingfunkyness.com%2Fnative-drag-and-drop-in-adobe-air%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fspreadingfunkyness.com%2Fnative-drag-and-drop-in-adobe-air%2F&amp;source=_funkyboy&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>In this tutorial we will learn the basics of native drag and drop in Adobe Air. Specifically we will see two examples:</p>
<ul>
<li>drag an image from a native application (Fireworks) and drop it onto an air application</li>
<li>drag an image from an air application and drop it onto another air application</li>
</ul>
<p>We will start by implementing the target application, which accepts the drop action. To enable this there are two behaviors to specify: what to do when something is dragged over the app and what to do when there is a drop action. These correspond to two events: nativeDragEnter and nativeDragDrop, both belonging to the WindowedApplication class. So we will start with this code.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:WindowedApplication 
        xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> 
        layout=<span style="color: #ff0000;">&quot;absolute&quot;</span> 
	nativeDragEnter=<span style="color: #ff0000;">&quot;dragEnterHandler(event)&quot;</span> 
	nativeDragDrop=<span style="color: #ff0000;">&quot;dropHandler(event)&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
<span style="color: #66cc66;">&lt;/</span>mx:WindowedApplication<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>Once associated the handlers we need to define them.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> dragEnterHandler<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:NativeDragEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #006600;">clipboard</span>.<span style="color: #006600;">hasFormat</span><span style="color: #66cc66;">&#40;</span>ClipboardFormats.<span style="color: #006600;">BITMAP_FORMAT</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			NativeDragManager.<span style="color: #006600;">acceptDragDrop</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> dropHandler<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:NativeDragEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">data</span>:BitmapData = <span style="color: #0066CC;">e</span>.<span style="color: #006600;">clipboard</span>.<span style="color: #006600;">getData</span><span style="color: #66cc66;">&#40;</span>ClipboardFormats.<span style="color: #006600;">BITMAP_FORMAT</span><span style="color: #66cc66;">&#41;</span> as BitmapData;
		<span style="color: #000000; font-weight: bold;">var</span> myBit:Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">stage</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>myBit<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
      <span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>In the nativeDragEnter event we have to check whether the dragged item is of type bitmap, if yes we can accept the drag (lines 29-30). During the drag a copy of the item is stored in the system&#8217;s clipboard. To replicate it in the target application we have to read it (line 35), clone it (line 36) and then add it to the display tree (line 37). This is all we need to do in the target application. At this point we can already test the application. Let&#8217;s run it, open an image in Fireworks and drag&#038;drop it. See the video below.</p>
<p><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr_1116090935.swf' ></param><param name='flashvars' value='i=38951' ></param><param name='allowFullScreen' value='true' ></param><embed src='http://screenr.com/Content/assets/screenr_1116090935.swf' flashvars='i=38951' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer' ></embed></object></p>
<p>Now let&#8217;s move to the other case: we start dragging an image from another air application. Here we have to mimic the behavior of Fireworks above: copy in the system clipboard the image when there is a startDrag action. Let&#8217;s start  by adding an image to the application.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:WindowedApplication 
	xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> 
	layout=<span style="color: #ff0000;">&quot;absolute&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:Image id=<span style="color: #ff0000;">&quot;image&quot;</span> 
		source=<span style="color: #ff0000;">&quot;logo.png&quot;</span> 
		mouseDown=<span style="color: #ff0000;">&quot;startDragDrop(event)&quot;</span><span style="color: #66cc66;">/&gt;</span> 
<span style="color: #66cc66;">&lt;/</span>mx:WindowedApplication<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>As you can see we attached a function to the mouseDown event. Now let&#8217;s define this function.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> startDragDrop<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:MouseEvent<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">data</span>:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>image.<span style="color: #0066CC;">width</span>, image.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">data</span>.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span>image<span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">// create my clipboard object to be passed to dragmanager</span>
		<span style="color: #000000; font-weight: bold;">var</span> cb:Clipboard = <span style="color: #000000; font-weight: bold;">new</span> Clipboard<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		cb.<span style="color: #006600;">setData</span><span style="color: #66cc66;">&#40;</span>ClipboardFormats.<span style="color: #006600;">BITMAP_FORMAT</span>, <span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">// data here is a 'representative' of the dragged object during dragging.</span>
		NativeDragManager.<span style="color: #006600;">doDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, cb, <span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>; 
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span></pre></td></tr></table></div>

<p>We create a copy of the image (lines 25-26). We use this in two cases: to put it in a clipboard object (line 30) and to provide feedback during the dragging (line 33). Now we can run both applications and check if everything is correct. </p>
<p><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0' width='560' height='345'><param name='movie' value='http://screenr.com/Content/assets/screenr_1116090935.swf' /><param name='flashvars' value='i=38956' /><param name='allowFullScreen' value='true' /><embed src='http://screenr.com/Content/assets/screenr_1116090935.swf' flashvars='i=38956' allowFullScreen='true' width='560' height='345' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object></p>
<p>Simple uh? Please drop a comment if you have any followup question.<br />
<a href='http://spreadingfunkyness.com/wp-content/uploads/2010/01/NativeDragDrop.zip'>Source code</a> is available.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://spreadingfunkyness.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://spreadingfunkyness.com/native-drag-and-drop-in-adobe-air/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
