<?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:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>M@ Blog</title>
	<atom:link href="http://mattreyuk.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://mattreyuk.wordpress.com</link>
	<description>Yet another Flex blog</description>
	<lastBuildDate>Mon, 24 Jan 2011 15:43:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='mattreyuk.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://1.gravatar.com/blavatar/dfeaed98375c3a5273cf2fccc9cf2828?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>M@ Blog</title>
		<link>http://mattreyuk.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://mattreyuk.wordpress.com/osd.xml" title="M@ Blog" />
	<atom:link rel='hub' href='http://mattreyuk.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Notes on Rocky Mountain Flash Camp (10/12/10)</title>
		<link>http://mattreyuk.wordpress.com/2010/10/21/notes-on-rocky-mountain-flash-camp-101210/</link>
		<comments>http://mattreyuk.wordpress.com/2010/10/21/notes-on-rocky-mountain-flash-camp-101210/#comments</comments>
		<pubDate>Fri, 22 Oct 2010 01:24:55 +0000</pubDate>
		<dc:creator>mattreyuk</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://mattreyuk.wordpress.com/?p=573</guid>
		<description><![CDATA[These are some notes on the recently held Flash Camp in Denver that I attended. I&#8217;ve included links to slides where I have them and the recordings that were made of each session (apparently the first 3 sessions had some audio issues). First off was RJ Owenof Effective UI on the Flex 4 Component Lifecycle [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=573&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>These are some notes on the recently held Flash Camp in Denver that I attended. I&#8217;ve included links to slides where I have them and the recordings that were made of each session (apparently the first 3 sessions had some audio issues).</p>
<p>First off was <a href="http://insideria.com/rj-owen/">RJ Owen</a>of <a href="http://effectiveui.com/">Effective UI</a> on the Flex 4 Component Lifecycle (<a href="http://www.slideshare.net/rjowen/flex4-componentlifecycle">slides</a>,<a href="http://realeyes.acrobat.com/p96019470/">recording</a>) who covered the classic elastic racetrack (for some reason I always want to say<em> electric </em>racetrack), the birth, life and death of components and where the &#8220;skin&#8221; aspects of Flex 4 come into play. He also covered some performance considerations (such as constructors are not JIT compiled and therefore not optimized so should be as small as possible).</p>
<p>Next up <a href="http://www.paultrani.com/blog/">Paul Trani</a> of <a href="http://www.adobe.com">Adobe</a> covered a Flash CS5 deep dive (<a href="http://realeyes.acrobat.com/p17391608/">recording</a>) going through some of the things you can do with the tool. It was an entertaining session with more of a designer emphasis.</p>
<p>Kevin Hoyt, also of Adobe went next on the Flash Player for Flex Developers (<a href="http://realeyes.acrobat.com/p11617161/">recording</a>). Unfortunately, Kevin&#8217;s blog seems to be unavailable while I&#8217;m writing this but you should find him at <a href="http://blog.kevinhoyt.org"> blog.kevinhoyt.org</a> probably after Adobe MAX is finished. This talk was one I&#8217;d seen Kevin give before going through a simple app to gather weather data written purely in Flash starting with the stage and using Sprite as the base object for the display components. The end result was a Flash program of ~ 3k compared to a Flex program (using framework libs) of ~100k. This time I remembered to ask him if there were any lightweight Flash frameworks I could look at rather than re-inventing everything myself. His suggestions were <a href="http://github.com/mikechambers/as3corelib">AS3CoreLib</a> and <a href="http://www.minimalcomps.com/">MinimalComps</a>.</p>
<p><a href="http://www.jamesward.com/">James Ward</a> (Adobe) talked about Mobile Flash and Flex Development (<a href="http://realeyes.acrobat.com/p77985264/">recording</a>). His session covered the <a href="http://flex.org/tour">&#8220;Tour de Flex&#8221;</a> mobile app for Android he&#8217;s currently working on using <a href="http://labs.adobe.com/technologies/flex/mobile/">Flex Hero</a> beta. It&#8217;s not generally available yet but you can find his code on <a href="http://github.com/jlward4th/TourDeMobileFlex">github</a>.</p>
<p><a href="http://david.realeyes.com/">David Hassoun</a> of <a href="http://www.realeyes.com/">RealEyes Media</a> talked about Video on the Flash Platform (<a href="http://realeyes.acrobat.com/p14458377/">recording</a>) which demoed some of the features of the <a href="http://www.opensourcemediaframework.com/">Open Source Media Framework (OSMF)</a></p>
<p><a href="http://iheartair.com/">Jun Heider</a> also of RealEyes Media covered &#8220;cool things you can do with Flash Player P2P&#8221; (<a href="http://jun.realeyes.com/?p=708">slides and source</a>,<a href="http://realeyes.acrobat.com/p32395904/">recording</a>). I had vaguely heard of Adobe Stratus (now <a href="http://labs.adobe.com/technologies/cirrus/"> Cirrus</a>) but that was about it so it was interesting to see some examples of how it could be used.</p>
<p>Last but not least was <a href="http://blog.juanbonfante.com/">Juan Bonfante</a> of <a href="http://www.roundarch.com/">Roundarch</a> talking on Advanced skinning and layout with Flex 4 (<a href="http://blog.juanbonfante.com/?p=353">code</a>,<a href="http://realeyes.acrobat.com/p33956060/">recording</a>).</p>
<p><a href="http://www.rmaug.com/">RMAUG</a> did a great job putting on this camp and if you&#8217;re in the Denver area on November 9th, you should check out their &#8220;Mini MAX&#8221; event (details on the website).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattreyuk.wordpress.com/573/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattreyuk.wordpress.com/573/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattreyuk.wordpress.com/573/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattreyuk.wordpress.com/573/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattreyuk.wordpress.com/573/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattreyuk.wordpress.com/573/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattreyuk.wordpress.com/573/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattreyuk.wordpress.com/573/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattreyuk.wordpress.com/573/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattreyuk.wordpress.com/573/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattreyuk.wordpress.com/573/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattreyuk.wordpress.com/573/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattreyuk.wordpress.com/573/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattreyuk.wordpress.com/573/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=573&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattreyuk.wordpress.com/2010/10/21/notes-on-rocky-mountain-flash-camp-101210/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed190de5e93656a6623680d1014dcf1f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattreyuk</media:title>
		</media:content>
	</item>
		<item>
		<title>Use the Force Luke!</title>
		<link>http://mattreyuk.wordpress.com/2010/07/10/use-the-force-luke/</link>
		<comments>http://mattreyuk.wordpress.com/2010/07/10/use-the-force-luke/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 20:47:04 +0000</pubDate>
		<dc:creator>mattreyuk</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Salesforce]]></category>

		<guid isPermaLink="false">http://mattreyuk.wordpress.com/?p=552</guid>
		<description><![CDATA[The &#8220;Force&#8221; in this case being Salesforce.com (or SFDC). If you haven&#8217;t heard of it, Salesforce.com is a cloud platform, Software as a Service (SaaS) offering for sales related activities. It also has modules for customer relationship management (CRM) as well as more general computing services. You can sign up for a free developer account [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=552&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The &#8220;Force&#8221; in this case being Salesforce.com (or SFDC).  If you haven&#8217;t heard of it, Salesforce.com is a cloud platform, Software as a Service (SaaS) offering for sales related activities. It also has modules for customer relationship management (CRM) as well as more general computing services.</p>
<p>You can sign up for a free developer account and find plenty of documentation to get you started <a href="http://developer.force.com/gettingstarteddevelopers">here</a>. SFDC allows you to create or modify database tables by creating custom objects or fields, query the data using a SQL like language  &#8211; SOQL (Salesforce Object Query Language) , write business logic in a Java like language called Apex and display code using Visualforce pages which is javascript with custom tags.</p>
<p>One thing to keep in mind when you start working with SFDC are the <a href="http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm">governor limits</a>. Because you&#8217;re working in a shared environment, Salesforce doesn&#8217;t want you hogging all the resources so there are limits set to make sure things don&#8217;t get out of hand. When developing using Flex, you&#8217;re using a wrapper for the web services api so the &#8220;WSDL method&#8221; column in the link above is what you&#8217;re interested in. Basically, what this means is you should try and limit the number of queries you do (&lt;100) and the amount of data you return for them (&lt;10,000 rows).</p>
<p>One annoying factor  is that SFDC counts the number of rows it has to look at to perform a query to determine if you hit the limit so if you issue a query like &#8220;select count() from Opportunity&#8221; and you have more than 10,000 opportunity records, you&#8217;re going to get a system exception. Not only that, you can&#8217;t catch that type of exception so you&#8217;ll need to use a limit clause  if you think you&#8217;re going to get near that level.</p>
<p><strong>Salesforce Flex APIs</strong></p>
<p>There are two APIs for Flex provided by Salesforce. The older Flex toolkit<a href="http://developer.force.com/flextoolkit"> SFDC page</a>, <a href="http://www.adobe.com/devnet/salesforce/toolkit.html">Adobe Page</a> which is basically a wrapper for the web services interface as a library swc file and a newer Flash builder interface<a href="http://developer.force.com/flashbuilder"> SFDC page</a>, <a href="http://www.adobe.com/devnet/salesforce/">Adobe page</a> which is still currently in Beta and involves a custom version of the Flash builder tool. It seems to be suited more to Air apps working outside of SFDC as it contains data synchronization capabilities. For the rest of this post, I&#8217;m going to concentrate on the older API as it&#8217;s the one I&#8217;ve actually used for a deployed app. You can find documentation for the classes it provides <a href="http://www.adnsandbox.com/media/flexsdk/docs/index.html">here.</a></p>
<p><span style="text-decoration:underline;">Internal or External</span></p>
<p>You can design your Flex app to run either within SFDC or as an external app (either hosted on your own webserver or as an Air application). If you&#8217;re going to run externally, your users will need to login to SFDC via your app to allow you to access the data.  When logging in externally, users must append a security token to the end of their password (from setup on the top of the page, My Personal Information on the left, Reset My Security Token) unless the ip address they are logging in on has been entered as a member of a trusted network (from setup, Security Controls, Network Access).</p>
<p>Regardless of how you connect to SFDC, the method of the <code>Connection</code> class you use is the same,<code> login()</code> the data you provide is what changes. For an external app, you&#8217;ll provide <code>serverURL</code>. <code>username</code> and <code>password</code> in your <code>LoginRequest</code> object, for an internal app, <code>server_url</code> and <code>session_id</code>.</p>
<p>Unless you have specific reasons not to, it makes sense to let SFDC host your Flex app and have your users access it in the same place they&#8217;re using for their other activities related to that data.</p>
<p>During development, I would hard code a login to run your app externally so you can use it with your debug player to get trace data etc and then convert it to use the internal SFDC data before you build it for deployment.</p>
<p><span style="text-decoration:underline;">Deploying a Flex Application to Salesforce</span></p>
<p>Once you have a swf for your application, you can load it onto SFDC as a static resource. To do this, select setup, Develop, Static Resources, new, provide a name for your app and browse to the swf file on your machine.</p>
<p>Now you have the swf, you&#8217;ll need a wrapper page to access it. Select setup, Develop,Pages, new and you can enter your visualsource code to display the swf. If you&#8217;re going to be doing a lot of SFDC development, they provide an <a href="http://wiki.developerforce.com/index.php/Force.com_IDE">eclipse based IDE</a> which is worth getting to know.</p>
<p>If you look at the <a href="http://wiki.developerforce.com/index.php/Creating_a_Flex_Mashup_on_Force.com">getting started code</a> through the &#8220;Flex toolkit&#8221; link above, you&#8217;ll see the use of an <code>&lt;apex:flash&gt;</code> tag. This works but causes a security warning pop up when running on IE which might cause problems for some of your users. The way around this is to use  swf wrapper code more like the example below.</p>
<p>You&#8217;ll need to use <code>flashvars</code> to import the session id and server url to your app (along with any other startup data you might want. I&#8217;ve had issues sometimes using the <code>!API.Session_ID</code> parameter so you&#8217;ll see a reference to <code>!mySessionID</code> in the code below which comes from the custom Apex class <code>SessionUtil</code> provided as the <code>page controller</code> which we&#8217;ll discuss later.</p>
<p>Here&#8217;s an example visualsource page for a Flex app:</p>
<pre class="brush: jscript;">
&lt;apex:page controller=&quot;SessionUtil&quot; sidebar=&quot;false&quot; showHeader=&quot;false&quot;&gt;
&lt;object classid=&quot;clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot;
  id=&quot;FlexAPP&quot; width=&quot;1200&quot; height=&quot;820&quot;
  codebase=&quot;https://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab&quot;&gt;
  &lt;param name=&quot;movie&quot; value=&quot;{!$Resource.FlexAppName}&quot; /&gt;
  &lt;param name=&quot;quality&quot; value=&quot;high&quot; /&gt;
  &lt;param name=&quot;bgcolor&quot; value=&quot;#869ca7&quot; /&gt;
  &lt;param name=&quot;allowScriptAccess&quot; value=&quot;sameDomain&quot; /&gt;
  &lt;param name=&quot;flashvars&quot; value=&quot;uid={!$User.Id}&amp;sid={!mySessionID}&amp;surl={!$API.Partner_Server_URL_150}
  &amp;name={!$User.FirstName} {!$User.LastName}&quot; /&gt;
  &lt;embed src=&quot;{!$Resource.FlexAppName}&quot; quality=&quot;high&quot; bgcolor=&quot;#869ca7&quot;
    width=&quot;1200&quot; height=&quot;820&quot; name=&quot;Name of my App&quot; align=&quot;middle&quot;
    play=&quot;true&quot;
    loop=&quot;false&quot;
    flashvars=&quot;uid={!$User.Id}&amp;sid={!mySessionID}&amp;surl={!$Api.Partner_Server_URL_150}
    &amp;name={!$User.FirstName} {!$User.LastName}&quot;
    quality=&quot;high&quot;
    allowScriptAccess=&quot;sameDomain&quot;
    type=&quot;application/x-shockwave-flash&quot;
    pluginspage=&quot;http://www.adobe.com/go/getflashplayer&quot;&gt;
  &lt;/embed&gt;
&lt;/object&gt;
&lt;/apex:page&gt;
</pre>
<p>The <code>FlexAppName</code> after<code> $Resource</code> is the name you gave the Static Resource for your swf file. You can get data from the user record for the user logged in using <code>$User</code> everything else is either boilerplate stuff or pretty obvious.</p>
<p>The Apex class SessionUtil needs to be added using Apex Classes under the Develop menu. Here&#8217;s the most basic version of it:</p>
<pre class="brush: java;">
public class SessionUtil
{
    public String mySessionID {get; private set;}

    public SessionUtil() {
        mySessionID=UserInfo.getSessionId();
    }
}
</pre>
<p>You can expand on this to use SOQL queries to grab more data if you need it to initialize your app. This solution is based on the one provided by <a href="http://community.salesforce.com/t5/Visualforce-Development/as3Salesforce-swc-Flex-Toolkit-no-longer-working/m-p/125399#M12373">Wintermute</a> (love that username!) I just didn&#8217;t want to work off a standard controller.</p>
<p>Once you have your page setup you can access it directly by<code> &lt;salesforce url&gt;/apex/pagename</code> or you can configure it to appear wherever Salesforce lets you reference a visualforce page (dashboard, custom links etc).</p>
<p><span style="text-decoration:underline;">Tips for Developing using the Salesforce API</span></p>
<p>The API pages linked to above are a great place to start. Both the Adobe pages have videos going over what they provide and  Adobe evangelist James Ward has <a href="http://www.jamesward.com/category/salesforce/">a number of great posts</a> on both APIs.</p>
<p>Although the old API has been around for a while, it works perfectly well with Flex 4 &#8211; that&#8217;s what I built my app with.</p>
<p>The API documentation is pretty light and doesn&#8217;t go into a whole lot of detail &#8211; the thing to remember is it&#8217;s basically the web services API so you can usually find more detail looking at that documentation. Look for the &#8220;see also&#8221; link to Apex Developer Doc in the top description of the API class documents or go directly to the <a href="http://www.salesforce.com/us/developer/docs/api/">Web services API document</a>.</p>
<p>The interface is asynchronous &#8211; you&#8217;ll declare a success and failure handler for each request. Usually you can reuse your fail handler and you should at least check for  &#8220;INVALID_SESSION_ID&#8221; so you can warn the user their session has timed out. Different Requests give rise to different result objects &#8211; QueryResult, SaveResult, UpsertResult so make sure your result handler is using the correct one for your request. All results are provided as an array.</p>
<p>A lack of a fault event does not necessarily mean your insert/update/upsert was successful. You need to check your result object for an id. Here&#8217;s an example upsert handler:</p>
<pre class="brush: as3;">

//upsert  handler
 private function handleUpsert(result:Object):void {
     if (!(result[0] as UpsertResult).id) {
     //failed to update/add
     trace('error on change: ' + (result[0] as UpsertResult).errors.getItemAt(0).message);
     Alert.show(&quot;Unable to update SalesForce: &quot;+(result[0] as UpsertResult).errors.getItemAt(0).message,&quot;Error&quot;);
     }
 }
</pre>
<p>Salesforce has field level security so one reason you&#8217;ll see an error is if your user does not have permission to write to that object or field.</p>
<p>Keep your SFDC interaction encapsulated in it&#8217;s own class and define data objects to carry the information you work on for the rest of your app. I used an XML file to generate the data I wanted within my Salesforce class initially, it gave me the chance to work on the display side while I was still figuring out my SFDC queries and generate data conditions to test for without having to alter data in SFDC. I could then switch that out for the real code without having to change anything else as the interface stayed the same.</p>
<p>Don&#8217;t forget to test logged in as your target users. As a developer, you&#8217;ll probably have a profile that allows you full access to everything, your users will likely be more restricted so you need to make sure they can access everything your app is going to need.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattreyuk.wordpress.com/552/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattreyuk.wordpress.com/552/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattreyuk.wordpress.com/552/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattreyuk.wordpress.com/552/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattreyuk.wordpress.com/552/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattreyuk.wordpress.com/552/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattreyuk.wordpress.com/552/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattreyuk.wordpress.com/552/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattreyuk.wordpress.com/552/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattreyuk.wordpress.com/552/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattreyuk.wordpress.com/552/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattreyuk.wordpress.com/552/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattreyuk.wordpress.com/552/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattreyuk.wordpress.com/552/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=552&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattreyuk.wordpress.com/2010/07/10/use-the-force-luke/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed190de5e93656a6623680d1014dcf1f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattreyuk</media:title>
		</media:content>
	</item>
		<item>
		<title>Learning Flex 4 &#8211; States</title>
		<link>http://mattreyuk.wordpress.com/2010/05/27/learning-flex-4-states/</link>
		<comments>http://mattreyuk.wordpress.com/2010/05/27/learning-flex-4-states/#comments</comments>
		<pubDate>Thu, 27 May 2010 20:23:45 +0000</pubDate>
		<dc:creator>mattreyuk</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex 4]]></category>
		<category><![CDATA[learning Flex]]></category>

		<guid isPermaLink="false">http://mattreyuk.wordpress.com/?p=540</guid>
		<description><![CDATA[States are easier to work with in Flex 4 than they were with 3. While Flex 3 had the advantage that everything to do with your states was in one place, it made things more complicated by the additional syntax you had to deal with to add/remove items etc. With Flex 4, you can just [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=540&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>States are easier to work with in Flex 4 than they were with 3. While Flex 3 had the advantage that everything to do with your states was in one place, it made things more complicated by the additional syntax you had to deal with to add/remove items etc. With Flex 4, you can just add your state name to a property to specify a value specific to that state and specify if components should be included in/excluded from a state. The only downside to this is that your state specific code gets scattered but Flash Builder has an option to show you components by state so that helps there.</p>
<p>Starting from the beginning, you first need to declare what states you are going to have. This is done using the <code>&lt;s:states&gt;</code> tag. Within this, specify one or more <code>&lt;s:State&gt;</code> tags with the <code>name</code> property set to the name for your state. The first State is used as the default. In addition to the name, you may also specify a <code>stateGroups</code> property. This allows you to group states so you can refer to the group rather than all the individual states. This could be useful in the case where for most of the time, you want to do the same thing for several states but for specific components/properties you need a finer distinction.</p>
<p>Here&#8217;s an example (I like to use all caps for my state names to help them stand out a  little more):</p>
<p><code>&lt;s:States&gt;<br />
&lt;s:State name="LOADING"/&gt;<br />
&lt;s:State name="EMPLOYEE_VIEW" stateGroups="VIEW" /&gt;<br />
&lt;s:State name="MANAGER_VIEW" stateGroups="VIEW"/&gt;<br />
&lt;s:State name="MANAGER_SELECT" /&gt;<br />
&lt;/s:States&gt;</code></p>
<p>The grouping is a bit artificial in this case but this app starts in the LOADING state while it&#8217;s gathering data from the back end. Then, if you&#8217;re a manager, the state becomes MANAGER_SELECT where you can select an employee to view data on, finally you get a MANAGER_VIEW of the data or the EMPLOYEE_VIEW if you logged in as an employee. You can see how there might be several components common to the MANAGER_VIEW and the EMPLOYEE_VIEW which you could use the VIEW <code>stateGroup</code> for but some components (maybe a change pay rate button for instance) would be specific to the MANAGER_VIEW.</p>
<p>You can include components in a state by using the property <code>includeIn</code> or exclude them using <code>excludeFrom</code>.  You can specify more than one state by using commas to separate them in the string (or specify a <code>stateGroup</code>). By adding the state to a group container, you can affect all the components within that group.</p>
<p>You can change properties (including event handlers) by suffixing the property name with the state name you want it to apply to eg &#8211; <code>label.LOADING="retrieving data..."</code></p>
<p>If you don&#8217;t specify a state, the component/property is considered to be the same for all states. You can change the state by setting the <code>currentState</code> property (by setting it to the empty string, you return to the default or first state).</p>
<p>Custom components can declare their own states and you can use the <code>currentState</code> property of the instance of the custom component to change the state for that particular object.</p>
<p>When the state changes, the <code>enterState</code> event is fired by the <code>State</code> object being entered and by components entering that state. The <code>exitState</code> event is sent by the <code>State</code> and components being left. The object the <code>currentState</code> is being changed on fires <code>currentStateChanging</code> when it&#8217;s about to change and <code>currentStateChange</code> when it&#8217;s done.</p>
<p>You can use states within a custom item renderer to react to view states such as hovered, selected and change the presentation for these cases. <a href="http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf63611-7ffe.html">This article</a> has the details. Saturn Boy has also written a <a href="http://saturnboy.com/2009/09/flex4-component-states-skin-states/">blog post</a> looking at states with skinning.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattreyuk.wordpress.com/540/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattreyuk.wordpress.com/540/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattreyuk.wordpress.com/540/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattreyuk.wordpress.com/540/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattreyuk.wordpress.com/540/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattreyuk.wordpress.com/540/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattreyuk.wordpress.com/540/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattreyuk.wordpress.com/540/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattreyuk.wordpress.com/540/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattreyuk.wordpress.com/540/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattreyuk.wordpress.com/540/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattreyuk.wordpress.com/540/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattreyuk.wordpress.com/540/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattreyuk.wordpress.com/540/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=540&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattreyuk.wordpress.com/2010/05/27/learning-flex-4-states/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed190de5e93656a6623680d1014dcf1f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattreyuk</media:title>
		</media:content>
	</item>
		<item>
		<title>Learning Flex 4 &#8211; Spark Components and Skinning Basics</title>
		<link>http://mattreyuk.wordpress.com/2010/04/12/learning-flex-4-spark-components-and-skinning-basics/</link>
		<comments>http://mattreyuk.wordpress.com/2010/04/12/learning-flex-4-spark-components-and-skinning-basics/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 05:20:04 +0000</pubDate>
		<dc:creator>mattreyuk</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://mattreyuk.wordpress.com/?p=536</guid>
		<description><![CDATA[One of the key changes to Flex moving to version 4 is the introduction of the Spark component set. The components in Flex 3 (Button, TextInput etc) were known under the code name Halo and they&#8217;re still available in Flex 4. These components are distinguished by the mx namespace prefix you are used to. The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=536&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of the key changes to Flex moving to version 4 is the introduction of the Spark component set.</p>
<p>The components in Flex 3 (<code>Button</code>, <code>TextInput</code> etc) were known under the code name Halo and they&#8217;re still available in Flex 4. These components are distinguished by the <code>mx</code> namespace prefix you are used to. The new Spark components have an <code>s</code> prefix and require the addition of a new namespace definition &#8211; <code>xmlns:s="library://ns.adobe.com/flex/spark"</code> (The <code>mx</code> namespace definition also changes to  <code>xmlns:mx="library://ns.adobe.com/flex/halo"</code>).</p>
<p>There are Spark equivalents of most but not all mx or Halo components (DataGrid, AdvancedDataGrid and Tree are some of the currently missing).</p>
<p>The key difference in the component sets is their construction. Halo components contain everything required for that object including styling, behavior and layout. Spark components on the other hand, separate out the behavior of a component from the display aspects. The information corresponding to component display is kept in a separate skin class.</p>
<p>The upshot of this change is that the look and feel of an application can be separated from it&#8217;s behavior and more readily changed. With the introduction of the <a href="http://mattreyuk.wordpress.com/tag/catalyst/">Catalyst tool</a> in CS5, designers can deal with the display skins while developers deal with the underlying behavior.</p>
<p>You can specify the skin a component should use with:</p>
<ul>
<li>CSS: <code>S|Button {skinClass: ClassReference ("com.example.skins.MyButtonSkin");}</code></li>
<li>MXML:<code> &lt;s:Button skinClass="com.example.MyButtonSkin"/&gt;</code></li>
<li>ActionScript: <code>myButton.setStyle("skinClass",Class(MyButtonSkin);</code></li>
</ul>
<p>The skin class is generally written in MXML and defines the states (with transitions) the skin reacts to, graphical elements and any component parts the skin is constructed from. The skin may also specify the <code>HostComponent</code> in a metadata tag. The <code>HostComponent</code> is the component class that will use the skin. This is useful for the skin to be able to gain a reference to properties of the component instance.</p>
<p>A skin class must declare state properties that are specified for it&#8217;s host component. For example, a Spark Button has states <code>up</code>, <code>over</code>, <code>down</code> and <code>disabled</code> so the skin must declare what it looks like for each of these states. The component will then set the relevant state at runtime.</p>
<p>Skin parts are sub components used to define a larger component &#8211; for example, a scrollbar has increment and decrement button parts together with a track and thumb part whereas a button just has a label.</p>
<p>The graphical elements of a skin are defined using a new graphics tag library cald FXG which includes graphics and text primitives including tags for creating basic shapes, fills, gradients and bitmaps. FXG is also used by Catalyst and other tools to transfer graphical data. The specification for FXG can be found <a href="http://opensource.adobe.com/wiki/display/flexsdk/FXG+2.0+Specification">here</a>.</p>
<p>A great way to begin working with Skins is to modify the Adobe supplied skin class for a component. Flash Builder 4 has a workflow for creating skin classes that allows you to work from a supplied class. With FlashDevelop, you&#8217;ll have to go off and find the class for yourself and copy it in to your project under the name you want. You&#8217;ll find the skin class source files under your SDK install in the <code>frameworks\projects\spark\src\spark\skins\spark</code> directory.</p>
<p>For further detail on skinning Spark components, take a look at <a href="http://opensource.adobe.com/wiki/display/flexsdk/Spark+Skinning">these</a> Adobe <a href="http://help.adobe.com/en_US/Flex/4.0/UsingSDK/WS53116913-F952-4b21-831F-9DE85B647C8A.html"> articles.</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattreyuk.wordpress.com/536/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattreyuk.wordpress.com/536/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattreyuk.wordpress.com/536/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattreyuk.wordpress.com/536/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattreyuk.wordpress.com/536/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattreyuk.wordpress.com/536/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattreyuk.wordpress.com/536/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattreyuk.wordpress.com/536/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattreyuk.wordpress.com/536/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattreyuk.wordpress.com/536/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattreyuk.wordpress.com/536/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattreyuk.wordpress.com/536/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattreyuk.wordpress.com/536/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattreyuk.wordpress.com/536/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=536&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattreyuk.wordpress.com/2010/04/12/learning-flex-4-spark-components-and-skinning-basics/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed190de5e93656a6623680d1014dcf1f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattreyuk</media:title>
		</media:content>
	</item>
		<item>
		<title>Where do we go from here?</title>
		<link>http://mattreyuk.wordpress.com/2010/03/17/where-do-we-go-from-here/</link>
		<comments>http://mattreyuk.wordpress.com/2010/03/17/where-do-we-go-from-here/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 03:17:30 +0000</pubDate>
		<dc:creator>mattreyuk</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://mattreyuk.wordpress.com/?p=531</guid>
		<description><![CDATA[My previous post completes what was hopefully a good introduction to Flex 3 so what next? Well don&#8217;t worry, there&#8217;s plenty more stuff out there to learn. To start with, Flex 4 is in beta now and due to be released some time this year. It&#8217;s not a complete redo so there&#8217;s plenty that carries [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=531&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My previous post completes what was hopefully a good introduction to Flex 3 so what next? Well don&#8217;t worry, there&#8217;s plenty more stuff out there to learn.</p>
<p>To start with, Flex 4 is in beta now and due to be released some time this year. It&#8217;s not a complete redo so there&#8217;s plenty that carries over from 3. Many of the changes revolve around the new Spark component set and the way they&#8217;ve separated out appearance (with skinning), states (with the new states design) and behavior. This supports the Catalyst tool as I&#8217;ve covered briefly in <a href="http://mattreyuk.wordpress.com/tag/catalyst/">prior posts</a>.</p>
<p>You can download the SDK for Flex 4 Beta2 from <a href="http://labs.adobe.com/technologies/flex4sdk/">here</a> and use it with FlashDevelop (although it only understands the MX namespace right now so it&#8217;s MXML autocomplete isn&#8217;t very helpful).</p>
<p>There&#8217;s a good article on the differences between Flex 3 &amp; 4 <a href="http://www.adobe.com/devnet/flex/articles/flex3and4_differences.html">here</a> to get you started and that&#8217;s certainly something I plan to post more on in the future.</p>
<p>Another avenue for exploration is frameworks &#8211; if you&#8217;re going to be writing Flex professionally as part of a team or larger apps on your own, you&#8217;re probably going to need to know about them. One of the oldest and most well known is Adobe <a href="http://opensource.adobe.com/wiki/display/cairngorm/Cairngorm">Cairngorm</a>. It&#8217;s sometimes criticized as heavy and requiring a lot of boilerplate code but because it&#8217;s well known, it&#8217;s probably worth at least knowing how it works. A newer contender is the <a href="http://swizframework.org/">Swiz framework</a>. I&#8217;ve seen a couple of presentations on this and plan to get to know it a lot better.</p>
<p>There are plenty of ActionScript libraries you can use, I&#8217;ve already written about <a href="http://mattreyuk.wordpress.com/tag/seam/">Google maps</a> and the <a href="http://mattreyuk.wordpress.com/tag/augmented-reality/">FLAR toolkit manager</a> but I plan to start looking more into data visualization using <a href="http://www.axiis.org/">Axiis</a> in the future.</p>
<p>All in all, I&#8217;d say there&#8217;s plenty to keep me busy here!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattreyuk.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattreyuk.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattreyuk.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattreyuk.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattreyuk.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattreyuk.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattreyuk.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattreyuk.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattreyuk.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattreyuk.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattreyuk.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattreyuk.wordpress.com/531/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattreyuk.wordpress.com/531/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattreyuk.wordpress.com/531/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=531&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattreyuk.wordpress.com/2010/03/17/where-do-we-go-from-here/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed190de5e93656a6623680d1014dcf1f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattreyuk</media:title>
		</media:content>
	</item>
		<item>
		<title>Learning Flex &#8211; Lesson 26, The Basics of Memory Management and Performance</title>
		<link>http://mattreyuk.wordpress.com/2010/03/07/learning-flex-lesson-26-the-basics-of-memory-management-and-performance/</link>
		<comments>http://mattreyuk.wordpress.com/2010/03/07/learning-flex-lesson-26-the-basics-of-memory-management-and-performance/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 01:48:15 +0000</pubDate>
		<dc:creator>mattreyuk</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[learning Flex]]></category>
		<category><![CDATA[memory management]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://mattreyuk.wordpress.com/?p=527</guid>
		<description><![CDATA[There are two basic ways to handle memory allocation. The first (used by C,C++) is to make the developer deal with it &#8211; you are responsible for allocating memory required and freeing it when you&#8217;re done. This allows the developer the freedom to decide when time consuming memory operations are done but the responsibility to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=527&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There are two basic ways to handle memory allocation. The first (used by C,C++) is to make the developer deal with it &#8211; you are responsible for allocating memory required and freeing it when you&#8217;re done. This allows the developer the freedom to decide when time consuming memory operations are done but the responsibility to keep track of everything or run into memory leaks (when unused memory isn&#8217;t released) or null pointer issues and the like when it&#8217;s released too soon.</p>
<p>The alternative chosen by Flash (and Java) is to use the runtime for garbage collection &#8211; i.e. let it decide how to allocate and free memory. The downside to this is that garbage collection can be time consuming and it&#8217;s nondeterministic &#8211; the runtime decides when it&#8217;s going to happen, not the developer.</p>
<p>There are several different algorithms for  garbage collection. The Flash player uses a version comprised of &#8220;reference counting&#8221; and &#8220;mark-and-sweep&#8221;. (For a discussion of various garbage collection strategies see <a href="http://en.wikipedia.org/wiki/Garbage_collection_%28computer_science%29">this article</a>).</p>
<p>For reference counting, the runtime keeps track of all the active references to an object. Each object keeps a reference internally to its children and each child has a reference to its parent. There are also references created explicitly by the developer as a way to access the object in question. If the reference count is zero, nothing can access that object any more so it can be removed and it&#8217;s memory reclaimed.</p>
<p>The second phase, mark-and-sweep is more costly and required to discover circular references &#8211; i.e. objects that reference each other but have no outside references. To perform the mark, the player starts at the root of the application and traverses through its references marking each as it goes. When it&#8217;s reached the leaf nodes of all those references, any objects not marked can be &#8220;swept&#8221; away and deallocated. Due to its cost, this operation is performed iteratively over several frames and is only run occasionally.</p>
<p>What does all this mean to a Flash/Flex developer? Well you should be sure to remove all references to an object when you no longer need it. Often this will be done for you with variables going out of scope etc but you should be proactive in removing longer lived references you no longer require.</p>
<p><strong>Event Listener Leaks</strong></p>
<p>Objects that want to be informed of an event can register as a listener using the addEventListener() method. This results in the creation of a reference to the object doing the listening. Therefore if an object is listening for events, it may not be available for garbage collection.</p>
<p>There is a method called removeEventListener() that can be called to remove the reference when it&#8217;s no longer required which would allow the listener object to be removed when it has no other references. Unfortunately, it&#8217;s not always easy to know when to call this.</p>
<p>An alternative when calling addEventListener() optional parameters may be added, the last of which is a Boolean indicating a weak reference (the default is false). What this means is that if set true, the reference created for the listener is considered weak and not counted as a reference for garbage collection. A listener with only weak references remaining would be eligible for garbage collection. <a href="http://www.gskinner.com/blog/archives/2006/07/as3_weakly_refe.html">Here&#8217;s a post</a> with more on weak references and <a href="http://joeberkovitz.com/blog/2007/06/20/moment-of-weakness-weak-event-listeners-can-be-dangerous/">here&#8217;s an opinion</a> on when they shouldn&#8217;t be used.</p>
<p><strong>Flash/Flex Performance tuning</strong></p>
<p>FlexBuilder (and now FlashBuilder) professional comes with a profiler tool that allows you to investigate the memory usage of your application and time operations to look for areas in need of tuning.</p>
<p>There are no free alternatives that I&#8217;m aware of but you can use <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/utils/package.html#getTimer%28%29"><code>flash.utils.getTimer()</code></a> to time operations and <a href="http://livedocs.adobe.com/flex/3/langref/flash/system/System.html#totalMemory"><code>System.totalMemory</code></a> to keep track of memory use in your application. Grant Skinner also has a <a href="http://www.gskinner.com/blog/archives/2010/02/performancetest.html">performance test harness</a> you might find useful.</p>
<p>A great resource with lots of links to more detailed information on memory management and performance is <a href="http://www.iheartair.com/?page_id=499">this page</a> on Jun Heider&#8217;s blog.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattreyuk.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattreyuk.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattreyuk.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattreyuk.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattreyuk.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattreyuk.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattreyuk.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattreyuk.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattreyuk.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattreyuk.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattreyuk.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattreyuk.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattreyuk.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattreyuk.wordpress.com/527/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=527&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattreyuk.wordpress.com/2010/03/07/learning-flex-lesson-26-the-basics-of-memory-management-and-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed190de5e93656a6623680d1014dcf1f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattreyuk</media:title>
		</media:content>
	</item>
		<item>
		<title>Learning Flex &#8211; Lesson 25, Debugging, Logging and Error Handling</title>
		<link>http://mattreyuk.wordpress.com/2010/02/01/learning-flex-lesson-25-debugging-logging-and-error-handling/</link>
		<comments>http://mattreyuk.wordpress.com/2010/02/01/learning-flex-lesson-25-debugging-logging-and-error-handling/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 05:20:48 +0000</pubDate>
		<dc:creator>mattreyuk</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Flex Tools]]></category>
		<category><![CDATA[learning Flex]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[fdb]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[exceptions]]></category>

		<guid isPermaLink="false">http://mattreyuk.wordpress.com/?p=523</guid>
		<description><![CDATA[Debugging Perhaps the simplest form of debugging is adding a trace() statement to your code to print out when a function is entered or the value of a variable at a particular point. In addition to the global trace() method, the &#60;mx:TraceTarget/&#62; tag allows you to see communication with a remote server. This can be [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=523&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Debugging</strong></p>
<p>Perhaps the simplest form of debugging is adding a <code>trace()</code> statement to your code to print out when a function is entered or the value of a variable at a particular point.</p>
<p>In addition to the global <code>trace()</code> method, the <code>&lt;mx:TraceTarget/&gt;</code> tag allows you to see communication with a remote server. This can be particularly useful in determining what (if anything) your server is returning for your requests.</p>
<p><code>TraceTarget</code> actually sets up the Flex logging API. The appearance of the server communication is down to the fact that the internal Flex components <code>mx.rpc.*</code>, <code>mx.messaging.*</code> and<code> mx.data.*</code> all use this API. We&#8217;ll come back to logging later.</p>
<p>A more interactive strategy for finding errors is to use a debugger. If you&#8217;re fortunate enough to have access to Flex Builder, you have a built-in graphical debugger that will allow you to set breakpoints, inspect variables etc.  If not, the Flex SDK comes with a command line debugger &#8211; fdb. This can be found in the bin directory and started by typing <code>fdb</code> and then <code>run</code> <em>location of swf </em>or just <code>fdb</code> <em>location of swf</em> directly. You can use <code>help</code> or <code>tutorial</code> at the fdb prompt to get information on the commands available. Basically you can set breakpoints (even conditional ones which the Flex Builder version doesn&#8217;t support), step through code and print or change the values of variables. It&#8217;s not quite as easy to use as the Flex Builder version but it will get the job done. There are also some 3rd party free tools available such as <a href="http://www.monsterdebugger.com/">Demonster Debugger</a> which can give you some of the features of a graphical debugger along with memory usage and frame rates but unfortunately, don&#8217;t support breakpoints.</p>
<p>Here&#8217;s <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=debugging_01.html">Adobe&#8217;s info</a> on the command line debugger and here&#8217;s a great chapter <a href="http://digitalmedia.oreilly.com/helpcenter/programmingflex3/chapter18.html">from the book Programming Flex 3</a> that OReilly have kindly put on their website that covers the command line debugger, the Flex Builder debugger and the logging framework.</p>
<p><strong>Logging</strong></p>
<p>The aforementioned OReilly chapter covers this topic really well. You can define different levels of logging (debug, warn etc) and filter on which you want to be logged. You can also determine what happens to your log data so for instance, you could arrange to log particularly worrying errors back to your server or perhaps to a local file that support staff could request users email them if problems occur.</p>
<p><strong>Error Handling</strong></p>
<p>Like most modern languages, ActionScript3 has the concept of exceptions and the associated <code>try</code>, <code>catch</code>, <code>throw</code> and <code>finally</code> commands.</p>
<p>Runtime exceptions occur during the operation of the application, often due to unexpected input or problems communicating with remote systems. In these situations, you can place the potentially troublesome code within a try-catch block like so:</p>
<p><code>try{</code><br />
<em>some dangerous code</em><br />
<code>}catch(e:Error){</code><br />
<em>do something about the error</em><br />
<code>}</code></p>
<p>Within the <code>catch</code> block, you can access properties and methods of the <code>Error</code> object:<code> message</code>; <code>name</code>; <code>getStackTrace()</code> &#8211; for debugger versions of the Flash player, returns the call stack for the error as a <code>String</code> and <code>toString()</code> which returns &#8220;<code>Error</code>&#8221; by default or the value contained in <code>message</code> if defined.</p>
<p>There are a number of error classes defined both by ECMAScript and ActionScript, more details on which can be found <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=11_Handling_errors_14.html">here</a>.</p>
<p>You may define multiple <code>catch</code> blocks to deal with specific error classes. The rules are that the first catch block to satisfy the error will be executed and only one <code>catch</code> block may be run. For this reason, you should never use the base class<code> Error</code> before other catch blocks as it will always take the error.</p>
<p>The <code>throw</code> statement allows you to raise an exception which will bypass the normal operation of your application. You would normally do this if you have discovered a condition that prevents the normal flow of execution. You may either throw an existing error type or create your own by extending the <code>Error</code> class.</p>
<p>The <code>finally</code> statement should be placed after all <code>catch</code> blocks and is used to define code that should be executed regardless of whether an exception was raised or not (generally this is used for something like freeing resources requested in the <code>try</code> block).</p>
<p>Flash player 10.1 introduces the concept of a global error handler so you can trap errors that have otherwise not been processed. This allows you to have a catch-all point where you can at least log something and potentially inform the user before gracefully exiting.</p>
<p>According to the <a href="http://labs.adobe.com/technologies/flashplayer10/releasenotes.pdf">release notes (pdf)</a>, the current beta 2 of 10.1 has this functionality disabled but here&#8217;s a <a href="http://blogs.adobe.com/cantrell/archives/2009/10/global_error_handling_in_air_20.html">blog post</a> from Christian Cantrell on how to do it using Air and here&#8217;s <a href="http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/flash/events/UncaughtErrorEvent.html">some more detail</a> about the <code>UncaughtErrorEvent</code>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattreyuk.wordpress.com/523/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattreyuk.wordpress.com/523/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattreyuk.wordpress.com/523/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattreyuk.wordpress.com/523/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattreyuk.wordpress.com/523/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattreyuk.wordpress.com/523/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattreyuk.wordpress.com/523/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattreyuk.wordpress.com/523/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattreyuk.wordpress.com/523/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattreyuk.wordpress.com/523/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattreyuk.wordpress.com/523/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattreyuk.wordpress.com/523/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattreyuk.wordpress.com/523/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattreyuk.wordpress.com/523/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=523&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattreyuk.wordpress.com/2010/02/01/learning-flex-lesson-25-debugging-logging-and-error-handling/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed190de5e93656a6623680d1014dcf1f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattreyuk</media:title>
		</media:content>
	</item>
		<item>
		<title>Learning Flex &#8211; Lesson 24, Using Shared Objects</title>
		<link>http://mattreyuk.wordpress.com/2010/01/11/learning-flex-lesson-24-using-shared-objects/</link>
		<comments>http://mattreyuk.wordpress.com/2010/01/11/learning-flex-lesson-24-using-shared-objects/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 17:53:02 +0000</pubDate>
		<dc:creator>mattreyuk</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[learning Flex]]></category>
		<category><![CDATA[shared objects]]></category>

		<guid isPermaLink="false">http://mattreyuk.wordpress.com/?p=519</guid>
		<description><![CDATA[It&#8217;s often useful to be able to store data on the client side such as preferences or a saved cart similar to the way websites do using cookies. Flex has the SharedObject class to achieve this which improves on cookies by being able to store complex data structures. Properties assigned to a SharedObject are written [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=519&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s often useful to be able to store data on the client side such as preferences or a saved cart similar to the way websites do using cookies.</p>
<p>Flex has the <code>SharedObject </code>class to achieve this which improves on cookies by being able to store complex data structures.</p>
<p>Properties assigned to a <code>SharedObject</code> are written to a file as soon as the swf is removed from Flash Player either by changing sites or closing down the browser. It&#8217;s also possible to manually force the write in the application.</p>
<p>Shared objects are stored on the end users machine in a location determined by the operating system (you can find out the details <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=lsos_3.html">here</a> ). They have an <code>.sol</code> extension and by default can each be up to 100kb in size (there&#8217;s no limit on their number). The user can use the flash player preferences to change this (right click in Flash window, select settings).</p>
<p>Shared objects cannot contain methods and are not deleted by clearing cookies. Like cookies, shared objects cannot be read from different domains. Note that when testing with Flex Builder, shared objects are limited to the same application as the testing environment opens a local file and does not establish a domain.</p>
<p>The static <code>getLocal()</code> method of the <code>SharedObject</code> class retrieves an existing <code>SharedObject </code>or creates a new one. If you need to write the object to file, you can use the static <code>flush()</code> method. Here&#8217;s an example of creating a <code>SharedObject</code>:</p>
<p><code>var mySO:SharedObject = SharedObject.getLocal("shoppingCart");</code></p>
<p>This creates a file called <code>shoppingCart.sol</code> on the users machine and the <code>SharedObject mySO</code> to refer to it.</p>
<p>To populate the object with data, you assign your values as properties of the data property of the object. For example, to store an <code>email</code> of <code>myEmail@mail.com</code> you would use:</p>
<p><code>mySO.data.email="myEmail@mail.com";</code></p>
<p>To store complex data objects, you must first create them so to store an array of products you would use:</p>
<p><code>mySO.data.products=new Array();<br />
mySO.data.products=productsToSave;</code></p>
<p>When using the <code>flush()</code> method, you may specify a value for the size of the file in bytes. This can be used to create a file larger than initially required. The reason for this is that for the initial write of the file and any time it needs to grow in size, the user will be prompted for approval. by requesting a file size as large as you expect to get, you prevent extra requests for approval every time the shared object is written to.</p>
<p>Flash Player raises an exception when a <code>flush()</code> fails. It returns <code>SharedObjectFlushStatus.FLUSHED<br />
</code> when it&#8217;s successful and <code>SharedObjectFlushStatus.PENDING</code> when the size of the file must increase and the user is being prompted for approval, after which a  <code>netStatus</code> event  is dispatched with an information object detailing the success or failure of the request.</p>
<p>When working with a shared object, it&#8217;s best to check that the value you are about to use is present before attempting to use it. You can achieve this  as follows:</p>
<p><code>if (mySO.data.email != undefined){<br />
  //use the email address<br />
}</code></p>
<p>To empty and remove the shared object, use it&#8217;s <code>clear()</code> method.</p>
<p>When using <code>SharedObject</code>s in a swf, make sure your display object is at least 215 pixels wide and at least 138 pixels high or the dialog prompt to increase storage cannot be displayed and the <code>flush()</code> call will fail.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattreyuk.wordpress.com/519/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattreyuk.wordpress.com/519/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattreyuk.wordpress.com/519/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattreyuk.wordpress.com/519/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattreyuk.wordpress.com/519/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattreyuk.wordpress.com/519/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattreyuk.wordpress.com/519/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattreyuk.wordpress.com/519/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattreyuk.wordpress.com/519/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattreyuk.wordpress.com/519/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattreyuk.wordpress.com/519/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattreyuk.wordpress.com/519/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattreyuk.wordpress.com/519/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattreyuk.wordpress.com/519/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=519&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattreyuk.wordpress.com/2010/01/11/learning-flex-lesson-24-using-shared-objects/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed190de5e93656a6623680d1014dcf1f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattreyuk</media:title>
		</media:content>
	</item>
		<item>
		<title>Learning Flex – Lesson 23, Printing From Flex</title>
		<link>http://mattreyuk.wordpress.com/2009/12/21/learning-flex-%e2%80%93-lesson-23-printing-from-flex/</link>
		<comments>http://mattreyuk.wordpress.com/2009/12/21/learning-flex-%e2%80%93-lesson-23-printing-from-flex/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 05:11:55 +0000</pubDate>
		<dc:creator>mattreyuk</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[learning Flex]]></category>
		<category><![CDATA[printing]]></category>

		<guid isPermaLink="false">http://mattreyuk.wordpress.com/?p=512</guid>
		<description><![CDATA[Flex allows for printing from an application by using the FlexPrintJob class which is a wrapper for the flash.printing.PrintJob class. This allows you to specify one or more objects to be printed. The objects can be containers or custom components and you can specify a separate format that is not visible to the user. The [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=512&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Flex allows for printing from an application by using the <code>FlexPrintJob</code> class which is a wrapper for the<code> flash.printing.PrintJob</code> class. This allows you to specify one or more objects to be printed. The objects can be containers or custom components and you can specify a separate format that is not visible to the user.</p>
<p>The basic process is as follows:</p>
<ol>
<li>Instantiate a <code>FlexPrintJob</code> object</li>
<li>call it&#8217;s<code> start()</code> method to begin the print process &#8211; this will cause the OS to display a print dialog and returns  <code>true</code> if they accept or <code>false</code> if they cancel out.</li>
<li>Add the object(s) to be printed using the <code>addObject() </code>method</li>
<li>Send the job to the printer using the <code>send()</code> method</li>
<li>clean up any temporary objects no longer needed.</li>
</ol>
<p>Between the <code>start()</code> and <code>send()</code> calls, a print job is spooled to the host operating system so only print specific work should be performed at this time.</p>
<p>It&#8217;s good practice to check the return of the <code>start()</code> method and abort the print attempt if it returns false.</p>
<p>If you try to hide the print version of a component by setting it&#8217;s visible property false, it will still occupy space in the layout. An alternative is to define the print layout in a custom component then define and instance and add it in your print process using the addchild() method of the application. You can then remove it using removeChild() as part of the print job cleanup. Your print code would then look something like this:</p>
<pre class="brush: as3;">
var printJob:FlexPrintJob = new FlexPrintJob();
if(printJob.start() != true){
  return;
}
var myPrintcontainer:CustomPrint = new CustomPrint();
addChild(myPrintContainer);
printJob.addObject(myPrintContainer);
printJob.send();
removeChild(myPrintContainer);
</pre>
<p>The output can be scaled by adding a parameter to the <code>addObject()</code> call. The options are static constants from the <code>FlexPrintJobScaleType</code> class:</p>
<ul>
<li><code>MATCH_WIDTH</code> &#8211; scales the printed output to match the page width. If the height exceeds the width, the output will span multiple pages (default)</li>
<li><code>MATCH_HEIGHT</code> &#8211; scales the printed output to fill the page height. If the width exceeds the height, the output will span multiple pages.</li>
<li><code>SHOW_ALL</code> &#8211; scales the printed output to fit on a single page, filling the smaller of width or height.</li>
<li><code>FILL_PAGE</code> &#8211; scales the printed output to fill at least one page. It selects the larger of width or height.</li>
<li><code>NONE</code> &#8211; the printed output matches the dimensions of the object on the screen.</li>
</ul>
<p>To aid with printing data grids, there are print versions of data grid classes namely <code>PrintDataGrid</code>, <code>PrintAdvancedDataGrid</code> and<code> PrintOLAPDataGrid</code>. These have default appearances designed for printing and methods to support multiple page printing.</p>
<p>A <code>PrintDataGrid</code> will only print the rows that are visible by default. The property <code>sizeToPage</code> specifies that partially visible rows are not printed if it&#8217;s set <code>true</code> (default). To print rows below a scrollbar, you must use the <code>nextPage()</code> method and <code>validNextPage boolean</code> property.</p>
<p>While<code> validNextPage</code> is <code>true</code>, call <code>nextPage()</code> and then add the <code>PrintDataGrid</code> object to the print job.</p>
<p>Flex printing can look somewhat blurry on the page and does not always produce the results desired. For a great series of posts on an alternative, (AlivePDF) take a look at <a href="http://www.kalengibbons.com/blog/index.php?s=printing">these posts</a> from Kalen Gibbons.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattreyuk.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattreyuk.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattreyuk.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattreyuk.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattreyuk.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattreyuk.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattreyuk.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattreyuk.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattreyuk.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattreyuk.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattreyuk.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattreyuk.wordpress.com/512/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattreyuk.wordpress.com/512/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattreyuk.wordpress.com/512/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=512&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattreyuk.wordpress.com/2009/12/21/learning-flex-%e2%80%93-lesson-23-printing-from-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed190de5e93656a6623680d1014dcf1f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattreyuk</media:title>
		</media:content>
	</item>
		<item>
		<title>Learning Flex &#8211; Lesson 22, Creating Transitions and Behaviors</title>
		<link>http://mattreyuk.wordpress.com/2009/12/09/learning-flex-lesson-22-creating-transitions-and-behaviors/</link>
		<comments>http://mattreyuk.wordpress.com/2009/12/09/learning-flex-lesson-22-creating-transitions-and-behaviors/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 05:45:14 +0000</pubDate>
		<dc:creator>mattreyuk</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[learning Flex]]></category>
		<category><![CDATA[behavior]]></category>
		<category><![CDATA[effects]]></category>
		<category><![CDATA[transition]]></category>

		<guid isPermaLink="false">http://mattreyuk.wordpress.com/?p=502</guid>
		<description><![CDATA[Behaviors and transitions allow you to add animation and sound effects to your application. Behaviors are effects that can be applied directly on components, transitions are these effects applied to application states. Some of the effects available are: fade, dissolve, move/resize, rotate, wipe, glow and play sound. These effects can be used to draw the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=502&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Behaviors and transitions allow you to add animation and sound effects to your application. Behaviors are effects that can be applied directly on components, transitions are these effects applied to application states.</p>
<p>Some of the effects available are: fade, dissolve, move/resize, rotate, wipe, glow and play sound.</p>
<p>These effects can be used to draw the user&#8217;s attention to items changing on the screen or give cues as to which elements they can interact with.</p>
<p><strong>Behaviors</strong></p>
<p>When applied to components, behaviors are made up of a trigger and an effect.</p>
<p>The trigger is the action taking place on the component such as a button click or gaining focus. It is important to note that triggers are different to events. A component would have a <code>mouseDownEffect</code> trigger as well as a <code>mouseDown</code> event. When you use a trigger, you do not specify an event handler, instead you specify the effect to occur.</p>
<p>You can directly specify an effect class name for a trigger such as:</p>
<p><code>&lt;mx:VBox showEffect="Fade"/&gt;</code></p>
<p>but in this case, you are limited to one effect and cannot customize it.</p>
<p>You may define an effect tag and specify desired properties that can then be provided to a trigger using data binding on the effect id such as:</p>
<p><code>&lt;mx:Fade id="myFade" duration="2000"/&gt;<br />
&lt;mx:VBox showEffect="{myFade}"/&gt;</code></p>
<p>You can apply multiple effects to the same trigger by using the <code>&lt;mx:Sequence&gt;</code> or <code>&lt;mx:Parallel&gt;</code> tags by nesting effects within them to occur in order (using <code>&lt;mx:Sequence&gt;</code>) or all together (using <code>&lt;mx:Parallel&gt;</code>). You can even nest these tags for more involved effects.</p>
<p>As effect triggers are implemented as CSS styles, you can specify them using an <code>&lt;mx:Style&gt;</code> tag:</p>
<p><code>&lt;mx:Style&gt;<br />
List {showEffect : myFade;}<br />
&lt;/mx:Style&gt;</code></p>
<p>which will make all lists have the same show effect (unless you override it in a specific list configuration, or:</p>
<p><code>&lt;mx:Style&gt;<br />
.fadeStyle { showEffect : myFade;}<br />
&lt;/mx:Style&gt;</code></p>
<p>which will display this effect for all components with the <code>styleName</code> property set to <code>fadeStyle</code>.</p>
<p>It&#8217;s also possible to play effects at other times by calling the effect&#8217;s <code>play()</code> method (you can optionally specify an array of components to perform the effect on and a <code>boolean</code> value which when set to <code>true</code>, will play the effect backwards. There&#8217;s also an end() method to end the effect (this is often called immediately before play() to stop any outstanding effects).</p>
<p>Effects can be used for changes in data provided by a <code>dataProvider</code> in a List or TileList. More information about this can be found <a href="http://livedocs.adobe.com/flex/3/html/behaviors_09.html#276561">here</a>.</p>
<p>More control over the animation of an effect may be provided by using an easing function. All effect classes that are children of the <code>TweenEffect</code> or<code> MaskEffect</code> classes support the <code>easingFunction</code> property. Some components have easing function style properties that can be used directly.  More information on easing functions can be found <a href="http://livedocs.adobe.com/flex/3/html/behaviors_08.html#276431">here</a>.</p>
<p>You can play a sound effect by using the <code>&lt;mx:SoundEffect&gt;</code> tag and specifying the url of an MP3 file in the <code>source</code> property. Alternatively, if you&#8217;ve already embedded  the sound file, you may use data binding to refer to it&#8217;s class object here.  There are also several properties to determine the duration, start point in the file, volume start and end values etc (you can find out the full details <a href="http://livedocs.adobe.com/flex/3/langref/mx/effects/SoundEffect.html">here</a>) .</p>
<p><strong>Transitions</strong></p>
<p>Transitions are effects for application states. They must be declared as children of an <code>&lt;mx:transitions&gt;</code> tag (this is a property of the application). Each <code>&lt;mx:Transition&gt;</code> has a <code>fromState</code> &#8211; the view state you&#8217;re moving from, <code>toState</code> &#8211; the view state you&#8217;re moving to and the effect object you want to play when the transition occurs. You can specify a <code>target</code> or <code>targets</code> (array of target objects) for the effect either in the effect tag directly or at a higher level within an <code>&lt;mx:Sequence&gt;</code> or <code>&lt;mx:Parallel&gt;</code> tag. An example would be:</p>
<p><code>&lt;mx:transitions&gt;<br />
&lt;mx:Transition fromState="START" toState="*"&gt;<br />
&lt;mx:Dissolve duration="2000"  target="{myContainer}"/&gt;<br />
&lt;/mx:Transition&gt;<br />
&lt;/mx:transitions&gt;</code></p>
<p>Once the transitions are declared, they are triggered by changing the application&#8217;s <code>currentState </code>property.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mattreyuk.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mattreyuk.wordpress.com/502/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mattreyuk.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mattreyuk.wordpress.com/502/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mattreyuk.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mattreyuk.wordpress.com/502/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mattreyuk.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mattreyuk.wordpress.com/502/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mattreyuk.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mattreyuk.wordpress.com/502/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mattreyuk.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mattreyuk.wordpress.com/502/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mattreyuk.wordpress.com/502/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mattreyuk.wordpress.com/502/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mattreyuk.wordpress.com&amp;blog=7292162&amp;post=502&amp;subd=mattreyuk&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mattreyuk.wordpress.com/2009/12/09/learning-flex-lesson-22-creating-transitions-and-behaviors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ed190de5e93656a6623680d1014dcf1f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">mattreyuk</media:title>
		</media:content>
	</item>
	</channel>
</rss>
