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

<channel>
	<title>dndigital.net &#187; Flex</title>
	<atom:link href="http://dndigital.net/category/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://dndigital.net</link>
	<description>Notes on Adobe Flash, Flex, AIR Development</description>
	<lastBuildDate>Wed, 22 Jun 2011 11:15:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Advanced Actionscript Tutorial &#8211; The Abstract Factory Design Pattern</title>
		<link>http://dndigital.net/2010/07/advanced-actionscript-tutorial-the-abstract-factory-design-pattern/</link>
		<comments>http://dndigital.net/2010/07/advanced-actionscript-tutorial-the-abstract-factory-design-pattern/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 11:17:58 +0000</pubDate>
		<dc:creator>Nils</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Free Tutorials]]></category>

		<guid isPermaLink="false">http://dndigital.net/?p=180</guid>
		<description><![CDATA[Although it wasn&#8217;t always the case, these days a good understanding of object oriented programming principles and the use of common design patterns are essential in order to become a successful Actionscript developer. When we&#8217;re working on projects, the Head First Design Patterns book is never far away &#8211; and one of the patterns that [...]]]></description>
			<content:encoded><![CDATA[<p>Although it wasn&#8217;t always the case, these days a good understanding of object oriented programming principles and the use of common design patterns are essential in order to become a successful Actionscript developer. When we&#8217;re working on projects, the <a href="http://www.amazon.co.uk/Head-First-Design-Patterns-Freeman/dp/0596007124/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1278608410&amp;sr=8-1" target="_blank">Head First Design Patterns</a> book is never far away &#8211; and one of the patterns that has been incredibly useful time and time again is the Abstract Factory and variations thereof, so I thought we&#8217;d dedicate a YouTube tutorial to it.</p>
<p>I&#8217;d love to hear about your own experiences in regards to object oriented programming in AS3 &#8211; please leave a comment!</p>
<p>The material in this blog post and in the video is an excerpt from our <a href="http://dndigital.net/training/advanced-as3-oop-patterns/">Advanced Actionscript 3 (Object Oriented Programming and Design Patterns) training course</a>.</p>
<p>You can watch the video and read up on the details after the break.</p>
<p><span id="more-180"></span></p>
<h2>Making Choices</h2>
<p>The Abstract Factory Design Pattern is all about choice. Not any kind of choice mind you &#8211; but very specifically choosing which class to instantiate given certain conditions. Whether you realise it or not, you are probably making these choices numerous times in your own programming code. Here are some examples:</p>
<ul>
<li>Which type of menu to display based on the admin privileges of the current user</li>
<li>Which type of skin to apply to your game characters, based on the selections made at the beginning of the game &#8211; and subsequently which types of weapons are available for that character</li>
<li>Which type of button graphic to use based on the size of a banner</li>
<li>Which type of XML parser to use based on the type of feed the user has loaded in</li>
</ul>
<p>and so on. Once you&#8217;re dealing with object oriented programming, most of those choices are going to result in a class being instantiated and the trick is to choose the correct class based on a set of circumstances.</p>
<p>No problem, right? You just whack an if-statement in there:</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> user.<span style="color: #006600;">isAdmin</span> <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #0066CC;">menu</span> = <span style="color: #000000; font-weight: bold;">new</span> AdminMenu<span style="color: #66cc66;">&#40;</span><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: #0066CC;">menu</span> = <span style="color: #000000; font-weight: bold;">new</span> NormalMenu<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h2>Weeds Everywhere</h2>
<p>Of course, using if-statements will work fine, however it spreads the choices throughout your application, like a weed taking a strong-hold in your garden, then your front lawn, then your walls&#8230;you get the picture. Suppose you introduce a third user privilege level? Time to revisit all those many if-statements (of course you&#8217;ll remember where they are!). The more complex your project, the more difficult, time-consuming and error prone such a change becomes.</p>
<h2>Factory Pattern to the Rescue</h2>
<p>It is in these cases that the Factory Design Pattern comes to your rescue, by moving the choice into a single, isolated piece of code. The resulting class that is instantiated &#8211; the factory &#8211; will then provide the application with the correct class instances. As a result, you only need to change the single point-of-choice and create a new factory class in order to make wide-ranging changes to your entire application.</p>
<p>In practice, it looks something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// isolated choice code (eg. after user logs in)</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> user.<span style="color: #006600;">isAdmin</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    factory = <span style="color: #000000; font-weight: bold;">new</span> AdminUserFactory<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span>
    factory = <span style="color: #000000; font-weight: bold;">new</span> NormalUserFactory<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;">// and in the AdminUserFactory class:</span>
<span style="color: #000000; font-weight: bold;">function</span> getMenu<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Menu</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> AdminMenu<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;">// and in the NormalUserFactory class:</span>
<span style="color: #000000; font-weight: bold;">function</span> getMenu<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Menu</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> NormalMenu<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;">// much later, in a remote location in your code-tree</span>
<span style="color: #0066CC;">menu</span> = factory.<span style="color: #006600;">getMenu</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Can you see how you would add a third user level &#8211; and how much more manageable it has become compared to the previous example?</p>
<p>Let&#8217;s follow the example code through to its logical conclusion. Say we have 10 user levels. Then we&#8217;ll end up with 10 different factory classes (AdminUserFactory, NormalUserFactory, SuperUserFactory, etc). So far so good. But how does the code that is actually using the factory to retrieve the menu know how to deal with all those 10 different classes without using another if-statement? Surely that will lead to type-errors if we don&#8217;t know the exact data-type?</p>
<h2>Interfacing with the Factory</h2>
<p>In order to allow code throughout your application to use different factory classes, we&#8217;re going to use an interface to define what methods a factory class provides. This interface will be used as the data-type when passing the factory around to other pieces of code. So in practice it doesn&#8217;t matter which factory class is used behind the scenes and dependencies within your code are reduced to a single interface class, which is what we like to see!</p>
<p>Our user-menu example seems to use factory to create its user-interface elements, so let&#8217;s create an interface called IUIFactory. We start with just a single function &#8211; we can always add to it later on:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// in the IUIFactory.as file</span>
<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">interface</span> IUIFactory <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">function</span> getMenu<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Menu</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>As a rule, you&#8217;d start with your interface first, then create your first factory class and then create your choice code &#8211; otherwise you&#8217;ll end up in a bit of a pickle.</p>
<p>Here is the sample code from earlier, with the interface thrown in.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// we start with an interface</span>
<span style="color: #000000; font-weight: bold;">var</span> factory:IUIFactory;
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span> user.<span style="color: #006600;">isAdmin</span> <span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#123;</span>
    factory = <span style="color: #000000; font-weight: bold;">new</span> AdminUserFactory<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #66cc66;">&#123;</span>
    factory = <span style="color: #000000; font-weight: bold;">new</span> NormalUserFactory<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;">// and in the AdminUserFactory class - which implements IUIFactory</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getMenu<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Menu</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> AdminMenu<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;">// and in the NormalUserFactory class - which also implements IUIFactory</span>
<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getMenu<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Menu</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> NormalMenu<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;">// much later, in a remote location in your code-tree</span>
<span style="color: #000000; font-weight: bold;">var</span> factory:IUIFactory;
<span style="color: #0066CC;">menu</span> = factory.<span style="color: #006600;">getMenu</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Splendid.</p>
<p>Another beneficial side-effect of using an interface in this way comes into play when adding new features to your factory. Any new feature requires a new method in your factory interface. That new method will immediately result in compiler errors because none of your factory classes has implemented it yet. You have no option but to implement the new method in every single factory class &#8211; hence automatically making sure that your code is properly maintained.</p>
<p>Doesn&#8217;t that sound better than finding a long-lost if-statement deep down in the murky depths of your code-tree that your colleague forgot to change when they added a new user-group?</p>
<h2>YouTube Tutorial and Source Code</h2>
<p>The YouTube tutorial steps through a different example of coding a user-interface that can change depending on the age-group of the viewer.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="640" height="385" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/spfienbiqqs&amp;hl=en_GB&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="640" height="385" src="http://www.youtube.com/v/spfienbiqqs&amp;hl=en_GB&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>You can <a title="Factory Design Pattern Source Code" href="http://dndigital.net/wp/wp-content/uploads/2010/07/dndigital-abstract-factory.zip">download the source-code as a FlashBuilder 4 project</a> so that you can follow the tutorial and experiment further. There are a couple of extra images in the assets folder so you can produce a third factory class. Copyright / licensing info is included in each file, all images used are publicly available via <a href="http://sxc.hu" target="_blank">sxc.hu</a>.</p>
<h2>Further Thoughts &#8211; Factory Pattern and Dependency Injection</h2>
<p>The Factory Design Pattern&#8217;s strengths come from isolating choices in a single location. Furthermore, each factory class also encapsulates a very simple set of actions &#8211; it knows how to create the correct instances but doesn&#8217;t require knowledge of the surrounding application to do so &#8211; so we are adhering to the  &#8217;one class &#8211; one responsibility&#8217; concept.</p>
<p>Of course you still need to pass the actual factory instance around to the classes that require them and there are various ways of managing these dependencies. In the YouTube tutorial, I simply pass the factory instance to the view classes via their constructor and this is a perfectly valid way of handling it.</p>
<p>There are of course other options &#8211; and Dependency Injection (DI) is especially helpful when working with the factory pattern.</p>
<p>Since DI hinges in principal around matching interface data-types to concrete classes, switching factory classes becomes a doddle. You simply specify the appropriate factory class to be used when the DI container encounters the factory interface and your project can be dramatically changed by essentially touching only a single line of code. This is especially true when there is a fixed, pre-determined choice of factory class, for example when repurposing an entire project for a different market or target audience.</p>
<p>I&#8217;d love to hear your own experiences of the Factory Pattern and OOP in general &#8211; leave a note in the comments below.</p>
]]></content:encoded>
			<wfw:commentRss>http://dndigital.net/2010/07/advanced-actionscript-tutorial-the-abstract-factory-design-pattern/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RobotLegs Flex Popup Example</title>
		<link>http://dndigital.net/2009/10/robotlegs-as3-framework-flex-popup-example/</link>
		<comments>http://dndigital.net/2009/10/robotlegs-as3-framework-flex-popup-example/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 14:29:50 +0000</pubDate>
		<dc:creator>Nils</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[RobotLegs AS3]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://dndigital.net/blog/?p=39</guid>
		<description><![CDATA[There has been some discussion on the RobotLegs AS3 Framework Google Group about the best workflow for launching popups in Flex, so I thought I&#8217;d do a quick sample. The workflow consists of: A Command to launch the popup (via the Flex PopupManager) A Mediator that handles events coming from the popup view component The [...]]]></description>
			<content:encoded><![CDATA[<p>There has been some discussion on the <a href="http://groups.google.com/group/robotlegs">RobotLegs AS3 Framework Google Group</a> about the best workflow for launching popups in Flex, so I thought I&#8217;d do a quick sample.<span id="more-39"></span></p>
<p>The workflow consists of:</p>
<ul>
<li>A Command to launch the popup (via the Flex PopupManager)</li>
<li>A Mediator that handles events coming from the popup view component</li>
</ul>
<p>The popup view component&#8217;s Mediator also handles closing of the popup and removes itself from the RobotLegs mediatorMap when it&#8217;s no longer required.</p>
<p>Note: I should point out that the source for the SWF below includes only some of the RobotLegs framework source-code. To run the source-code, please <a href="http://github.com/robotlegs/robotlegs-framework">download the current version of RobotLegs</a>. </p>
<p>Here&#8217;s the SWF and sample code. Feel free to use and abuse, no warranties given or implied. <a href="http://tutorials.dndigital.net/flex/robotlegstitlewindow/srcview/" target="_blank">View source</a></p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_RobotLegsTitleWindow_288317580"
			class="flashmovie"
			width="400"
			height="400">
	<param name="movie" value="http://tutorials.dndigital.net/flex/robotlegstitlewindow/RobotLegsTitleWindow.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://tutorials.dndigital.net/flex/robotlegstitlewindow/RobotLegsTitleWindow.swf"
			name="fm_RobotLegsTitleWindow_288317580"
			width="400"
			height="400">
	<!--<![endif]-->
		
<p><a href="http://adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p><a href="http://tutorials.dndigital.net/flex/robotlegstitlewindow/srcview/" target="_blank">View source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://dndigital.net/2009/10/robotlegs-as3-framework-flex-popup-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mastercard Priceless Travel Flex app now live</title>
		<link>http://dndigital.net/2008/08/mastercard-priceless-travel-flex-app-now-live/</link>
		<comments>http://dndigital.net/2008/08/mastercard-priceless-travel-flex-app-now-live/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 15:54:22 +0000</pubDate>
		<dc:creator>Nils</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[PureMVC]]></category>

		<guid isPermaLink="false">http://dndigital.net/blog/?p=25</guid>
		<description><![CDATA[After many weeks of hard work the Mastercard Priceless Travel Flex 3 application I&#8217;ve been working on has now also gone live. I worked on the project as sole Flex developer / Flex architect, together with a team of talented and enthusiastic people. It was another project I completed for MRM Worldwide in London and [...]]]></description>
			<content:encoded><![CDATA[<p>After many weeks of hard work the Mastercard Priceless Travel Flex 3 application I&#8217;ve been working on has now also gone live. I worked on the project as sole Flex developer / Flex architect, together with a team of talented and enthusiastic people. It was another project I completed for MRM Worldwide in London and I thoroughly enjoyed it as always.</p>
<p>Apart from Flex 3, the project also uses the PureMVC framework. I&#8217;ve been using it for a few projects now and have to say that overall I&#8217;m very happy with it&#8217;s structure. The Priceless Travel application had some major changes applied to it during the development lifecycle and architecturally speaking they were all handled with ease.</p>
<p>You can view the project via the link from <a href="http://portfolio.dndigital.net">my online portfolio</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://dndigital.net/2008/08/mastercard-priceless-travel-flex-app-now-live/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex UIComponent subclass needs to resize images</title>
		<link>http://dndigital.net/2008/08/flex-uicomponent-subclass-needs-to-resize-images/</link>
		<comments>http://dndigital.net/2008/08/flex-uicomponent-subclass-needs-to-resize-images/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 12:57:17 +0000</pubDate>
		<dc:creator>Nils</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Image]]></category>
		<category><![CDATA[UIComponent]]></category>

		<guid isPermaLink="false">http://dndigital.net/blog/?p=15</guid>
		<description><![CDATA[The title could do with some improving &#8211; what I&#8217;m trying to say is that when subclassing UIComponent, any Image component instances need to be given an appropriate width/height. I have overlooked this time and time again, only to find that the image doesn&#8217;t appear &#8211; because it&#8217;s width and height are initialised to zero. [...]]]></description>
			<content:encoded><![CDATA[<p>The title could do with some improving &#8211; what I&#8217;m trying to say is that when subclassing UIComponent, any Image component instances need to be given an appropriate width/height. I have overlooked this time and time again, only to find that the image doesn&#8217;t appear &#8211; because it&#8217;s width and height are initialised to zero.</p>
<p>The following code will result in an image with zero width/height, so the image won&#8217;t show:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> img:Image = <span style="color: #000000; font-weight: bold;">new</span> Image<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
img.<span style="color: #006600;">source</span> = <span style="color: #ff0000;">&quot;myfile.jpg&quot;</span>;</pre></div></div>

<p>Solutions:</p>
<ol>
<li>Assign specific values for width and height:

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">img.<span style="color: #0066CC;">width</span> = <span style="color: #cc66cc;">100</span>;
img.<span style="color: #0066CC;">height</span> = <span style="color: #cc66cc;">100</span>;</pre></div></div>

</li>
<li>Set the &#8216;scaleContent&#8217; property to false &#8211; the image will then resize its container automatically, once it has loaded. Note that this technique <strong>has no effect if loading image from non-trusted domains</strong>!

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">img.<span style="color: #006600;">scaleContent</span> = <span style="color: #000000; font-weight: bold;">false</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// or, if loading cross-domain, provided a crossdomain policy file allows access</span>
img.<span style="color: #006600;">trustContent</span> = <span style="color: #000000; font-weight: bold;">true</span>;
img.<span style="color: #006600;">scaleContent</span> = <span style="color: #000000; font-weight: bold;">false</span>;</pre></div></div>

</li>
<li>Use an event listener to detect when the image has finished loading, then assign the correct width and height. <strong>Again, this will only work if the image has been loaded from a trusted domain.</strong>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">img.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, onImageComplete<span style="color: #66cc66;">&#41;</span>;
&nbsp;
protected <span style="color: #000000; font-weight: bold;">function</span> onImageComplete<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> img:Image = evt.<span style="color: #0066CC;">target</span> as Image;
    img.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, onImageComplete<span style="color: #66cc66;">&#41;</span>;
    img.<span style="color: #0066CC;">width</span> = img.<span style="color: #006600;">content</span>.<span style="color: #0066CC;">width</span>;
    img.<span style="color: #0066CC;">height</span> = img.<span style="color: #006600;">content</span>.<span style="color: #0066CC;">height</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

</li>
</ol>
<p>I&#8217;ve mainly blogged about it so I remember the next time I write some code &#8211; but maybe it will also help somebody else debug their missing image problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://dndigital.net/2008/08/flex-uicomponent-subclass-needs-to-resize-images/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Crossdomain Flex and Flash SOAP Webservice access</title>
		<link>http://dndigital.net/2008/08/crossdomain-flex-and-flash-soap-webservice-access/</link>
		<comments>http://dndigital.net/2008/08/crossdomain-flex-and-flash-soap-webservice-access/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 12:00:06 +0000</pubDate>
		<dc:creator>Nils</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://dndigital.net/blog/?p=9</guid>
		<description><![CDATA[Here&#8217;s a quick guide on how to get crossdomain access working for SOAP Webservices from Flash and Flex. Obviously you need to allow access to the domain, however it&#8217;s more difficult to realise that you also need to allow the SOAP headers to be sent to the foreign server. Here is an example crossdomain file [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick guide on how to get crossdomain access working for SOAP Webservices from Flash and Flex. Obviously you need to allow access to the domain, however it&#8217;s more difficult to realise that you also need to allow the SOAP headers to be sent to the foreign server.</p>
<p>Here is an example crossdomain file that does just that &#8211; amend to suit your own requirements, the * wildcard is probably not what you need for your production server.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://dndigital.net/2008/08/crossdomain-flex-and-flash-soap-webservice-access/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Accessing flashvars in a custom Flex preloader</title>
		<link>http://dndigital.net/2008/08/accessing-flashvars-in-a-custom-flex-preloader/</link>
		<comments>http://dndigital.net/2008/08/accessing-flashvars-in-a-custom-flex-preloader/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 00:24:37 +0000</pubDate>
		<dc:creator>Nils</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[custom preloader]]></category>
		<category><![CDATA[flashvars]]></category>

		<guid isPermaLink="false">http://dndigital.net/blog/?p=3</guid>
		<description><![CDATA[Here&#8217;s a little code snippet that allows you to access flashvar parameters inside a custom Flex preloader. The custom preloader class extends Sprite and implements the IPreloaderDisplay class. Once the Sprite&#8217;s &#8216;root&#8217; property becomes available, you can use the standard AS3 way of accessing flashvars, namely: var flashvars:Object = root.loaderInfo.parameters; This code should be used [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little code snippet that allows you to access flashvar parameters inside a custom Flex preloader.</p>
<p>The custom preloader class extends Sprite and implements the IPreloaderDisplay class. Once the Sprite&#8217;s &#8216;root&#8217; property becomes available, you can use the standard AS3 way of accessing flashvars, namely:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> flashvars:<span style="color: #0066CC;">Object</span> = root.<span style="color: #006600;">loaderInfo</span>.<span style="color: #006600;">parameters</span>;</pre></div></div>

<p>This code should be used once the &#8216;root&#8217; property has been initialised &#8211; for example in the &#8216;initialize()&#8217; method defined by the IPreloaderDisplay interface:</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;">function</span> initialize<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">var</span> flashvars:<span style="color: #0066CC;">Object</span> = root.<span style="color: #006600;">loaderInfo</span>.<span style="color: #006600;">parameters</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Just for reference, compare the above approach with the standard Flex method of accessing flashvar parameters &#8211; which becomes possible once the main Application instance has been created:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> flashvars:<span style="color: #0066CC;">Object</span> = Application.<span style="color: #006600;">application</span>.<span style="color: #006600;">parameters</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://dndigital.net/2008/08/accessing-flashvars-in-a-custom-flex-preloader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

