<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>

<channel>
	<title>Tiago&#039;s Weblog &#187; Flash</title>
	<atom:link href="http://blog.six4rty.ch/tag/flash/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.six4rty.ch</link>
	<description>Code &#38; Technology Aficionado - Come for the Flash, stay for more!</description>
	<lastBuildDate>Tue, 01 Nov 2011 14:06:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
		<item>
		<title>another blog, more authors</title>
		<link>http://blog.six4rty.ch/2011/03/22/another-blog-more-authors/</link>
		<comments>http://blog.six4rty.ch/2011/03/22/another-blog-more-authors/#comments</comments>
		<pubDate>Tue, 22 Mar 2011 08:08:21 +0000</pubDate>
		<dc:creator>Tiago</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[AS3.0]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[opensource]]></category>

		<guid isPermaLink="false">http://blog.six4rty.ch/?p=1062</guid>
		<description><![CDATA[Two weeks ago me and my fellow co-workers have started our company blog which can be reached at http://blog.publicis-modem.ch every open source initiative, project or library that we create will be published there. I might do a cross link to a blog post or even write a little more about it, but I think you [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.publicis-modem.ch"><img class="alignnone size-full wp-image-1065" title="blogModem" src="http://blog.six4rty.ch/wp-content/uploads/2011/03/blogModem.jpg" alt="" width="620" height="252" /></a></p>
<p>Two weeks ago me and my fellow co-workers have started our company blog which can be reached at<br />
<a href="http://blog.publicis-modem.ch" target="_blank">http://blog.publicis-modem.ch</a> every open source initiative, project or library that we create will be published there.<br />
I might do a cross link to a blog post or even write a little more about it, but I think you should keep an eye over there aswell, we already released two opensource projects (<a href="http://opensource.publicis-modem.ch/websvn/listing.php?repname=Open+Source+at+Publicis+Modem+Repository&amp;path=%2Fwallago%2Ftrunk%2Fsrc%2F&amp;#a820ba52e91ea86abf879a04967ee2ccc" target="_blank">wallaGo </a>and <a href="http://opensource.publicis-modem.ch/websvn/listing.php?repname=Open+Source+at+Publicis+Modem+Repository&amp;path=%2Fas3square%2Ftrunk%2Fsrc%2F&amp;#a8ac9b707f5b226f9b5e414505c42f451" target="_blank">AS3Square</a>) and there is more to come soon, so stay tuned for some fresh content and don&#8217;t forget to bookmark a new fresh blog.</p>
<div style="padding-top:5px;padding-right:0px;padding-bottom:5px;padding-left:0px;;">
											<iframe
												style="height:25px !important; border:0px solid gray !important; overflow:hidden !important; width:550px !important;" frameborder="0" scrolling="no" allowTransparency="true"
												src="http://www.linksalpha.com/social?blog=Tiago%26%23039%3Bs+Weblog&link=http%253A%252F%252Fblog.six4rty.ch%252F2011%252F03%252F22%252Fanother-blog-more-authors%252F&title=another+blog%2C+more+authors&desc=%0D%0A%0D%0ATwo+weeks+ago+me+and+my+fellow+co-workers+have+started+our+company+blog+which+can+be+reached+at%0D%0Ahttp%3A%2F%2Fblog.publicis-modem.ch+every+open+source+initiative%2C+project+or+library+that+we+create+will+&fc=333333&fs=arial&fblname=like&fblref=facebook&fbllang=en_US&fblshow=1&fbsbutton=1&fbsctr=1&fbslang=en&fbsendbutton=1&twbutton=1&twlang=en&twmention=six4rty&twrelated1=&twrelated2=&twctr=1&lnkdshow=show&lnkdctr=1&buzzbutton=1&buzzlang=en&buzzctr=0&diggbutton=1&diggctr=0&stblbutton=1&stblctr=0&g1button=1&g1ctr=1&g1lang=en-US">
											</iframe>
										</div>]]></content:encoded>
			<wfw:commentRss>http://blog.six4rty.ch/2011/03/22/another-blog-more-authors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
	</item>
		<item>
		<title>gotoAndSki(); is over and..</title>
		<link>http://blog.six4rty.ch/2011/02/06/gotoandski-is-over-and/</link>
		<comments>http://blog.six4rty.ch/2011/02/06/gotoandski-is-over-and/#comments</comments>
		<pubDate>Sun, 06 Feb 2011 11:34:16 +0000</pubDate>
		<dc:creator>Tiago</dc:creator>
				<category><![CDATA[Meetings]]></category>
		<category><![CDATA[Review]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://blog.six4rty.ch/?p=1044</guid>
		<description><![CDATA[&#8230; it feels very bad, why? Just to mention a few reasons, the people, the scenery, the people, the snowboarding, have I already mentioned the people? yep, besides Flash At The Lake 09 there was no conference that I loved so much, It was such an awesome time talking with some great cool people, it [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.six4rty.ch/wp-content/uploads/2010/12/gotoski1.jpg"><img class="size-full wp-image-966 alignleft" title="gotoski" src="http://blog.six4rty.ch/wp-content/uploads/2010/12/gotoski1.jpg" alt="" width="620" height="252" /></a></p>
<p>&#8230; it feels very bad, why? Just to mention a few reasons, the people, the scenery, the people, the snowboarding, have I already mentioned the people?<br />
yep, besides Flash At The Lake 09 there was no conference that I loved so much, It was such an awesome time talking with some great cool people, it was a laid back conference with<br />
lots of time for networking, snowboarding, and simply having fun. Let me recap for your what happened and how I experienced it.<span id="more-1044"></span></p>
<p><strong>Day T-1:</strong><br />
Yep, I&#8217;ve driven up to Stechelberg a day before the Conference officially started together with Mihai Corlan which I had the opportunity of picking up at the Airport and having<br />
a very relaxed drive to the mountains with some very good talks not only geeky but very inspiring and fun. After arriving at the Location, people started to walk in ( there were already a few though ),<br />
and we had a great time getting to know each other and to learn about what others do, very constructive and inspiring, if it wasn&#8217;t for the <a href="http://www.flickr.com/photos/uselesspics/5391295487/in/pool-gotoandskiswitzerland#/photos/uselesspics/5391295487/in/pool-1568756@N25/" target="_blank">late night obligatory speaker snowball fight at 3am</a></p>
<p><strong>Day 1:</strong><br />
First day on the slopes, first day of the conference, after a very relaxing snowboarding day with <a href="http://twitter.com/riccastelhano" target="_blank">@riccastelhano</a>, <a href="http://twitter.com/masdennis" target="_blank">@masdennis</a>, <a href="http://twitter.com/starnut" target="_blank">@starnut,</a> <a href="http://twitter.com/johanlopes" target="_blank">@johanlopes </a>and<a href="http://twitter.com/agens" target="_blank"> @agens</a> as you can see <a href="http://www.flickr.com/photos/25190572@N05/5406817547/in/pool-gotoandskiswitzerland#/photos/25190572@N05/5406817547/in/pool-1568756@N25/" target="_blank">here</a>, the conference started late but very interesting with the opening speech of <a href="http://twitter.com/mcorlan">@mcorlan</a> on <em>Building Mobile Apps with Adobe AIR</em>, followed by <a href="http://twitter.com/agens" target="_blank">@agens</a> speech on <em>Making Flash Games</em> where he showed an awesome ski jump game which attracted a sick amount of gamers, Peter also presented <a href="http://agens.no/2011/01/fungrid/" target="_blank">FunGrid </a>an opensource flash game API, almost at midnight <a href="http://twitter.com/mcorlan" target="_blank">@mcorlan</a> had the last speech of the day/night where he showed some great AIR/P2P examples as well some tips &amp; tricks on his session <em>Optimizing your Flash/AIR Application</em>. Same as last night, it didn&#8217;t end very early and in this place I would like to thank Otto &amp; and his service for keeping us awake with some booze and especially to stay awake with us at such late time.</p>
<p><strong>Day 2:</strong><br />
Apart from the usual awesome weather in Stechelberg, just have a look at this awful pics, <a href="http://www.flickr.com/photos/imhugo/5408571207/in/pool-gotoandskiswitzerland" target="_blank">here</a>, <a href="http://www.flickr.com/photos/imhugo/5409180462/in/pool-gotoandskiswitzerland#/photos/imhugo/5409180462/in/pool-1568756@N25/" target="_blank">here</a>, <a href="http://www.flickr.com/photos/imhugo/5409180462/in/pool-gotoandskiswitzerland#/photos/imhugo/5409180462/in/pool-1568756@N25/" target="_blank">here</a>, <a href="http://www.flickr.com/photos/25190572@N05/5407471200/in/pool-gotoandskiswitzerland#/photos/25190572@N05/5407471200/in/pool-1568756@N25/" target="_blank">here</a>, <a href="http://www.flickr.com/photos/25190572@N05/5406854327/in/pool-gotoandskiswitzerland#/photos/25190572@N05/5406854327/in/pool-1568756@N25/" target="_blank">here</a>, <a href="http://www.flickr.com/photos/25190572@N05/5406817547/in/pool-gotoandskiswitzerland#/photos/25190572@N05/5406817547/in/pool-1568756@N25/" target="_blank">here</a>, <a href="http://www.flickr.com/photos/25190572@N05/5407408414/in/pool-gotoandskiswitzerland#/photos/25190572@N05/5407408414/in/pool-1568756@N25/" target="_blank">here </a>and if you don&#8217;t have enough of it, <a href="http://www.flickr.com/groups/gotoandskiswitzerland/" target="_blank">here the complete Album</a>. Everybody was pretty much on time to attend <a href="http://twitter.com/masdennis" target="_blank">@masdennis</a> awesome presentation on <em>Messing with Actionscript and the Kinect</em> then as the Dinner arrived, <a href="http://twitter.com/fcolaco">@fcolaco</a> had a surprise prepared for us especially for visitors outside of Switzerland, the local yodeler group made a show for us and you shouldn&#8217;t miss this one, <a href="http://vimeo.com/19413117" target="_blank">The Yodelers at gotoAndSki();</a> after their show, the conference continued its normal path and <a href="http://twitter.com/starnut" target="_blank">@starnut</a> was up on the stage for his talk titled <em>Hot Wireless Data Fudge</em> where he speaks about all kinds of wireless communication while developing for AIR on mobile and on the desktop, again quite late it was my turn to present <em>Developing for TV with AIR</em>, where @fcolaco <a href="http://vimeo.com/19514168" target="_blank">grounded me for not behaving</a> don&#8217;t remember why though but I think it was okay to do so.</p>
<p><strong>Day 3 &amp; Last Day:<br />
</strong>Yep, this pretty much sucks, everybody knew that this was the last day of the conference and everyone was sad about it as well, nevertheless, <a href="http://twitter.com/dctrl">@dctrl </a><a href="http://twitter.com/starnut" target="_blank">@starnut</a> and me decided to have a blast on the slopes and do some snowboarding the last day, which again was wonderful due to the awesome weather in the mountains, this time we had to start a bit earlier as some attendees were living that night.<br />
First of all <a href="http://twitter.com/trinefalbe" target="_blank">@trinefalbe</a> stepped up the stage with her talk on <em>Cognitive Psychology in Interactive Design</em> a very very good talk which I really enjoyed and I recommend this one to all of you designing Flash Applications, Websites, or even if you are not a Flash Developer, have a look at it as soon as her video is online. After Trine we had to speed up things a little and instaed of having dinner <a href="http://twitter.com/riccastelhano" target="_blank">@riccastelhano</a> was up on the stage doing his talk on <em>Flash + Arduino: a connection with Feelings</em>, again a very inspiring talk with funny moments and great shows, as well it wakened up the electronical guy in me, just need to get my hands on a bunch of boards and start building my own stuff, I think our good friend <a href="http://twitter.com/inoutin" target="_blank">Maciek &#8220;Feel happy like a pig in the mud&#8221; Wcislik</a> aka <a href="http://twitter.com/inoutin" target="_blank">@inoutin</a> had the same thoughts like me.<br />
Last but not least our very own <a href="http://twitter.com/sfug" target="_blank">SFUG </a>co-manager <a href="http://twitter.com/_sandro" target="_blank">@_sandro</a> was up on the stage talking about <em>Advanced Flash Accessibility</em> a great talk as usual and how could it be different, Sandro released a new opensource library called <a href="http://wiki.swfjunkie.com/jacc" target="_blank">JAcc </a>that will help every flash developer enabling Accessibility in their Flash Projects. That was it gotoAndSki(); was officially over and everyone was feeling sad about it.</p>
<p>At the end it was one of the best conferences I&#8217;ve attended in the past, not only because there was some snowboarding involved, no, <a href="http://twitter.com/fcolaco">@fcolaco</a> and <a href="http://twitter.com/almeidavid_" target="_blank">@almeidavid_</a>made a great conference in the swiss alps porting the concept from norway to switzerland, I had a blast meeting all these people, which now became friends, I can&#8217;t describe well enough how the conference was, I think the best would be to check out the <a href="http://twitter.com/#!/search?q=%23gotoAndSki" target="_blank">tweets from the first week after the event</a> by then you will be mad that you didn&#8217;t attend this event but you will know where you are going to be next year when it&#8217;s time for gotoAndSki(&#8220;switzerland&#8221;); 2012.</p>
<p>Below some of the tweets that I think really explain how the conference was:</p>
<blockquote><p>I guess good networking is when you think &#8220;I miss this guys&#8221; instead of just &#8220;I made this business contacts&#8221;. Damn <a title="#gotoAndSki" rel="nofollow" href="http://twitter.com/#%21/search?q=%23gotoAndSki"><strong>#gotoAndSki</strong></a> nostalgia&#8230;<br />
@fcolaco</p>
<p>Blog:  Two thumbs up for <a title="#gotoAndSki" rel="nofollow" href="http://twitter.com/#%21/search?q=%23gotoAndSki"><strong>#gotoAndSki</strong></a>(&#8216;Switzerland&#8217;) <a title="http://www.trinefalbe.com/?p=690" rel="nofollow" href="http://www.trinefalbe.com/?p=690" target="_blank">http://www.trinefalbe.com/?p=690<br />
</a>@trinefalbe<a title="http://www.trinefalbe.com/?p=690" rel="nofollow" href="http://www.trinefalbe.com/?p=690" target="_blank"></a></p>
<p>Walking through the streets of Lisbon. &#8220;Need to catch fresh air&#8221;, my brain says. I guess it&#8217;s a <a title="#gotoAndSki" rel="nofollow" href="http://twitter.com/#%21/search?q=%23gotoAndSki"><strong>#gotoAndSki</strong></a> secon&#8230; <a title="http://picplz.com/user/imhugo/pic/ntf8/" rel="nofollow" href="http://picplz.com/FvSV" target="_blank">http://picplz.com/FvSV</a><br />
@imhugo</p>
<div>
<div>Me too! RT @<a rel="nofollow" href="http://twitter.com/RicCastelhano">RicCastelhano</a>: may I return to the Swiss Alps ?? May I, please? Pretty please? <a title="#gotoandski" rel="nofollow" href="http://twitter.com/#%21/search?q=%23gotoandski"><strong>#gotoandski</strong></a> aftermath<br />
@jenschr</div>
</div>
</blockquote>
<div>Once again I would like to thank Fernando for the opportunity of speaking at the first gotoAndSki(); event in Switzerland, as well David for helping organizing such a great event and last but not least all attendees and speakers that made the conference as great as it was. One thing is sure I&#8217;ll be there again in 2012 if as Speaker or not, you too?</div>
<div style="padding-top:5px;padding-right:0px;padding-bottom:5px;padding-left:0px;;">
											<iframe
												style="height:25px !important; border:0px solid gray !important; overflow:hidden !important; width:550px !important;" frameborder="0" scrolling="no" allowTransparency="true"
												src="http://www.linksalpha.com/social?blog=Tiago%26%23039%3Bs+Weblog&link=http%253A%252F%252Fblog.six4rty.ch%252F2011%252F02%252F06%252Fgotoandski-is-over-and%252F&title=gotoAndSki%28%29%3B+is+over+and..&desc=%0D%0A%0D%0A...+it+feels+very+bad%2C+why%3F+Just+to+mention+a+few+reasons%2C+the+people%2C+the+scenery%2C+the+people%2C+the+snowboarding%2C+have+I+already+mentioned+the+people%3F%0D%0Ayep%2C+besides+Flash+At+The+Lake+09+there+was+&fc=333333&fs=arial&fblname=like&fblref=facebook&fbllang=en_US&fblshow=1&fbsbutton=1&fbsctr=1&fbslang=en&fbsendbutton=1&twbutton=1&twlang=en&twmention=six4rty&twrelated1=&twrelated2=&twctr=1&lnkdshow=show&lnkdctr=1&buzzbutton=1&buzzlang=en&buzzctr=0&diggbutton=1&diggctr=0&stblbutton=1&stblctr=0&g1button=1&g1ctr=1&g1lang=en-US">
											</iframe>
										</div>]]></content:encoded>
			<wfw:commentRss>http://blog.six4rty.ch/2011/02/06/gotoandski-is-over-and/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
	</item>
		<item>
		<title>my session at gotoAndSki();</title>
		<link>http://blog.six4rty.ch/2011/01/09/my-session-at-gotoandski/</link>
		<comments>http://blog.six4rty.ch/2011/01/09/my-session-at-gotoandski/#comments</comments>
		<pubDate>Sun, 09 Jan 2011 21:11:26 +0000</pubDate>
		<dc:creator>Tiago</dc:creator>
				<category><![CDATA[Meetings]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://blog.six4rty.ch/?p=1017</guid>
		<description><![CDATA[Just 17 more days to gotoAndSki(); the swiss edition in Stechelberg, a good time to present what I&#8217;m going to talk about during my session called &#8220;Developing AIR for TV&#8221;. During these 45 minutes, you are going to learn how to develop AIR content for Television, starting from a simple videoplayer using the new StageVideo [...]]]></description>
			<content:encoded><![CDATA[<p><img title="gotoski" src="http://blog.six4rty.ch/wp-content/uploads/2010/12/gotoski1.jpg" alt="" width="620" height="252" /></p>
<p>Just 17 more days to <a href="http://switzerland.gotoandski.com/">gotoAndSki();</a> the swiss edition in Stechelberg, a good time to present what I&#8217;m going to talk about during my session called &#8220;Developing AIR for TV&#8221;.<span id="more-1017"></span></p>
<p>During these 45 minutes, you are going to learn how to develop AIR content for Television, starting from a simple videoplayer using the new StageVideo classes (StageCraft) to a simple Remote Controlled Slideshowviewer, up to a P2P multiplayer game which can be played with different control devices like the TV remote that comes along with your TV device or with any Android 2.2 with Adobe AIR powered Device. All these examples and a few more hints on optimization and design considerations are being showed during this session.</p>
<p>I hope to see a bunch of you up in the mountains of beautiful Lauterbrunnen,<a href="http://switzerland.gotoandski.com/" target="_blank"> gotoAndSki(); </a>tickets are limited to approx 100 attendees, and as far as I know there are not much comfort tickets left, so if you want to experience an awesome event with the beautiful swiss alps and a bunch of flash / flex guys having fun in the slopes, then jump right over to the <a href="http://switzerland.gotoandski.com/" target="_blank">gotoAndSki();</a> site and book your ticket now.</p>
<p>See you there!<br />
Tiago</p>
<div style="padding-top:5px;padding-right:0px;padding-bottom:5px;padding-left:0px;;">
											<iframe
												style="height:25px !important; border:0px solid gray !important; overflow:hidden !important; width:550px !important;" frameborder="0" scrolling="no" allowTransparency="true"
												src="http://www.linksalpha.com/social?blog=Tiago%26%23039%3Bs+Weblog&link=http%253A%252F%252Fblog.six4rty.ch%252F2011%252F01%252F09%252Fmy-session-at-gotoandski%252F&title=my+session+at+gotoAndSki%28%29%3B&desc=%0D%0A%0D%0AJust+17+more+days+to+gotoAndSki%28%29%3B+the+swiss+edition+in+Stechelberg%2C+a+good+time+to+present+what+I%27m+going+to+talk+about+during+my+session+called+%22Developing+AIR+for+TV%22.%0D%0A%0D%0ADuring+these+45+minute&fc=333333&fs=arial&fblname=like&fblref=facebook&fbllang=en_US&fblshow=1&fbsbutton=1&fbsctr=1&fbslang=en&fbsendbutton=1&twbutton=1&twlang=en&twmention=six4rty&twrelated1=&twrelated2=&twctr=1&lnkdshow=show&lnkdctr=1&buzzbutton=1&buzzlang=en&buzzctr=0&diggbutton=1&diggctr=0&stblbutton=1&stblctr=0&g1button=1&g1ctr=1&g1lang=en-US">
											</iframe>
										</div>]]></content:encoded>
			<wfw:commentRss>http://blog.six4rty.ch/2011/01/09/my-session-at-gotoandski/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
	</item>
		<item>
		<title>Android-AS3: Accelerometer</title>
		<link>http://blog.six4rty.ch/2010/11/21/android-as3-accelerometer/</link>
		<comments>http://blog.six4rty.ch/2010/11/21/android-as3-accelerometer/#comments</comments>
		<pubDate>Sun, 21 Nov 2010 18:04:22 +0000</pubDate>
		<dc:creator>Tiago</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA["burrito"]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.six4rty.ch/?p=889</guid>
		<description><![CDATA[You bought an Android phone because you want to start developing a cool flash or AIR App for that device? Or you just wondering how easy it is to develop an application for those target devices? In the following series, I&#8217;m going to show you how to access those special properties that are available when [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.six4rty.ch/wp-content/uploads/2010/11/as3mobile.jpg"><img class="alignleft size-medium wp-image-890" style="margin: 10px;" title="as3mobile" src="http://blog.six4rty.ch/wp-content/uploads/2010/11/as3mobile-300x270.jpg" alt="" width="168" height="151" /></a>You bought an Android phone because you want to start developing a cool flash or AIR App for that device?<br />
Or you just wondering how easy it is to develop an application for those target devices?</p>
<p>In the following series, I&#8217;m going to show you how to access those special properties that are available when developing for an Android or any other Flash / AIR powered device.</p>
<p>Today, we start with the <strong>Accelerometer API</strong>.</p>
<p>In this article I&#8217;m going to show you how to control a simple ball with the help of the accelerometer API. Clearly you could create a game like the well known <a rel="lightbox" href="http://blog.six4rty.ch/wp-content/uploads/2010/11/labyrinth.jpg">Labyrinth</a> available for the iOS or <a rel="lightbox" href="http://blog.six4rty.ch/wp-content/uploads/2010/11/teeter.jpg">Teeter</a> available on the HTC android devices very easy as soon as you know how to master the Accelerometer API.<br />
<span id="more-889"></span></p>
<p>Before we start just a heads up that you can follow this article even if you work with Flash CS5 although working with Flash Builder &#8220;Burrito&#8221; makes your life much easier.</p>
<p>To start let&#8217;s create a new Flash Builder &#8220;actionscript mobile project&#8221; called: &#8220;<strong>AccelerometerBall</strong>&#8220;.  Setup the project how you like it, just be sure that you enable full screen.</p>
<p>Now that you are ready to go we first check if an accelerometer is available, if none is available then it&#8217;s not worth of continuing the game, but if it&#8217;s available we add the sphere to the stage which we want to control. You can add whatever you want, i&#8217;m just using a simple sphere I created in Photoshop to be my indicator.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> Accelerometer.<span style="color: #006600;">isSupported</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    _accelerometer = <span style="color: #000000; font-weight: bold;">new</span> Accelerometer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    _accelerometer.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> AccelerometerEvent.<span style="color: #006600;">UPDATE</span>, onAccelUpdate <span style="color: #66cc66;">&#41;</span>;
&nbsp;
    _sphere = <span style="color: #000000; font-weight: bold;">new</span> sphereClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
    _sphere.<span style="color: #006600;">scaleX</span> = _sphere.<span style="color: #006600;">scaleY</span> = .2;
    addChild<span style="color: #66cc66;">&#40;</span> _sphere <span style="color: #66cc66;">&#41;</span>;
&nbsp;
    addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, moveSphere <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #808080; font-style: italic;">//display message to user that accelerometer is not available</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>When you test the application at this point, you will not see your sphere unless your developer machine has an accelerometer in place, which I doubt <img src='http://blog.six4rty.ch/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>So to properly test it, you should debug your application on your mobile phone, now if you are on Flash CS5 you can use Device Central to simulate the normal behavior of  a mobile phone, Flash Builder &#8220;Burrito&#8221; users can deploy and debug directly from the Flash Builder Interface, to do that, just simply create a new Run configuration and setup as following.<br />
<a rel="lightbox" href="http://blog.six4rty.ch/wp-content/uploads/2010/11/runMobile.jpg"><img title="runMobile" src="http://blog.six4rty.ch/wp-content/uploads/2010/11/runMobile-150x150.jpg" alt="" width="150" height="150" /></a></p>
<p>When debugging the application on your phone you should now be able to see the sphere you placed in stage.</p>
<p>Next on let&#8217;s move on to the usage of the Accelerometer API.</p>
<p>To move our sphere, we simply need to take the accelerometers x &amp; y event, have a look at the code below:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">protected <span style="color: #000000; font-weight: bold;">function</span> onAccelUpdate<span style="color: #66cc66;">&#40;</span> event:AccelerometerEvent <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
     _targetX = event.<span style="color: #006600;">accelerationX</span> <span style="color: #66cc66;">*</span> _factor;
     _targetY = event.<span style="color: #006600;">accelerationY</span> <span style="color: #66cc66;">*</span> _factor;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
protected <span style="color: #000000; font-weight: bold;">function</span> moveSphere<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
      _sphere.<span style="color: #006600;">x</span> -= _targetX;
      _sphere.<span style="color: #006600;">y</span> += _targetY;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>If you now test your applcation on your device or in Device Central you should see your sphere moving around on your screen.<br />
As you see every time an update of accelerometer is being dispatched the new position is being saved in the _targetX &amp; _targetY variable, thanks to the EnterFrame we move our sphere around the stage.</p>
<p>Here the complete code for you to review:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Bitmap</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">StageAlign</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">StageScaleMode</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">AccelerometerEvent</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">sensors</span>.<span style="color: #006600;">Accelerometer</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AcceleroBall <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;sphere.png&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> sphereClass:<span style="color: #000000; font-weight: bold;">Class</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _sphere			:Bitmap;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _factor			:uint			= <span style="color: #cc66cc;">50</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _accelerometer		:Accelerometer;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _targetX			:<span style="color: #0066CC;">Number</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _targetY			:<span style="color: #0066CC;">Number</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AcceleroBall<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			setup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> setup<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> Accelerometer.<span style="color: #006600;">isSupported</span> <span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				_accelerometer = <span style="color: #000000; font-weight: bold;">new</span> Accelerometer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				_accelerometer.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> AccelerometerEvent.<span style="color: #006600;">UPDATE</span>, onAccelUpdate <span style="color: #66cc66;">&#41;</span>;
&nbsp;
				_sphere = <span style="color: #000000; font-weight: bold;">new</span> sphereClass<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				_sphere.<span style="color: #006600;">scaleX</span> = _sphere.<span style="color: #006600;">scaleY</span> = .2;
				addChild<span style="color: #66cc66;">&#40;</span> _sphere <span style="color: #66cc66;">&#41;</span>;
&nbsp;
				addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ENTER_FRAME</span>, moveSphere <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #b1b100;">else</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #808080; font-style: italic;">//display message to user that accelerometer is not available</span>
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> onAccelUpdate<span style="color: #66cc66;">&#40;</span> event:AccelerometerEvent <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_targetX = event.<span style="color: #006600;">accelerationX</span> <span style="color: #66cc66;">*</span> _factor;
			_targetY = event.<span style="color: #006600;">accelerationY</span> <span style="color: #66cc66;">*</span> _factor;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		protected <span style="color: #000000; font-weight: bold;">function</span> moveSphere<span style="color: #66cc66;">&#40;</span>event:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_sphere.<span style="color: #006600;">x</span> -= _targetX;
			_sphere.<span style="color: #006600;">y</span> += _targetY;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Now it&#8217;s up on you to create the boundaries, some holes on the floor, and there you go you have your first Flash Game.</p>
<p>If you have questions, don&#8217;t hesitate to comment on this post.</p>
<div style="padding-top:5px;padding-right:0px;padding-bottom:5px;padding-left:0px;;">
											<iframe
												style="height:25px !important; border:0px solid gray !important; overflow:hidden !important; width:550px !important;" frameborder="0" scrolling="no" allowTransparency="true"
												src="http://www.linksalpha.com/social?blog=Tiago%26%23039%3Bs+Weblog&link=http%253A%252F%252Fblog.six4rty.ch%252F2010%252F11%252F21%252Fandroid-as3-accelerometer%252F&title=Android-AS3%3A+Accelerometer&desc=You+bought+an+Android+phone+because+you+want+to+start+developing+a+cool+flash+or+AIR+App+for+that+device%3F%0D%0AOr+you+just+wondering+how+easy+it+is+to+develop+an+application+for+those+target+devices%3F%0D%0A%0D%0AI&fc=333333&fs=arial&fblname=like&fblref=facebook&fbllang=en_US&fblshow=1&fbsbutton=1&fbsctr=1&fbslang=en&fbsendbutton=1&twbutton=1&twlang=en&twmention=six4rty&twrelated1=&twrelated2=&twctr=1&lnkdshow=show&lnkdctr=1&buzzbutton=1&buzzlang=en&buzzctr=0&diggbutton=1&diggctr=0&stblbutton=1&stblctr=0&g1button=1&g1ctr=1&g1lang=en-US">
											</iframe>
										</div>]]></content:encoded>
			<wfw:commentRss>http://blog.six4rty.ch/2010/11/21/android-as3-accelerometer/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
	</item>
		<item>
		<title>AS3: Embed specific characters (part.2)</title>
		<link>http://blog.six4rty.ch/2010/08/23/as3-embed-specific-characters-part-2/</link>
		<comments>http://blog.six4rty.ch/2010/08/23/as3-embed-specific-characters-part-2/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 21:44:38 +0000</pubDate>
		<dc:creator>Tiago</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Quick Hints]]></category>
		<category><![CDATA[Utils]]></category>
		<category><![CDATA[AS3.0]]></category>
		<category><![CDATA[Font]]></category>

		<guid isPermaLink="false">http://blog.six4rty.ch/?p=840</guid>
		<description><![CDATA[Just as a quick update, I&#8217;ve updated the previously created unicode finder app, to be a bit more helpful for the everyday usage. Here a list of things that have been changed: No double unicodes. Automatic generation of embed code, easy for you to copy &#38; paste directly into your application. One thing that I [...]]]></description>
			<content:encoded><![CDATA[<p>Just as a quick update, I&#8217;ve updated the previously created unicode finder app, to be a bit more helpful for the everyday usage.<br />
Here a list of things that have been changed:</p>
<ul>
<li>No double unicodes.</li>
<li>Automatic generation of embed code, easy for you to copy &amp; paste directly into your application.</li>
</ul>
<p>One thing that I can&#8217;t handle for you is to define the source of the font with it&#8217;s according fontname as defined in your system, but hey if I find a way around this, I will update it.</p>
<p>And again if you would like to play around with it, here the app. Have fun!</p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="616" height="494">
      <param name="movie" value="http://blog.six4rty.ch/wp-content/uploads/2010/08/UnicodeFinder1.swf" />
      <param name="allowfullscreen" value="true" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://blog.six4rty.ch/wp-content/uploads/2010/08/UnicodeFinder1.swf" width="616" height="494" allowfullscreen="true">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<div style="padding-top:5px;padding-right:0px;padding-bottom:5px;padding-left:0px;;">
											<iframe
												style="height:25px !important; border:0px solid gray !important; overflow:hidden !important; width:550px !important;" frameborder="0" scrolling="no" allowTransparency="true"
												src="http://www.linksalpha.com/social?blog=Tiago%26%23039%3Bs+Weblog&link=http%253A%252F%252Fblog.six4rty.ch%252F2010%252F08%252F23%252Fas3-embed-specific-characters-part-2%252F&title=AS3%3A+Embed+specific+characters+%28part.2%29&desc=Just+as+a+quick+update%2C+I%27ve+updated+the+previously+created+unicode+finder+app%2C+to+be+a+bit+more+helpful+for+the+everyday+usage.%0D%0AHere+a+list+of+things+that+have+been+changed%3A%0D%0A%0D%0A%09No+double+unicodes.%0D&fc=333333&fs=arial&fblname=like&fblref=facebook&fbllang=en_US&fblshow=1&fbsbutton=1&fbsctr=1&fbslang=en&fbsendbutton=1&twbutton=1&twlang=en&twmention=six4rty&twrelated1=&twrelated2=&twctr=1&lnkdshow=show&lnkdctr=1&buzzbutton=1&buzzlang=en&buzzctr=0&diggbutton=1&diggctr=0&stblbutton=1&stblctr=0&g1button=1&g1ctr=1&g1lang=en-US">
											</iframe>
										</div>]]></content:encoded>
			<wfw:commentRss>http://blog.six4rty.ch/2010/08/23/as3-embed-specific-characters-part-2/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
	</item>
		<item>
		<title>AS3: Embed specific characters</title>
		<link>http://blog.six4rty.ch/2010/08/21/as3-embed-specific-characters/</link>
		<comments>http://blog.six4rty.ch/2010/08/21/as3-embed-specific-characters/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 17:40:31 +0000</pubDate>
		<dc:creator>Tiago</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Quick Hints]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Utils]]></category>
		<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Font]]></category>

		<guid isPermaLink="false">http://blog.six4rty.ch/?p=820</guid>
		<description><![CDATA[You might have read on one of my previous tweets, where I was screaming about using &#8220;special&#8221; characters in Flash, with &#8220;special&#8221; I mean arabic, cyrillic, hebrew, chinese simplified and traditional, as well japanese. I know,  I know, there is TLF (Text Layout Framework) that handles the whole text, but I&#8217;m talking about embedding the [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-medium wp-image-724" style="margin: 10px;" title="as3code" src="http://blog.six4rty.ch/wp-content/uploads/2010/07/as3code-300x270.jpg" alt="" width="210" height="189" /></p>
<p>You might have read on one of my previous tweets, where I was screaming about using &#8220;special&#8221; characters in Flash, with &#8220;special&#8221; I mean arabic, cyrillic, hebrew, chinese simplified and traditional, as well japanese.</p>
<p>I know,  I know, there is TLF (Text Layout Framework) that handles the whole text, but I&#8217;m talking about embedding the font, did you knew that the complete chinese Unicode range helds something around 20&#8217;000 characters? You might think so what? Let me tell you that the complete chinese character range is over 7MB big!!! Do you really want to let your viewers download a 7MB file just for the font? No.</p>
<p>So I&#8217;ve created a quick app that will enable you to read out the UTF code from the text you need to use, with it you can specifically embed only the characters you need and take the file size down to a minimum. Now there is only a downside of this method, if the textual content changes a day, you need to again import the new characters.<br />
Apart from that, I haven&#8217;t seen any bad things about this implementation.</p>
<p>At the end of this post you will find an useful small tool to get all the needed characters.<span id="more-820"></span></p>
<p>As an example below with this line you are embedding a font only containing numerals typing 1234567890 will give you a range from U+0030 to U+0039</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">Embed(source=&quot;font_file_name&quot;, fontName=&quot;font_name&quot;, mimeType=&quot;application/x-font-truetype&quot;, unicodeRange=&quot;U+0030-U+0039,U+002E&quot;)]</pre></div></div>

<p>So let&#8217;s assume you would like to write this: <em>&#8220;Nemusíte oči vidět, musíte vidění&#8221;</em> which means <em>&#8220;You don&#8217;t need eyes to see, you need vision&#8221;</em> and only embed the needed characters, you would embed your font like this</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">Embed(source=&quot;font_file_name&quot;, fontName=&quot;font_name&quot;,  mimeType=&quot;application/x-font-truetype&quot;,  unicodeRange=&quot;U+004e, U+0065, U+006d, U+0075, U+0073, U+00ed, U+0074, U+0065, U+0020,  U+006f, U+010d, U+0069, U+0020, U+0076, U+0069, U+0064, U+011b, U+0074,  U+002c, U+0020, U+006d, U+0075, U+0073, U+00ed, U+0074, U+0065, U+0020,  U+0076, U+0069, U+0064, U+011b, U+006e, U+00ed&quot;)]</pre></div></div>

<p>If you don&#8217;t know how to use this kind of font embedding, have a read here:<a href="http://soledadpenades.com/2008/10/21/embedding-fonts-in-actionscript-3-using-flex-sdk/" target="_blank"></p>
<p>http://soledadpenades.com/2008/10/21/embedding-fonts-in-actionscript-3-using-flex-sdk/</a></p>
<p>Test ride it your self and have fun <img src='http://blog.six4rty.ch/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_1" width="616" height="494">
      <param name="movie" value="http://blog.six4rty.ch/wp-content/uploads/2010/08/UnicodeFinder1.swf" />
      <param name="allowfullscreen" value="true" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://blog.six4rty.ch/wp-content/uploads/2010/08/UnicodeFinder1.swf" width="616" height="494" allowfullscreen="true">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<div style="padding-top:5px;padding-right:0px;padding-bottom:5px;padding-left:0px;;">
											<iframe
												style="height:25px !important; border:0px solid gray !important; overflow:hidden !important; width:550px !important;" frameborder="0" scrolling="no" allowTransparency="true"
												src="http://www.linksalpha.com/social?blog=Tiago%26%23039%3Bs+Weblog&link=http%253A%252F%252Fblog.six4rty.ch%252F2010%252F08%252F21%252Fas3-embed-specific-characters%252F&title=AS3%3A+Embed+specific+characters&desc=%0D%0A%0D%0AYou+might+have+read+on+one+of+my+previous+tweets%2C+where+I+was+screaming+about+using+%22special%22+characters+in+Flash%2C+with+%22special%22+I+mean+arabic%2C+cyrillic%2C+hebrew%2C+chinese+simplified+and+traditiona&fc=333333&fs=arial&fblname=like&fblref=facebook&fbllang=en_US&fblshow=1&fbsbutton=1&fbsctr=1&fbslang=en&fbsendbutton=1&twbutton=1&twlang=en&twmention=six4rty&twrelated1=&twrelated2=&twctr=1&lnkdshow=show&lnkdctr=1&buzzbutton=1&buzzlang=en&buzzctr=0&diggbutton=1&diggctr=0&stblbutton=1&stblctr=0&g1button=1&g1ctr=1&g1lang=en-US">
											</iframe>
										</div>]]></content:encoded>
			<wfw:commentRss>http://blog.six4rty.ch/2010/08/21/as3-embed-specific-characters/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
	</item>
		<item>
		<title>Foundation Flash CS5</title>
		<link>http://blog.six4rty.ch/2010/08/08/foundation-flash-cs5/</link>
		<comments>http://blog.six4rty.ch/2010/08/08/foundation-flash-cs5/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 17:32:04 +0000</pubDate>
		<dc:creator>Tiago</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[CS5]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.six4rty.ch/?p=817</guid>
		<description><![CDATA[After 4 years Tom Green and I just published our latest book, this time we are not talking about Flash &#38; After Effects, rather the newest and coolest version since the history of Flash, Adobe&#8217;s Flash CS5. If you are just learning the ins and outs of flash, then this is a book you shouldn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.six4rty.ch/wp-content/uploads/2010/08/9781430229940.jpg"><img class="alignleft size-full wp-image-818" title="9781430229940" src="http://blog.six4rty.ch/wp-content/uploads/2010/08/9781430229940.jpg" alt="" width="200" height="247" /></a>After 4 years Tom Green and I just published our latest book, this time we are not talking about Flash &amp; After Effects, rather the newest and coolest version since the history of Flash, Adobe&#8217;s Flash CS5. If you are just learning the ins and outs of flash, then this is a book you shouldn&#8217;t miss, lots of examples, code snippets, cool projects and even an Android game is being built.</p>
<p>Flash is one of the most engaging, innovative, and versatile  technologies available—allowing the creation of anything from animated  banners and simple cartoons, to Rich Internet Applications, interactive  videos, and dynamic user interfaces for web sites, kiosks, devices, or  DVDs. The possibilities are endless, and now it just got better.</p>
<p>Flash CS5 boasts a host of new features, including the  much-anticipated iPhone application creation feature, a whole new  animation engine enabling full manipulation of tweens and paths, custom  easing, improved inverse kinematics, a revamped timeline, built-in 3D,  and much more.</p>
<p><span id="more-817"></span></p>
<p>This book is all you&#8217;ll need to learn Flash CS5 from the ground up.  If you already have Flash experience, this book will allow you to  quickly catch up on all the cool new features. Flash experts Tom Green  and Tiago Dias guide you step-by-step through all facets of Flash CS5,  keeping the emphasis firmly on good design techniques that you use in  your own projects.</p>
<ul>
<li>Learn Flash design from the ground up, or just get to grips with the new features, with a series of step-by-step tutorials.</li>
<li>Provides an easy introduction to ActionScript 3.0 coding, but the focus is mainly kept on design.</li>
<li>Learn from the experts—written by renowned Flash designers Tom Green and Tiago Dias.</li>
</ul>
<h3>What You&#8217;ll Learn</h3>
<ul>
<li>How to create an iPhone application.</li>
<li>The ins and outs of the Flash CS5 interface</li>
<li>How to use all of Flash CS5&#8242;s essential features, such as text, graphics, and animation</li>
<li>How to use video and sound effectively in Flash</li>
<li>The fundamentals of Flash CS5’s new animation and timeline features</li>
<li>The basics of ActionScript 3.0</li>
<li>How to populate a Flash movie with dynamic data such as XML.</li>
</ul>
<h3>Who this book is for</h3>
<p>This book is for both beginners who want a solid grounding in Flash  CS5, and designers with previous Flash experience, who want to get up to  speed with the new features.</p>
<div style="padding-top:5px;padding-right:0px;padding-bottom:5px;padding-left:0px;;">
											<iframe
												style="height:25px !important; border:0px solid gray !important; overflow:hidden !important; width:550px !important;" frameborder="0" scrolling="no" allowTransparency="true"
												src="http://www.linksalpha.com/social?blog=Tiago%26%23039%3Bs+Weblog&link=http%253A%252F%252Fblog.six4rty.ch%252F2010%252F08%252F08%252Ffoundation-flash-cs5%252F&title=Foundation+Flash+CS5&desc=After+4+years+Tom+Green+and+I+just+published+our+latest+book%2C+this+time+we+are+not+talking+about+Flash+%26amp%3B+After+Effects%2C+rather+the+newest+and+coolest+version+since+the+history+of+Flash%2C+Adobe%27s+Fl&fc=333333&fs=arial&fblname=like&fblref=facebook&fbllang=en_US&fblshow=1&fbsbutton=1&fbsctr=1&fbslang=en&fbsendbutton=1&twbutton=1&twlang=en&twmention=six4rty&twrelated1=&twrelated2=&twctr=1&lnkdshow=show&lnkdctr=1&buzzbutton=1&buzzlang=en&buzzctr=0&diggbutton=1&diggctr=0&stblbutton=1&stblctr=0&g1button=1&g1ctr=1&g1lang=en-US">
											</iframe>
										</div>]]></content:encoded>
			<wfw:commentRss>http://blog.six4rty.ch/2010/08/08/foundation-flash-cs5/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
	</item>
		<item>
		<title>AS3: Multiline textfields and Line Metrics</title>
		<link>http://blog.six4rty.ch/2010/07/31/as3-multiline-textfields-and-line-metrics/</link>
		<comments>http://blog.six4rty.ch/2010/07/31/as3-multiline-textfields-and-line-metrics/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 11:25:25 +0000</pubDate>
		<dc:creator>Tiago</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Quick Hints]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[AS3.0]]></category>
		<category><![CDATA[StringUtil]]></category>
		<category><![CDATA[TextField]]></category>

		<guid isPermaLink="false">http://blog.six4rty.ch/?p=791</guid>
		<description><![CDATA[Last week I had to do something that I never thought of, let me present you the case: First of all we have a multiline, word-wrapped textfield in AS3, the text is picked up from an external XML file and gets styled with a CSS stylesheet, the textfield CAN have one line or multiple lines [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.six4rty.ch/wp-content/uploads/2010/07/as3code.jpg"><img class="alignleft size-medium wp-image-724" style="margin: 10px;" title="as3code" src="http://blog.six4rty.ch/wp-content/uploads/2010/07/as3code-300x270.jpg" alt="" width="210" height="189" /></a>Last week I had to do something that I never thought of, let me present you the case:</p>
<p>First of all we have a multiline, word-wrapped textfield in AS3, the text is picked up from an external XML file and gets styled with a CSS stylesheet, the textfield CAN have one line or multiple lines (depending on the translation and the language used), if the text is only an one-liner, the graphic (a simple small gray arrow) needs to be placed after the text in the middle of the first line, so you are able to visualize this, think about a standard &lt;li&gt; tag where you get the black dot, in my case just at the other side eg. at the end fo the line. have a look at the <a rel="lightbox" href="http://blog.six4rty.ch/wp-content/uploads/2010/07/lastLine.jpg">Example</a> for a visual clarification what I want to achieve.</p>
<p>Basically a simple task, you grab the textlength add the gutter and margin to it and place the small arrow at that position.. but what do you do when the text goes multine and word wraps automatically?<br />
After doing some experiments, I&#8217;ve came up with a simple yet appropriate solution for this.<br />
<span id="more-791"></span>Let&#8217;s start with a simple text field, containing some text and setup for multiline and wordwrapping.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> tf:<span style="color: #0066CC;">TextField</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">TextField</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
tf.<span style="color: #0066CC;">text</span> = <span style="color: #ff0000;">&quot;Lorem Ipsum is simply dummy text of the printing and typesetting industry.&quot;</span>;
tf.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">100</span>;
tf.<span style="color: #0066CC;">multiline</span> = <span style="color: #000000; font-weight: bold;">true</span>;
tf.<span style="color: #0066CC;">wordWrap</span> = <span style="color: #000000; font-weight: bold;">true</span>;
addChild<span style="color: #66cc66;">&#40;</span> tf <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This will display a simple textfield without any formatting with 5 lines of content. Why did I set a width value on my textfield? Well without it, the textfield would just be as wide as the text, resulting in a single line text, and that&#8217;s not what we want.</p>
<p>Now we create a simple square / dot / arrow whatever you like acting as a marker for the end of line, so you can visualize what&#8217;s happening, I&#8217;ve created a small rectangle like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> rect:Sprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
rect.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xff0000<span style="color: #66cc66;">&#41;</span>;
rect.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">10</span>, <span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#41;</span>;
rect.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
addChild<span style="color: #66cc66;">&#40;</span> rect <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Simple rectangle, doesn&#8217;t need much of an explanation, maybe you asking yourself why I&#8217;ve set it at x &amp; y 0? Although I could position the rectangle right at the proper position I always preferred to use the setters of it so I rather create all my shapes/graphs at 0,0 and move them with myShape.x = 100, it makes things more obvious to read and you find it much quicker then doing directly on the drawRect() method.</p>
<p>Next up let&#8217;s have a look at our class that returns the requested values.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> StringUtil
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> _lastChar		:TextLineMetrics;
	<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">_x</span>			:<span style="color: #0066CC;">int</span>;
	<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">_y</span>			:<span style="color: #0066CC;">int</span>;
&nbsp;
	<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">var</span> _gutter		:<span style="color: #0066CC;">int</span> = <span style="color: #cc66cc;">2</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> getEndOfLine<span style="color: #66cc66;">&#40;</span> tf:<span style="color: #0066CC;">TextField</span>, line:<span style="color: #0066CC;">int</span> <span style="color: #66cc66;">&#41;</span>:Point
	<span style="color: #66cc66;">&#123;</span>
		_lastChar 	= tf.<span style="color: #006600;">getLineMetrics</span><span style="color: #66cc66;">&#40;</span>line<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #0066CC;">_x</span>		= tf.<span style="color: #006600;">x</span> + _lastChar.<span style="color: #0066CC;">width</span> + _gutter;
		<span style="color: #0066CC;">_y</span>		= _lastChar.<span style="color: #0066CC;">height</span> <span style="color: #66cc66;">*</span> line  + _lastChar.<span style="color: #006600;">ascent</span>;
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">_x</span>, <span style="color: #0066CC;">_y</span> <span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>What we are doing here is rather simple then you think. First we pass the textfield and the desired line to our static function, then using the getLineMetrics() method we return the desired line&#8217;s metrics, this can now be used to set an x and y position of the to be returned Point(). as you see at the _x value, I&#8217;m just telling it to add the textfields x position to the width of the requested line, at the end we add the gutter value for the textfield.<br />
The vertical position is another story, here we need to get the height of the desired line and multiply with it. this has the reason that there is no method available to get the proper y position of the line, so by multiplying the textheight with the desired line you get the proper y position of it. After that calculation we add the _lastCahr.ascent property of the line, asking what ascent? Take a look at the image below for more information about it but basically it&#8217;s just the length of the baseline to the top of the line height in pixels, so exactly the middle of our text.</p>
<p>Have a look at the image below for a nice and clean overview about the gutter of a flash textfield as well about the other properties a textfield has.</p>
<p><a href="http://blog.six4rty.ch/wp-content/uploads/2010/07/text-metrics.jpg" rel="lightbox"><img class="size-medium wp-image-800 alignnone" title="text-metrics" src="http://blog.six4rty.ch/wp-content/uploads/2010/07/text-metrics-300x200.jpg" alt="" width="180" height="120" /></a></p>
<p>Something you should also be aware of is that the width of the text line is relative to the textfield width, but you need to subtract the gutter width of 4 pixels (2 pixels on each side ).</p>
<p>Now that our class is available let&#8217;s take a look at how I used it for this example.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> point:Point = StringUtil.<span style="color: #006600;">getEndOfLine</span><span style="color: #66cc66;">&#40;</span> tf, tf.<span style="color: #006600;">numLines</span> - <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span>;
rect.<span style="color: #006600;">x</span> = point.<span style="color: #006600;">x</span>;
rect.<span style="color: #006600;">y</span> = point.<span style="color: #006600;">y</span>;</pre></div></div>

<p>What we are doing here is nothing else then creating a new Point based on the position returned by our class, passing the textfield and specially since I want to have the rectangle on the LAST line I just ask for the textfields number of lines &#8211; 1.</p>
<p><a href="http://blog.six4rty.ch/wp-content/uploads/2010/07/lastLine.jpg"><img class="size-full wp-image-794 alignnone" title="lastLine" src="http://blog.six4rty.ch/wp-content/uploads/2010/07/lastLine.jpg" alt="" width="199" height="113" /></a><br />
When running this example above you should see the small red rectangle on the last line of our textfield. yay!!!</p>
<p>You can download the StringUtil class here: <a href="http://blog.six4rty.ch/wp-content/uploads/2010/07/StringUtil.as_.zip">StringUtil.as</a><br />
Hope this serves you as well as it served me last week, and don&#8217;t forget to leave a comment if you have any questions about it.</p>
<div style="padding-top:5px;padding-right:0px;padding-bottom:5px;padding-left:0px;;">
											<iframe
												style="height:25px !important; border:0px solid gray !important; overflow:hidden !important; width:550px !important;" frameborder="0" scrolling="no" allowTransparency="true"
												src="http://www.linksalpha.com/social?blog=Tiago%26%23039%3Bs+Weblog&link=http%253A%252F%252Fblog.six4rty.ch%252F2010%252F07%252F31%252Fas3-multiline-textfields-and-line-metrics%252F&title=AS3%3A+Multiline+textfields+and+Line+Metrics&desc=Last+week+I+had+to+do+something+that+I+never+thought+of%2C+let+me+present+you+the+case%3A%0D%0A%0D%0AFirst+of+all+we+have+a+multiline%2C+word-wrapped+textfield+in+AS3%2C+the+text+is+picked+up+from+an+external+XML+fil&fc=333333&fs=arial&fblname=like&fblref=facebook&fbllang=en_US&fblshow=1&fbsbutton=1&fbsctr=1&fbslang=en&fbsendbutton=1&twbutton=1&twlang=en&twmention=six4rty&twrelated1=&twrelated2=&twctr=1&lnkdshow=show&lnkdctr=1&buzzbutton=1&buzzlang=en&buzzctr=0&diggbutton=1&diggctr=0&stblbutton=1&stblctr=0&g1button=1&g1ctr=1&g1lang=en-US">
											</iframe>
										</div>]]></content:encoded>
			<wfw:commentRss>http://blog.six4rty.ch/2010/07/31/as3-multiline-textfields-and-line-metrics/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
	</item>
		<item>
		<title>AS3: Quickhint: Shared Objects</title>
		<link>http://blog.six4rty.ch/2010/07/24/as3-quick-hint-shared-objects/</link>
		<comments>http://blog.six4rty.ch/2010/07/24/as3-quick-hint-shared-objects/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 16:51:54 +0000</pubDate>
		<dc:creator>Tiago</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Media Server]]></category>
		<category><![CDATA[Quick Hints]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Shared Object]]></category>

		<guid isPermaLink="false">http://blog.six4rty.ch/?p=542</guid>
		<description><![CDATA[Last week while working on the interface for my new upcoming library I needed a way to save some data on the users computer, altough I&#8217;m working with AIR I could easily save an xml or a txt file to the users local computer, but as soon as I would start writing a pure as3 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.six4rty.ch/wp-content/uploads/2010/07/as3code.jpg"><img class="alignleft size-medium wp-image-724" style="margin: 10px;" title="as3code" src="http://blog.six4rty.ch/wp-content/uploads/2010/07/as3code-300x270.jpg" alt="" width="210" height="189" /></a></p>
<p>Last week while working on the interface for my new upcoming library I needed a way to save some data on the users computer, altough I&#8217;m working with AIR I could easily save an xml or a txt file to the users local computer, but as soon as I would start writing a pure as3 project I would have to rewrite it again, as I can&#8217;t be sure that the client will have Flash Player 10 or even the rights to save to it&#8217;s local harddisk, some people working at bigger companies are not allowed to save anything to their local harddisk due to security rights.</p>
<p>The solution for this is simple yet effective, you need to use SharedObjects aka. Cookies in Flash.</p>
<p>Shared Objects can do the following:</p>
<ul>
<li><strong>Maintain Local Persistence</strong>: Saves data locally on the users drive, for example you could save the last application state or the score of the last game, create a local highscore list and many many more applications for local use.</li>
<li><strong>Store and Share Data on FMS</strong>: Basically the same as before, but with the difference that you saving the shared object on a flash media server. Good thing about it, it can be shared throughout multiple computers, the same user using the same application on multiple computers can save its data on a server.</li>
<li><strong>Share data in realtime</strong>: using FMS you can aswell for example save the state of a multiuser application saving the current state of the applcation, every new user will get the current state based on the shared object</li>
</ul>
<p>More information about Shared Objects can be found <a href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/net/SharedObject.html" target="_blank">HERE </a></p>
<p><span id="more-542"></span></p>
<p>Let me show you a few lines of code and explain what you can do with it.</p>
<p>The most basic example is how to write data into a shared object.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> _so:<span style="color: #0066CC;">SharedObject</span>;
_so = <span style="color: #0066CC;">SharedObject</span>.<span style="color: #0066CC;">getLocal</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myLocalData&quot;</span><span style="color: #66cc66;">&#41;</span>;
_so.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">firstname</span> = <span style="color: #ff0000;">&quot;myfirstname&quot;</span>;
_so.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">lastname</span> = <span style="color: #ff0000;">&quot;mylastname&quot;</span>;
_so.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">age</span> = <span style="color: #ff0000;">&quot;30&quot;</span>;
_so.<span style="color: #0066CC;">flush</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>In the example above we create a new variable called _so of the type SharedObject, after that we use the getLocal() method to create the shared object, if no shared object does not already exist it will be created. if the call fails or the parameters passed along are invalid, flash throws an exception. Calling the flush() method the data will be saved to the users local harddisk.</p>
<p>Next up lets see how you can read from a persistent shared object.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> _so:<span style="color: #0066CC;">SharedObject</span>;
_so = <span style="color: #0066CC;">SharedObject</span>.<span style="color: #0066CC;">getLocal</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myLocalData&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span> _so.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">firstname</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">//traces myfirstname</span>
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>_so.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">lastname</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// traces mylastname</span>
<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span>_so.<span style="color: #0066CC;">data</span>.<span style="color: #006600;">age</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// traces 30</span></pre></div></div>

<p>This time we do basically the same as before, but instead of saving data we call data, when calling _so.data.age you are going to grab the sharedobjects property named age which results in 30.</p>
<p>If you rather prefer to save SharedObjects to an FMS, you can use it this way:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> _nc:<span style="color: #0066CC;">NetConnection</span>;
<span style="color: #000000; font-weight: bold;">var</span> _so:<span style="color: #0066CC;">SharedObject</span>;
&nbsp;
_nc = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">NetConnection</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
_nc.<span style="color: #0066CC;">connect</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;rtmp://yourFMSserver/yourAppName&quot;</span><span style="color: #66cc66;">&#41;</span>;
_so = <span style="color: #0066CC;">SharedObject</span>.<span style="color: #006600;">getRemote</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;myRemoteData&quot;</span>, nc.<span style="color: #006600;">uri</span>, <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
_so.<span style="color: #0066CC;">connect</span><span style="color: #66cc66;">&#40;</span> nc <span style="color: #66cc66;">&#41;</span>;
_so.<span style="color: #0066CC;">setProperty</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;names&quot;</span>, <span style="color: #66cc66;">&#123;</span>firstame:myfirstname, lastname:myLastname<span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">&#41;</span>;
_so.<span style="color: #0066CC;">setProperty</span><span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;age&quot;</span>, <span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">&quot;30&quot;</span><span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>This time we create a new NetConnection to the Flash Media Server and it&#8217;s application, calling the getRemote() method acts the same as using the getLocal() method, but you also need to pass the netconnections URI to be able to save the the sharedobject remotely.<br />
Differently from the local version we use the setProperty() method to save data on the remote Shared Object.</p>
<p>These are the basics for handling Shared Objects, if you have any further questions just drop me a line and I might be able to help you out.</p>
<div style="padding-top:5px;padding-right:0px;padding-bottom:5px;padding-left:0px;;">
											<iframe
												style="height:25px !important; border:0px solid gray !important; overflow:hidden !important; width:550px !important;" frameborder="0" scrolling="no" allowTransparency="true"
												src="http://www.linksalpha.com/social?blog=Tiago%26%23039%3Bs+Weblog&link=http%253A%252F%252Fblog.six4rty.ch%252F2010%252F07%252F24%252Fas3-quick-hint-shared-objects%252F&title=AS3%3A+Quickhint%3A+Shared+Objects&desc=%0D%0A%0D%0ALast+week+while+working+on+the+interface+for+my+new+upcoming+library+I+needed+a+way+to+save+some+data+on+the+users+computer%2C+altough+I%27m+working+with+AIR+I+could+easily+save+an+xml+or+a+txt+file+t&fc=333333&fs=arial&fblname=like&fblref=facebook&fbllang=en_US&fblshow=1&fbsbutton=1&fbsctr=1&fbslang=en&fbsendbutton=1&twbutton=1&twlang=en&twmention=six4rty&twrelated1=&twrelated2=&twctr=1&lnkdshow=show&lnkdctr=1&buzzbutton=1&buzzlang=en&buzzctr=0&diggbutton=1&diggctr=0&stblbutton=1&stblctr=0&g1button=1&g1ctr=1&g1lang=en-US">
											</iframe>
										</div>]]></content:encoded>
			<wfw:commentRss>http://blog.six4rty.ch/2010/07/24/as3-quick-hint-shared-objects/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
	</item>
		<item>
		<title>AS3 &amp; Facebook: Uploading Webcam Photos</title>
		<link>http://blog.six4rty.ch/2010/07/17/as3-facebook-uploading-webcam-photos/</link>
		<comments>http://blog.six4rty.ch/2010/07/17/as3-facebook-uploading-webcam-photos/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 12:34:27 +0000</pubDate>
		<dc:creator>Tiago</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[AS3.0]]></category>
		<category><![CDATA[Facebook]]></category>

		<guid isPermaLink="false">http://blog.six4rty.ch/?p=740</guid>
		<description><![CDATA[Facebook.. Could you live without facebook nowadays? Sometimes I&#8217;m happy when I don&#8217;t get anything on facebook, just to have a bit of peace and quiet of it. Well, nevertheless, I&#8217;m writing this article because I&#8217;ve seen this post on the Adobe Forums by dmennenoh where he asked for the possibilities of using the Facebook [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.six4rty.ch/wp-content/uploads/2010/07/as3FB.jpg"><img class="size-medium wp-image-741 alignleft" style="margin: 10px;" title="as3FB" src="http://blog.six4rty.ch/wp-content/uploads/2010/07/as3FB-300x270.jpg" alt="" width="210" height="189" /></a>Facebook.. Could you live without facebook nowadays? Sometimes I&#8217;m happy when I don&#8217;t get anything on facebook, just to have a bit of peace and quiet of it.</p>
<p>Well, nevertheless, I&#8217;m writing this article because I&#8217;ve seen this post on the Adobe Forums by dmennenoh where he asked for the possibilities of using the Facebook AS3 API without Flex or AIR and the possibility of uploading pictures to Facebook.</p>
<p>Short answer: yes, it&#8217;s possible but&#8230;. it&#8217;s not a very well documented process of achieving it.</p>
<p>Before we start, I would like to recommend you a few tutorials on the Adobe Developer Connection, Jeanette Stallons wrote a whole series about the usage of the Facebook AS3 API, and it&#8217;s an absolute must read if you want to start developing flash applications or websites using facebook data and connectivity. First I recommend you starting with the <a href="http://www.adobe.com/devnet/facebook/articles/first_flex_facebook_desktop_app.html" target="_blank">Quick Start</a> to get a feeling for it, after that move on to <a href="http://www.adobe.com/devnet/facebook/articles/first_flex_facebook_web_app_pt1.html" target="_blank">Part 1: Build and Test Locally</a>, <a href="http://www.adobe.com/devnet/facebook/articles/first_flex_facebook_web_app_pt2.html" target="_blank">Part 2: Deploy on Facebook</a> and Part 3: <a href="http://www.adobe.com/devnet/facebook/articles/first_flex_facebook_web_app_pt3.html" target="_blank">Deploy using Facebook Connect</a><span id="more-740"></span></p>
<p>First of all before we start be sure to get the newest FacebookAS3 library, be sure to download the Flash version of it. At this point the current version is <a href="http://code.google.com/p/facebook-actionscript-api/downloads/detail?name=Facebook_library_v3.4_flash.swc" target="_blank">Facebook_library_v3.4_flash.swc</a> you can get newest version on the <a href="http://code.google.com/p/facebook-actionscript-api/" target="_blank">Project page</a>.</p>
<p>As I prefer using <a href="http://www.minimalcomps.com/" target="_blank">MinimalComps</a> by Keith Peters (aka. BIT-101) we are going to download his classes here. If you don&#8217;t know MinimalComps, it&#8217;s a set of components like you know from Flex or the Flash IDE, it contains the default set of components like button, textfield, textarea, but also has various interesting components like dials, calendars, knobs and much much more. I strongly recommend you read through the documentation and work through a few tutorials so you get your hands dirty with it.<br />
Again this is not a MUST-USE, I just feel more comfortable using these then any other components.</p>
<p>I strongly recommend to use the <a href="http://demonsterdebugger.com/" target="_blank">deMonsterDebugger</a> to trace events and data returned from facebook, it has a simple to use interface and is far better then the normal trace() functionality.</p>
<p><strong>1. Setup</strong><br />
1.1 Let&#8217;s start by opening Flash Builder and creating a new Actionscript Project with the name <em><strong>FacebookAS3</strong></em>. We are not going to use any Flex Components neither any AIR methods, you could also build this in the Flash IDE, but I prefer to use Flash Builder for it&#8217;s Code Completion features and it&#8217;s the tool I prefer when coding AS3.</p>
<p>1.2 Import the .SWC file by right clicking on the Project name and selecting <strong>Properties</strong>, then go to <strong>Actionscript Build Path </strong>and<strong> </strong>select the<strong> Library path</strong> tab, press the <strong>Add SWC</strong> button and locate the downloaded facebook_library_flash.swc you downloaded previously. Press OK and we are ready to go.</p>
<p>1.3 If you using MinimalComps for the UserInterface, don&#8217;t forget to import the source to your project so you can use them properly.</p>
<p>1.4 If you using deMonsterDebugger to trace and debug your application, don&#8217;t forget to import the needed classes to your project src folder.</p>
<p><strong>2. Login </strong><br />
Below you will find my main class that handles the whole login procedure of our small application.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const API_KEY	:<span style="color: #0066CC;">String</span>				= <span style="color: #ff0000;">&quot;xxxxx&quot;</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const SECRET	:<span style="color: #0066CC;">String</span>				= <span style="color: #ff0000;">&quot;xxxxx&quot;</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _overlaySprite		:Sprite;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _userInterface		:UserInterface;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _photoBA			:ByteArray;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _fb					:Facebook;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _fbSession			:FacebookSessionUtil;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _userData			:FacebookUser;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _uid				:<span style="color: #0066CC;">String</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _batchCollection	:BatchCollection;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _batchRun			:BatchRun;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _albumArray			:<span style="color: #0066CC;">Array</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _uploadPhoto		:UploadPhoto;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Main<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			MonsterDebugger.<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #ff0000;">&quot;init - Facebook integration&quot;</span> <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">scaleMode</span> = StageScaleMode.<span style="color: #006600;">NO_SCALE</span>;
			<span style="color: #0066CC;">stage</span>.<span style="color: #0066CC;">align</span>		= StageAlign.<span style="color: #006600;">TOP_LEFT</span>;
&nbsp;
			_overlaySprite = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_overlaySprite.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span>0xcccccc, <span style="color: #cc66cc;">0.5</span> <span style="color: #66cc66;">&#41;</span>;
			_overlaySprite.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span>, <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> <span style="color: #66cc66;">&#41;</span>;
			_overlaySprite.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span> _overlaySprite <span style="color: #66cc66;">&#41;</span>;
			_overlaySprite.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;
&nbsp;
			_userInterface				= <span style="color: #000000; font-weight: bold;">new</span> UserInterface<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_userInterface.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">SELECT</span>, uploadImage <span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span> _userInterface <span style="color: #66cc66;">&#41;</span>;
			_userInterface.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;
			login<span style="color: #66cc66;">&#40;</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> login<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_fbSession					= <span style="color: #000000; font-weight: bold;">new</span> FacebookSessionUtil<span style="color: #66cc66;">&#40;</span> API_KEY, SECRET, loaderInfo <span style="color: #66cc66;">&#41;</span>;
			_fb							= _fbSession.<span style="color: #006600;">facebook</span>;
&nbsp;
			_fbSession.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> FacebookEvent.<span style="color: #0066CC;">CONNECT</span>, connectHandle <span style="color: #66cc66;">&#41;</span>;
			_fbSession.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> FacebookEvent.<span style="color: #006600;">WAITING_FOR_LOGIN</span>, loginWaitHandler <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_fbSession.<span style="color: #006600;">login</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> connectHandle<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>:FacebookEvent <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>.<span style="color: #006600;">success</span> <span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				_uid 					= <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">data</span> as GetSessionData <span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">uid</span>;
&nbsp;
				_batchCollection		= <span style="color: #000000; font-weight: bold;">new</span> BatchCollection<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				_batchCollection.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> HasAppPermission<span style="color: #66cc66;">&#40;</span> HasAppPermissionValues.<span style="color: #006600;">PHOTO_UPLOAD</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
				_batchCollection.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> GetInfo<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#91;</span>_uid<span style="color: #66cc66;">&#93;</span>, <span style="color: #66cc66;">&#91;</span>GetInfoFieldValues.<span style="color: #006600;">FIRST_NAME</span>, GetInfoFieldValues.<span style="color: #006600;">CURRENT_LOCATION</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
				_batchCollection.<span style="color: #006600;">addItem</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> GetAlbums<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span>;
&nbsp;
				_batchRun				= _fb.<span style="color: #006600;">post</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> BatchRun<span style="color: #66cc66;">&#40;</span> _batchCollection <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#41;</span> as BatchRun;
				_batchRun.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> FacebookEvent.<span style="color: #006600;">COMPLETE</span>, batchCompleteHandler <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> batchCompleteHandler<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>:FacebookEvent <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;">success</span> <span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> results:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">data</span> as BatchResult <span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">results</span>;
&nbsp;
				<span style="color: #000000; font-weight: bold;">var</span> hasPermission:BooleanResultData = results<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
				<span style="color: #000000; font-weight: bold;">var</span> getInfoResult:GetInfoData = results<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>;
				<span style="color: #000000; font-weight: bold;">var</span> getAlbumsResult:GetAlbumsData = results<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span>;
&nbsp;
				<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span> <span style="color: #66cc66;">!</span>hasPermission.<span style="color: #006600;">value</span> <span style="color: #66cc66;">&#41;</span>
				<span style="color: #66cc66;">&#123;</span>
					MonsterDebugger.<span style="color: #0066CC;">trace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span>, <span style="color: #ff0000;">&quot;no permission&quot;</span> <span style="color: #66cc66;">&#41;</span>;
					getPermissions<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #66cc66;">&#125;</span>
&nbsp;
					<span style="color: #808080; font-style: italic;">/*_userData = getInfoResult.userCollection.getItemAt(0) as FacebookUser;
					_userInterface.username = _userData.first_name + _userData.last_name;
					_userInterface.albumList = getAlbumsResult.albumCollection.toArray();*/</span>
&nbsp;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getPermissions<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_fb.<span style="color: #006600;">grantExtendedPermission</span><span style="color: #66cc66;">&#40;</span> ExtendedPermissionValues.<span style="color: #006600;">PHOTO_UPLOAD</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> uploadImage<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>:Event <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_uploadPhoto = <span style="color: #000000; font-weight: bold;">new</span> UploadPhoto<span style="color: #66cc66;">&#40;</span>_userInterface.<span style="color: #006600;">snapshot</span><span style="color: #66cc66;">&#41;</span>;
			_fb.<span style="color: #006600;">post</span><span style="color: #66cc66;">&#40;</span>_uploadPhoto<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> loginWaitHandler<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>:FacebookEvent <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_overlaySprite.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			_overlaySprite.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">CLICK</span>, confirmConnect <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> confirmConnect<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>
			_overlaySprite.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;
			_userInterface.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			_overlaySprite.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">CLICK</span>, confirmConnect <span style="color: #66cc66;">&#41;</span>;
			_fbSession.<span style="color: #006600;">validateLogin</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Let&#8217;s take a look at what&#8217;s happening here, first of all we create instances of the facebook and the facebooksessionutil classes, those are going to help using Facebook throughout the whole application.<br />
We setup an overlaysprite (this could also be a simple button or an alert panel) that will let us know when the user came back from the facebook login page. When the overlaysprite is clicked we validate the login and enable our userinterface. When the user is connected successfully to the application we start our BatchCollection to make multiple calls to FB, We check if the user has allowed permission to upload pictures, get his basic information like id, name and so on, and also get the album list from his profile<em> (currently not working due to API bug)</em><br />
When the batch is completed we assign the result to various variables and check the status of the extended permission if this is false, then we ask the user to confirm the permission so we are able to upload pictures, the getPermission() method.<br />
After that we are ready to move on to our interface.</p>
<p>In this example I&#8217;m not going to create a seamless experience with Facebook that you know from other applications mostly on Mobile Phones, that involves a bunch of HTML and Javascript scripting and is covered on Jeanette Stallons Part 3: <a href="http://www.adobe.com/devnet/facebook/articles/first_flex_facebook_web_app_pt3.html" target="_blank">Deploy using Facebook Connect</a></p>
<p><strong>3. Interface</strong> (UserInterface.as)<br />
Next up we are going to create a simple interface so you can preview the webcam image and take a snapshot, we also going to create a small logger window so we get informed about what&#8217;s going on without having to switch to the deMonsterDebugger to view the status. Therefore I&#8217;m going to create a custom class named <strong>UserInterface</strong> which will have the visual assets and placeholders for the data received.</p>
<p>Below the Userinterface.as class:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> UserInterface <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _video			:<span style="color: #0066CC;">Video</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _camera			:<span style="color: #0066CC;">Camera</span>;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _bitmap			:Bitmap;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _bitmapData			:BitmapData;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _snapshotBA			:ByteArray;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _pushButton			:PushButton;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _albumArray			:<span style="color: #0066CC;">Array</span>;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _albumList			:<span style="color: #0066CC;">List</span>;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> UserInterface<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			_camera				= <span style="color: #0066CC;">Camera</span>.<span style="color: #006600;">getCamera</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_camera.<span style="color: #0066CC;">setMode</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">640</span>, <span style="color: #cc66cc;">480</span>, <span style="color: #cc66cc;">25</span>, <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #66cc66;">&#41;</span>;
			_video				= <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Video</span><span style="color: #66cc66;">&#40;</span> _camera.<span style="color: #0066CC;">width</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>, _camera.<span style="color: #0066CC;">height</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">&#41;</span>;
			_video.<span style="color: #006600;">attachCamera</span><span style="color: #66cc66;">&#40;</span> _camera <span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span> _video <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_pushButton				= <span style="color: #000000; font-weight: bold;">new</span> PushButton<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_pushButton.<span style="color: #0066CC;">width</span>			= <span style="color: #cc66cc;">80</span>;
			_pushButton.<span style="color: #006600;">x</span>				= _video.<span style="color: #0066CC;">width</span> - _pushButton.<span style="color: #0066CC;">width</span>;
			_pushButton.<span style="color: #006600;">y</span>				= _video.<span style="color: #0066CC;">height</span> + <span style="color: #cc66cc;">5</span>;
			_pushButton.<span style="color: #006600;">label</span>			= <span style="color: #ff0000;">&quot;CAPTURE&quot;</span>;
			_pushButton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">CLICK</span>, createSnapshot <span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span> _pushButton <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_bitmapData				= <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span> _camera.<span style="color: #0066CC;">width</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>, _camera.<span style="color: #0066CC;">height</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">&#41;</span>;
			_bitmap					= <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span> _bitmapData <span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createSnapshot<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>
			_bitmapData.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span> _video <span style="color: #66cc66;">&#41;</span>;
			_video.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;
			addChild<span style="color: #66cc66;">&#40;</span> _bitmap <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> enc:JPGEncoder = <span style="color: #000000; font-weight: bold;">new</span> JPGEncoder<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">80</span> <span style="color: #66cc66;">&#41;</span>;
			_snapshotBA = enc.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span> _bitmapData <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_pushButton.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">CLICK</span>, createSnapshot <span style="color: #66cc66;">&#41;</span>;
			_pushButton.<span style="color: #006600;">label</span> = <span style="color: #ff0000;">&quot;UPLOAD IMAGE&quot;</span>;
			_pushButton.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">CLICK</span>, sendSnapshot <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> sendSnapshot<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>
			dispatchEvent<span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">new</span> Event<span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">SELECT</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> createList<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_albumList			= <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">List</span><span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">this</span>, _video.<span style="color: #006600;">x</span> + _video.<span style="color: #0066CC;">width</span> + <span style="color: #cc66cc;">20</span>, _video.<span style="color: #006600;">y</span>, _albumArray <span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span> _albumList <span style="color: #66cc66;">&#41;</span>;
&nbsp;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> albumList<span style="color: #66cc66;">&#40;</span> arr:<span style="color: #0066CC;">Array</span> <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_albumArray = arr;
			<span style="color: #808080; font-style: italic;">//MonsterDebugger.trace(this, _albumArray );</span>
			<span style="color: #808080; font-style: italic;">//createList();</span>
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> snapshot<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:ByteArray
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _snapshotBA;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>As you see I&#8217;m creaing a Camera instance with the size of 640x480px and attaching it to a video class to be displayed on the stage at halfsize, you could also keep it the full size but I prefer working with the 320&#215;240 format.<br />
The Bitmap and BitmapData instances are created and create a getter to return the bytearray to our mainapplication.</p>
<p><strong>4. Using the Webcam</strong><br />
Let&#8217;s take a quicklook what we are doing to take a snapshot of the webcam and how to prepare the image to be uploaded to Facebook. As mentioned on my previous post we take a snapshot of the webcam by creating a bitmapdata of it, then we use the JPGEncoder classes from the AS3Corelib <em>(these are as well already inside the AS3Facebook Library)</em> and encode them into a ByteArray.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> createSnapshot<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>
			_bitmapData.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span> _video <span style="color: #66cc66;">&#41;</span>;
			_video.<span style="color: #0066CC;">visible</span> = <span style="color: #000000; font-weight: bold;">false</span>;
			addChild<span style="color: #66cc66;">&#40;</span> _bitmap <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> enc:JPGEncoder = <span style="color: #000000; font-weight: bold;">new</span> JPGEncoder<span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">80</span> <span style="color: #66cc66;">&#41;</span>;
			_snapshotBA = enc.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span> _bitmapData <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><strong>5. Choosing Album and uploading Picture</strong><br />
As mentioned before there is currently a bug with the AS3Facebook API 3.4, you cannot get the Albumlist from the logged in user, even if you give the application the proper extended permissions. So in our case we are just going to upload our photos to the default album, now you&#8217;re asking what&#8217;s the default album?</p>
<p>It&#8217;s not very clear to me as well, but basically Facebook creates a Photoalbum for every application that uploads an image to it, let&#8217;s say your application is called &#8220;APU&#8221; the user using the application will get a APU PhotoGallery folder in his profile. So choose wisely what name your application will have.</p>
<p>Below the upload code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> uploadImage<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">e</span>:Event <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_uploadPhoto = <span style="color: #000000; font-weight: bold;">new</span> UploadPhoto<span style="color: #66cc66;">&#40;</span>_userInterface.<span style="color: #006600;">snapshot</span><span style="color: #66cc66;">&#41;</span>;
			_fb.<span style="color: #006600;">post</span><span style="color: #66cc66;">&#40;</span>_uploadPhoto<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>That&#8217;s it, the most difficult part developing applications using Facebook is barely the way the whole data communication works, the API is very stable and things work well ( let&#8217;s forget the GetAlbum bug ).<br />
Most tutorials out there have been written for Flex or AIR, simply because it gives you the best userinterface to handle FB needs nevertheless I prefer using pure AS3.</p>
<p>This time I didn&#8217;t want to create a nice interface to use it, as this is solely a programming article, feel free to modify it, download it, share it, whatever you would like to do with it.</p>
<p>You can download the project here: <a href="http://blog.six4rty.ch/wp-content/uploads/2010/07/Facebook-AS3.zip">Source  (Flash Builder Project)</a></p>
<div style="padding-top:5px;padding-right:0px;padding-bottom:5px;padding-left:0px;;">
											<iframe
												style="height:25px !important; border:0px solid gray !important; overflow:hidden !important; width:550px !important;" frameborder="0" scrolling="no" allowTransparency="true"
												src="http://www.linksalpha.com/social?blog=Tiago%26%23039%3Bs+Weblog&link=http%253A%252F%252Fblog.six4rty.ch%252F2010%252F07%252F17%252Fas3-facebook-uploading-webcam-photos%252F&title=AS3+%26+Facebook%3A+Uploading+Webcam+Photos&desc=Facebook..+Could+you+live+without+facebook+nowadays%3F+Sometimes+I%27m+happy+when+I+don%27t+get+anything+on+facebook%2C+just+to+have+a+bit+of+peace+and+quiet+of+it.%0D%0A%0D%0AWell%2C+nevertheless%2C+I%27m+writing+this+art&fc=333333&fs=arial&fblname=like&fblref=facebook&fbllang=en_US&fblshow=1&fbsbutton=1&fbsctr=1&fbslang=en&fbsendbutton=1&twbutton=1&twlang=en&twmention=six4rty&twrelated1=&twrelated2=&twctr=1&lnkdshow=show&lnkdctr=1&buzzbutton=1&buzzlang=en&buzzctr=0&diggbutton=1&diggctr=0&stblbutton=1&stblctr=0&g1button=1&g1ctr=1&g1lang=en-US">
											</iframe>
										</div>]]></content:encoded>
			<wfw:commentRss>http://blog.six4rty.ch/2010/07/17/as3-facebook-uploading-webcam-photos/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
	</item>
		<item>
		<title>AS3: QuickHint: Convert BitmapData to ByteArray</title>
		<link>http://blog.six4rty.ch/2010/07/17/as3-quickhint-convert-bitmapdata-to-bytearray/</link>
		<comments>http://blog.six4rty.ch/2010/07/17/as3-quickhint-convert-bitmapdata-to-bytearray/#comments</comments>
		<pubDate>Sat, 17 Jul 2010 01:30:12 +0000</pubDate>
		<dc:creator>Tiago</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Quick Hints]]></category>
		<category><![CDATA[AS3.0]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[ByteArray]]></category>

		<guid isPermaLink="false">http://blog.six4rty.ch/?p=754</guid>
		<description><![CDATA[While writing my next post, about Facebook and Flash development, I noticed that there is something in my post drafts that I haven&#8217;t published yet, so I changed it a bit and here you go. On one of my last posts taking a screenshot with AS3 I&#8217;ve explained how to create a snapshot by using [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.six4rty.ch/wp-content/uploads/2010/07/as3code.jpg"><img class="alignleft size-medium wp-image-724" style="margin: 10px;" title="as3code" src="http://blog.six4rty.ch/wp-content/uploads/2010/07/as3code-300x270.jpg" alt="" width="210" height="189" /></a>While writing my next post, about Facebook and Flash development, I noticed that there is something in my post drafts that I haven&#8217;t published yet, so I changed it a bit and here you go.</p>
<p>On one of my last posts <a href="http://blog.six4rty.ch/2010/07/11/as3-take-a-screenshot-of-displayobject/" target="_blank">taking a screenshot with AS3</a> I&#8217;ve explained how to create a snapshot by using the Bitmap and the BitmapData classes.</p>
<p>Sometimes you need to convert the bitmaps to bytearrays to send them to a server-side script, save it directly to an AIR database or send it with AMF.</p>
<p>Something that is still a bit unclear, is how to convert the freshly created BitmapData to a ByteArray, there are no methods available in the default packages that come along with Flash Builder or Flash Professional, there are a few other ways, but they are in my opinion not really the best way on doing it. After all we all like to write short, smart clean code right?<br />
<span id="more-754"></span><br />
Make sure you download the <a href="http://code.google.com/p/as3corelib/source/browse/#svn/trunk/src/com/adobe/images" target="_blank">JPG/PNG Encoder</a> classes from the <a href="http://code.google.com/p/as3corelib/" target="_blank">AS3 corelib,</a> without these you will not be able to create a proper bytearray of the snapshot,</p>
<p>To start off, let&#8217;s refresh our memory on how to create a bitmapdata.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">_bitmapData					= <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span> _sprite.<span style="color: #0066CC;">width</span>, _sprite.<span style="color: #0066CC;">height</span> <span style="color: #66cc66;">&#41;</span>;
_bitmap						= <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span> _bitmapData <span style="color: #66cc66;">&#41;</span>;
_bitmapData.<span style="color: #006600;">draw</span> <span style="color: #66cc66;">&#40;</span> _sprite <span style="color: #66cc66;">&#41;</span>;
addChild<span style="color: #66cc66;">&#40;</span> _bitmap <span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Now that we remember how we create the bitmapdata object, let&#8217;s move on to the creation of a ByteArray, don&#8217;t be afraid it&#8217;s really easy, and it doesn&#8217;t cost you more then two lines of code.</p>
<pre lang ="actionscript">
var enc:JPGEncoder = new JPGEncoder( 80 );
var _snapshotBA = enc.encode( _bitmapData );
</pre>
<p>That was it, as you see, I kept my promise, only 2 lines of code to create a ByteArray.</p>
<p>Stay tuned for the next post.</p>
<div style="padding-top:5px;padding-right:0px;padding-bottom:5px;padding-left:0px;;">
											<iframe
												style="height:25px !important; border:0px solid gray !important; overflow:hidden !important; width:550px !important;" frameborder="0" scrolling="no" allowTransparency="true"
												src="http://www.linksalpha.com/social?blog=Tiago%26%23039%3Bs+Weblog&link=http%253A%252F%252Fblog.six4rty.ch%252F2010%252F07%252F17%252Fas3-quickhint-convert-bitmapdata-to-bytearray%252F&title=AS3%3A+QuickHint%3A+Convert+BitmapData+to+ByteArray&desc=While+writing+my+next+post%2C+about+Facebook+and+Flash+development%2C+I+noticed+that+there+is+something+in+my+post+drafts+that+I+haven%27t+published+yet%2C+so+I+changed+it+a+bit+and+here+you+go.%0D%0A%0D%0AOn+one+of+&fc=333333&fs=arial&fblname=like&fblref=facebook&fbllang=en_US&fblshow=1&fbsbutton=1&fbsctr=1&fbslang=en&fbsendbutton=1&twbutton=1&twlang=en&twmention=six4rty&twrelated1=&twrelated2=&twctr=1&lnkdshow=show&lnkdctr=1&buzzbutton=1&buzzlang=en&buzzctr=0&diggbutton=1&diggctr=0&stblbutton=1&stblctr=0&g1button=1&g1ctr=1&g1lang=en-US">
											</iframe>
										</div>]]></content:encoded>
			<wfw:commentRss>http://blog.six4rty.ch/2010/07/17/as3-quickhint-convert-bitmapdata-to-bytearray/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
	</item>
		<item>
		<title>AS3: Drawing dynamic anchor lines</title>
		<link>http://blog.six4rty.ch/2010/07/13/as3-drawing-dynamic-anchor-lines/</link>
		<comments>http://blog.six4rty.ch/2010/07/13/as3-drawing-dynamic-anchor-lines/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 18:14:12 +0000</pubDate>
		<dc:creator>Tiago</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Quick Hints]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[Drawing]]></category>

		<guid isPermaLink="false">http://blog.six4rty.ch/?p=732</guid>
		<description><![CDATA[Based on this post on the Adobe&#8217;s AS3 forum, I thought  I would create a simple class that takes care of the requested task. The whole idea is basically to draw a line dynamically between 2 displayobjects, on top of it when one object is being dragged the line is redrawn along based on the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.six4rty.ch/wp-content/uploads/2010/07/as3code.jpg"><img class="size-medium wp-image-724 alignleft" style="margin: 10px;" title="as3code" src="http://blog.six4rty.ch/wp-content/uploads/2010/07/as3code-300x270.jpg" alt="" width="210" height="189" /></a>Based on <a href="http://forums.adobe.com/thread/669998?tstart=0" target="_blank">this</a> post on the Adobe&#8217;s AS3 forum, I thought  I would create a simple class that takes care of the requested task.</p>
<p>The whole idea is basically to draw a line dynamically between 2 displayobjects, on top of it when one object is being dragged the line is redrawn along based on the second sprite position.</p>
<p>There is  a lot more that can be done, like avoiding other sprites, drawing multiple lines attached to multiple buttons and so on. but I think this class can give you a good head start for future implementations.</p>
<p>First of all there are a few things that we need to consider before starting, let&#8217;s take a look at the first few tasks</p>
<p>1. Every Sprite needs to know to which button it has been linked to. You need to store this somewhere.<br />
2. Every Sprite needs a specific anchor point that is used as endpoint of the drawn line.<br />
3. As soon the drag method is started we need to know where  the one end of the line (from the sprite that is not being dragged by the mouse) is positioned at. This is something that we really need to do once on a startDrag method.</p>
<p>Here&#8217;s what I&#8217;ve done:<span id="more-732"></span><br />
Based on the notices above, I&#8217;ve created a new Class called ConnectedSprite a simple class which extends the Sprite Class but with a few more options that helps us towards our goal and this is how our class looks like:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">DisplayObject</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">geom</span>.<span style="color: #006600;">Point</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ConnectedSprite <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _anchorPoint			:Point;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _relativeObject		:ConnectedSprite;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> ConnectedSprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">super</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> anchorPoint <span style="color: #66cc66;">&#40;</span> p:Point <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_anchorPoint = p;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> anchorPoint<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:Point
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _anchorPoint;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">set</span> relativeObject <span style="color: #66cc66;">&#40;</span> co:ConnectedSprite <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			_relativeObject = co;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">get</span> relativeObject<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:ConnectedSprite
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">return</span> _relativeObject;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Just to give you quick overview of what we are doing here:<br />
Basically we are extending the Sprite class and adding two new variables _<strong>anchorPoint</strong> and _<strong>relativeObject</strong>, those are accessible by using getters &amp; setters.<br />
The _anchorpoint variable holds a fixed x and y position where our line should connect to and the _relativeObject has a reference to the other sprite which is being conntected to.<br />
Pretty simple but effective.</p>
<p>That was already it, we now just need to create two new ConnectedSprite instances pass the needed values and there you go, below the BaseClass I&#8217;ve built for this example:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AnchoredSprite <span style="color: #0066CC;">extends</span> Sprite
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _spriteA			:ConnectedSprite;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _spriteB			:ConnectedSprite;
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _movingTarget		:ConnectedSprite;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> _staticTargetPos		:Point		= <span style="color: #000000; font-weight: bold;">new</span> Point<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;">var</span> _connector			:Sprite;
&nbsp;
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> AnchoredSprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			_connector = <span style="color: #000000; font-weight: bold;">new</span> Sprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span> _connector <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_spriteA = <span style="color: #000000; font-weight: bold;">new</span> ConnectedSprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_spriteA.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span> 0xff0000, <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span>;
			_spriteA.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">50</span> <span style="color: #66cc66;">&#41;</span>;
			_spriteA.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_spriteA.<span style="color: #006600;">anchorPoint</span> = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span> _spriteA.<span style="color: #0066CC;">width</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>, _spriteA.<span style="color: #0066CC;">height</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span> _spriteA <span style="color: #66cc66;">&#41;</span>;
			_spriteA.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, mouseDownHandler <span style="color: #66cc66;">&#41;</span>;
			_spriteA.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, mouseUpHandler <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_spriteB = <span style="color: #000000; font-weight: bold;">new</span> ConnectedSprite<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_spriteB.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">beginFill</span><span style="color: #66cc66;">&#40;</span> 0x0000ff, <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#41;</span>;
			_spriteB.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">50</span>, <span style="color: #cc66cc;">50</span> <span style="color: #66cc66;">&#41;</span>;
			_spriteB.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_spriteB.<span style="color: #006600;">anchorPoint</span> = <span style="color: #000000; font-weight: bold;">new</span> Point<span style="color: #66cc66;">&#40;</span> _spriteB.<span style="color: #0066CC;">width</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span>, _spriteB.<span style="color: #0066CC;">height</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span> _spriteB <span style="color: #66cc66;">&#41;</span>;
			_spriteB.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">MOUSE_DOWN</span>, mouseDownHandler <span style="color: #66cc66;">&#41;</span>;
			_spriteB.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">MOUSE_UP</span>, mouseUpHandler <span style="color: #66cc66;">&#41;</span>;
&nbsp;
			_spriteA.<span style="color: #006600;">relativeObject</span> = _spriteB;
			_spriteB.<span style="color: #006600;">relativeObject</span> = _spriteA;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> mouseDownHandler<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>
			<span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">startDrag</span><span style="color: #66cc66;">&#40;</span> <span style="color: #000000; font-weight: bold;">false</span> <span style="color: #66cc66;">&#41;</span>;
			_movingTarget = <span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span> as ConnectedSprite;
			_staticTargetPos.<span style="color: #006600;">x</span> = _movingTarget.<span style="color: #006600;">relativeObject</span>.<span style="color: #006600;">x</span> + _movingTarget.<span style="color: #006600;">relativeObject</span>.<span style="color: #006600;">anchorPoint</span>.<span style="color: #006600;">x</span>;
			_staticTargetPos.<span style="color: #006600;">y</span> = _movingTarget.<span style="color: #006600;">relativeObject</span>.<span style="color: #006600;">y</span> + _movingTarget.<span style="color: #006600;">relativeObject</span>.<span style="color: #006600;">anchorPoint</span>.<span style="color: #006600;">y</span>;
			addEventListener<span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, drawLine <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> mouseUpHandler<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>
			<span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #0066CC;">stopDrag</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_movingTarget = <span style="color: #000000; font-weight: bold;">null</span>;
&nbsp;
			removeEventListener<span style="color: #66cc66;">&#40;</span> MouseEvent.<span style="color: #006600;">MOUSE_MOVE</span>, drawLine <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> drawLine<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>
			_connector.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			_connector.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineStyle</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">1</span>, 0x333333 <span style="color: #66cc66;">&#41;</span>;
			_connector.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">moveTo</span><span style="color: #66cc66;">&#40;</span> _staticTargetPos.<span style="color: #006600;">x</span>, _staticTargetPos.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&#41;</span>;
			_connector.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">lineTo</span><span style="color: #66cc66;">&#40;</span> _movingTarget.<span style="color: #006600;">x</span> + _movingTarget.<span style="color: #006600;">anchorPoint</span>.<span style="color: #006600;">x</span>, _movingTarget.<span style="color: #006600;">y</span> + _movingTarget.<span style="color: #006600;">anchorPoint</span>.<span style="color: #006600;">y</span> <span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">updateAfterEvent</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>it&#8217;s quite a long base class for this simple task, it could have been reduced using other drawing methods, but that is something that I leave up to you.</p>
<p>Below a working example and you can download the source files here: <a href="http://blog.six4rty.ch/wp-content/uploads/2010/07/ConnectedSprite.zip">ConnectedSprite</a></p>

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_2" width="400" height="300">
      <param name="movie" value="http://blog.six4rty.ch/wp-content/uploads/2010/07/AnchoredSprite1.swf" />
      <param name="allowfullscreen" value="true" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://blog.six4rty.ch/wp-content/uploads/2010/07/AnchoredSprite1.swf" width="400" height="300" allowfullscreen="true">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

<div style="padding-top:5px;padding-right:0px;padding-bottom:5px;padding-left:0px;;">
											<iframe
												style="height:25px !important; border:0px solid gray !important; overflow:hidden !important; width:550px !important;" frameborder="0" scrolling="no" allowTransparency="true"
												src="http://www.linksalpha.com/social?blog=Tiago%26%23039%3Bs+Weblog&link=http%253A%252F%252Fblog.six4rty.ch%252F2010%252F07%252F13%252Fas3-drawing-dynamic-anchor-lines%252F&title=AS3%3A+Drawing+dynamic+anchor+lines&desc=Based+on+this+post+on+the+Adobe%27s+AS3+forum%2C+I+thought%C2%A0+I+would+create+a+simple+class+that+takes+care+of+the+requested+task.%0D%0A%0D%0AThe+whole+idea+is+basically+to+draw+a+line+dynamically+between+2+displa&fc=333333&fs=arial&fblname=like&fblref=facebook&fbllang=en_US&fblshow=1&fbsbutton=1&fbsctr=1&fbslang=en&fbsendbutton=1&twbutton=1&twlang=en&twmention=six4rty&twrelated1=&twrelated2=&twctr=1&lnkdshow=show&lnkdctr=1&buzzbutton=1&buzzlang=en&buzzctr=0&diggbutton=1&diggctr=0&stblbutton=1&stblctr=0&g1button=1&g1ctr=1&g1lang=en-US">
											</iframe>
										</div>]]></content:encoded>
			<wfw:commentRss>http://blog.six4rty.ch/2010/07/13/as3-drawing-dynamic-anchor-lines/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by/2.5/ch/</creativeCommons:license>
	</item>
	</channel>
</rss>

