﻿<?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>Digital Primates&#187; runtime</title>
	<atom:link href="http://www.digitalprimates.net/author/category/runtime/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.digitalprimates.net</link>
	<description>Development and Consulting</description>
	<lastBuildDate>Thu, 16 May 2013 21:25:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Reflecting an image in Flex</title>
		<link>http://www.digitalprimates.net/author/tapper/2007/09/21/reflecting-an-image-in-flex/</link>
		<comments>http://www.digitalprimates.net/author/tapper/2007/09/21/reflecting-an-image-in-flex/#comments</comments>
		<pubDate>Fri, 21 Sep 2007 14:09:00 +0000</pubDate>
		<dc:creator>tapper</dc:creator>
				<category><![CDATA[actionscript3]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flash9]]></category>
		<category><![CDATA[flashplayer]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flex2]]></category>
		<category><![CDATA[flex3]]></category>
		<category><![CDATA[fp9]]></category>
		<category><![CDATA[runtime]]></category>

		<guid isPermaLink="false">http://test.digitalprimates.net/2007/09/21/reflecting-an-image-in-flex/</guid>
		<description><![CDATA[Increasingly, clients have been asking for a &#34;reflection&#34; effect, showing a vertically flipped image of a component next to the actual component.&#160; After reinventing the wheel on this several times, I came up with this simple reusable component:package com.tappernimer.components{import mx.containers.Canvas;import &#8230; <a href="http://www.digitalprimates.net/author/tapper/2007/09/21/reflecting-an-image-in-flex/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Increasingly, clients have been asking for a &quot;reflection&quot; effect, showing a vertically flipped image of a component next to the actual component.&#160; After reinventing the wheel on this several times, I came up with this simple reusable component:</p><pre>package com.tappernimer.components{</pre><blockquote><pre>import mx.containers.Canvas;</pre><pre>import mx.core.UIComponent;</pre><pre>import flash.display.BitmapData;</pre><pre>import flash.geom.Matrix;</pre><pre>import flash.display.IBitmapDrawable;</pre><pre>public class VerticalReflection extends Canvas{</pre><blockquote><pre>private var _component:UIComponent;</pre><pre>public var trans:Number=.5;</pre><pre>public var filterArray:Array=new Array();</pre><pre>public var skewY:Number=0;</pre><pre>public var skewX:Number=0;</pre><pre>public function get component():UIComponent{</pre><blockquote><pre>return _component;</pre></blockquote><pre>}</pre></blockquote></blockquote><blockquote><blockquote><pre>public function set component(c:UIComponent):void{</pre><blockquote><pre>this._component = c;</pre><pre>// hack to work around issue with component being </pre><pre>// a dynamically loaded image its possible for the </pre><pre>// image to be fully loaded, but its height or width </pre><pre>// not yet set this call later, keeps retrying until </pre><pre>// the values are set.</pre><pre>if(c.width ==0 || c.height==0){</pre><blockquote><pre>callLater(resetComponent,);</pre><pre>return;</pre></blockquote><pre>}</pre></blockquote></blockquote><blockquote><blockquote><pre>doReflection();</pre></blockquote></blockquote><blockquote><pre>}</pre></blockquote></blockquote><blockquote><blockquote><pre>private function resetComponent(c:UIComponent):void{</pre><blockquote><pre>this.component = c;</pre></blockquote><pre>}</pre></blockquote></blockquote><blockquote><blockquote><pre>private function doReflection():void {</pre><blockquote><pre>// create bitmap object</pre><pre>var bmpData:BitmapData = new BitmapData(</pre><pre>	component.width,component.height);</pre><pre>// create matrix</pre><pre>var invertMatrix:Matrix = new Matrix(1,skewY,skewX);</pre><pre>// set matrix to invert vertically, but normal horizontally</pre><pre>invertMatrix.scale(1, -1);</pre><pre>// move matrix, so top is at bottom, and vice versa</pre><pre>invertMatrix.translate(0, component.height);</pre><pre>// draw component flipped</pre><pre>bmpData.draw(component as IBitmapDrawable,invertMatrix);</pre><pre>// create a new holder for the image</pre><pre>var ref:UIComponent = new UIComponent();</pre><pre>// match new holders size to the original</pre><pre>ref.setActualSize(component.width,component.height);</pre><pre>// fill the new component with the image</pre><pre>ref.graphics.beginBitmapFill(bmpData);</pre><pre>ref.graphics.drawRect(0, 0, </pre><pre>	component.width, component.height);</pre><pre>ref.graphics.endFill();</pre><pre>// set the transparency</pre><pre>ref.alpha = trans;</pre><pre>// apply any filters</pre><pre>ref.filters = filterArray;</pre><pre>// add image to stage</pre><pre>addChild(ref);</pre></blockquote><pre>} </pre></blockquote></blockquote><blockquote><pre>}</pre></blockquote><pre>}</pre><p>This component can then be passed any other component to reflect, accepting filters (filterArray), alpha value (trans), and arguments to allow you to skew the reflection.&#160; In fact, using it can be as simple as this:</p><font size="2"><p align="left">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</p></font><pre>&lt;mx:Application xmlns:mx=<a href="http://www.adobe.com/2006/mxml">http://www.adobe.com/2006/mxml</a> </pre><blockquote><pre>xmlns:c=&quot;com.tappernimer.components.*&quot; </pre><pre>layout=&quot;absolute&quot;&gt;</pre></blockquote><blockquote><pre>&lt;mx:Image id=&quot;image&quot; source=&quot;images/tn_logo_full.jpg&quot;/&gt;</pre><pre>&lt;c:VerticalReflection id=&quot;ref&quot; </pre><blockquote><pre>component=&quot;{image}&quot; </pre><pre>x=&quot;{image.x}&quot; y=&quot;{image.height}&quot; </pre><pre>filterArray=&quot;{new Array(new BlurFilter())}&quot;/&gt;</pre></blockquote></blockquote><pre>&lt;/mx:Application&gt;</pre><pre>Here is the code running:<br /><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="225" height="225"><param name="movie" value="http://files.blog-city.com/files/J05/88593/b/reflectiontest.swf" /><param name="quality" value="high" /><param name="menu" value="false" /><param name="wmode" value="" /><embed src="http://files.blog-city.com/files/J05/88593/b/reflectiontest.swf" wmode="" quality="high" menu="false" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="225" height="225"></embed></object></pre><pre>&#160;</pre><pre>&#160;</pre>]]></content:encoded>
			<wfw:commentRss>http://www.digitalprimates.net/author/tapper/2007/09/21/reflecting-an-image-in-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing Flex Style Sheets at runtime</title>
		<link>http://www.digitalprimates.net/author/tapper/2007/08/13/changing-flex-style-sheets-at-runtime/</link>
		<comments>http://www.digitalprimates.net/author/tapper/2007/08/13/changing-flex-style-sheets-at-runtime/#comments</comments>
		<pubDate>Mon, 13 Aug 2007 11:08:00 +0000</pubDate>
		<dc:creator>tapper</dc:creator>
				<category><![CDATA[actionscript3]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[flash9]]></category>
		<category><![CDATA[flex2]]></category>
		<category><![CDATA[flex3]]></category>
		<category><![CDATA[runtime]]></category>

		<guid isPermaLink="false">http://test.digitalprimates.net/2007/08/13/changing-flex-style-sheets-at-runtime/</guid>
		<description><![CDATA[Sorry its been so long since the last blog entry, between the two kids, writing 3 books, and many clients, its been hard to find time to write new entries here.&#160; Today, I wanted to give a quick example of &#8230; <a href="http://www.digitalprimates.net/author/tapper/2007/08/13/changing-flex-style-sheets-at-runtime/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sorry its been so long since the last blog entry, between the two kids, writing 3 books, and many clients, its been hard to find time to write new entries here.&#160; Today, I wanted to give a quick example of the Flex 2.0.1 feature of loading CSS style sheets at runtime.</p><p>In most Flex applications, I had been creating a seperate CSS style sheet, and compiling it into the application through the use of the &lt;mx:Script source=&quot;&#8230;&quot; /&gt;.&#160; One of the pains of this, is that applying changes to the styles requires re-compiling the application, and as you probably now, the styles are one of the most frequently changed aspects of any application.</p><p>To help solve this problem, Adobe implemented the ability to load Style Sheets at run time in the Flex 2.0.1 release.&#160; To do this, you first need to compile the CSS into a swf.&#160; You can do this in FlexBuilder by right clicking on the css file and choosing &quot;Compile CSS to SWF&quot; option, or using the comand line compiler (mxmlc).&#160; Once the css is compiled into a swf, it can be loaded with the StyleManager.loadStyleDeclarations(&#8230;) method.&#160; Consider this simple example:</p><h2>TestLoadStyles.mxml&#160;</h2><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;mx:Application xmlns:mx=&quot;<a href="http://www.adobe.com/2006/mxml">http://www.adobe.com/2006/mxml</a>&quot; layout=&quot;vertical&quot;&gt;<br />&#160;&lt;mx:Style&gt;<br />&#160;&#160;.text1{<br />&#160;&#160;&#160;color:#0000ff;<br />&#160;&#160;}<br />&#160;&#160;.text2{<br />&#160;&#160;&#160;color:#ffff00;<br />&#160;&#160;}<br />&#160;&lt;/mx:Style&gt;<br />&#160;&lt;mx:Script&gt;<br />&#160;&#160;&lt;![CDATA[<br />&#160;&#160;&#160;private function changeCSS():void{<br />&#160;&#160;&#160;&#160;StyleManager.loadStyleDeclarations(&quot;myCSS.swf&quot;);<br />&#160;&#160;&#160;&#160;<br />&#160;&#160;&#160;}<br />&#160;&#160;&#160;private function undoStyle():void{<br />&#160;&#160;&#160;&#160;StyleManager.unloadStyleDeclarations(&quot;myCSS.swf&quot;);<br />&#160;&#160;&#160;}<br />&#160;&#160;]]&gt;<br />&#160;&lt;/mx:Script&gt;<br />&#160;&lt;mx:Button label=&quot;change css&quot; click=&quot;changeCSS()&quot;/&gt;<br />&#160;&lt;mx:Button label=&quot;revert css&quot; click=&quot;undoStyle()&quot;/&gt;<br />&#160;&lt;mx:Label text=&quot;hi there&quot;/&gt;<br />&#160;&lt;mx:Label text=&quot;hi there&quot; styleName=&quot;text1&quot;/&gt;<br />&#160;&lt;mx:Label text=&quot;hi there&quot; styleName=&quot;text2&quot;/&gt;<br />&lt;/mx:Application&gt;<br /><font size="5" color="#0000ff">&#160;</font></pre><h2>myCSS.css</h2><pre>Application{<br />&#160;color:#ff0000;<br />&#160;font-size:40;<br />}<br />.text1{<br />&#160;color:#00ff00;<br />}&#160;</pre><p>Compile the css into a swf, and make sure it is in the same directory as the TestLoadStyles.swf. As you run the application, you can see the changes as the style sheet is loaded or unloaded.&#160; One thing to notice, is that even when the styles are loaded, and styles initially defined, which are not overridden in the loaded style sheet still remain, therefore, the styles of .text2 (yellow text), remain yellow, even after the new style sheet is loaded, since the .text2 style does not appear in the load style sheet, while the style .text1 which is defined as red text in the initial application, is changed to green, as the same style name is defined in both, so when the new style sheet is loaded, the .text1 label changes its color from green to red, and when its unloaded, it reverts to green.</p><p>This offers great opportunities not only for greater separation of styles from the application, but also for the concepts of writing an application once and rebranding the same deployed application.</p>]]></content:encoded>
			<wfw:commentRss>http://www.digitalprimates.net/author/tapper/2007/08/13/changing-flex-style-sheets-at-runtime/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
