<?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>Flexmaniak.pl</title>
	<atom:link href="http://blog.flexmaniak.pl/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.flexmaniak.pl</link>
	<description>Flex, Papervision3D, PHP, Symfony</description>
	<lastBuildDate>Sun, 02 Oct 2011 08:36:28 +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>[Modules] Check if class implements interface</title>
		<link>http://blog.flexmaniak.pl/actionscript/modules-check-if-class-implements-interface</link>
		<comments>http://blog.flexmaniak.pl/actionscript/modules-check-if-class-implements-interface#comments</comments>
		<pubDate>Sun, 02 Oct 2011 07:36:49 +0000</pubDate>
		<dc:creator>damian</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://blog.flexmaniak.pl/?p=1485</guid>
		<description><![CDATA[Problem: I have module that implements my interface: class MyModule extends ModuleBase implmenets IMyInterface &#123; ... &#125; After loading module from external file: var moduleInfo:IModuleInfo = ModuleManager.getModule&#40;'module_path.swf'&#41;; moduleInfo.addEventListener&#40;ModuleEvent.READY, this_READY &#41;; moduleInfo.load&#40;null,null,null ,FlexGlobals.topLevelApplication.moduleFactory&#41;; And creating module object: private function this_READY&#40; moduleEvent:ModuleEvent &#41;:void &#123; var moduleInfo:IModuleInfo = moduleEvent.module; var m:Object = moduleInfo.factory.create&#40;&#41;; &#125; The expression: m is IMyInterface; returns [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>I have module that implements my interface:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">class</span> MyModule <span style="color: #0066CC;">extends</span> ModuleBase implmenets IMyInterface<br />
<span style="color: #66cc66;">&#123;</span><br />
...<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>After loading module from external file:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> moduleInfo:IModuleInfo = ModuleManager.<span style="color: #006600;">getModule</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'module_path.swf'</span><span style="color: #66cc66;">&#41;</span>;<br />
moduleInfo.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>ModuleEvent.<span style="color: #006600;">READY</span>, this_READY <span style="color: #66cc66;">&#41;</span>;<br />
moduleInfo.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">null</span>,<span style="color: #000000; font-weight: bold;">null</span>,<span style="color: #000000; font-weight: bold;">null</span> ,FlexGlobals.<span style="color: #006600;">topLevelApplication</span>.<span style="color: #006600;">moduleFactory</span><span style="color: #66cc66;">&#41;</span>;</div></div>
<p>And creating module object:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> this_READY<span style="color: #66cc66;">&#40;</span> moduleEvent:ModuleEvent <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">var</span> moduleInfo:IModuleInfo = moduleEvent.<span style="color: #006600;">module</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> m:<span style="color: #0066CC;">Object</span> = moduleInfo.<span style="color: #006600;">factory</span>.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>The expression:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">m is IMyInterface;</div></div>
<p>returns <strong>false</strong> instead of <strong>true</strong>.</p>
<p>&nbsp;</p>
<p><strong>Solution:</strong></p>
<p>The solution for this problem is following:</p>
<p>After creating the module object using factory, we must use the expression presented above. I do not know why, but after the first use of this expression or casting (operator <em>as</em>) it behaves right.</p>
<p>Therefore we must add the following line:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> this_READY<span style="color: #66cc66;">&#40;</span> moduleEvent:ModuleEvent <span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">var</span> moduleInfo:IModuleInfo = moduleEvent.<span style="color: #006600;">module</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> m:<span style="color: #0066CC;">Object</span> = moduleInfo.<span style="color: #006600;">factory</span>.<span style="color: #006600;">create</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
m is IMyInterface;<br />
<span style="color: #66cc66;">&#125;</span></div></div>
<p>It looks like error in Flex for me, as I cannot find an explanation for it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexmaniak.pl/actionscript/modules-check-if-class-implements-interface/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Two way data binding</title>
		<link>http://blog.flexmaniak.pl/flex/two-way-data-binding</link>
		<comments>http://blog.flexmaniak.pl/flex/two-way-data-binding#comments</comments>
		<pubDate>Fri, 23 Sep 2011 12:48:04 +0000</pubDate>
		<dc:creator>Piotr Wierzgała</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[data binding]]></category>

		<guid isPermaLink="false">http://blog.flexmaniak.pl/?p=1476</guid>
		<description><![CDATA[If you bind a variable to some component&#8217;s property by just adding [Bindable] metatag above it you may notice that component&#8217;s property changes when variable changes but it doesn&#8217;t work in the opposite direction. So what to do in order to achieve to way data binding? In MXML you have to add twoWay=&#8221;true&#8221; attribute to [...]]]></description>
			<content:encoded><![CDATA[<p>If you bind a variable to some component&#8217;s property by just adding [Bindable] metatag above it you may notice that component&#8217;s property changes when variable changes but it doesn&#8217;t work in the opposite direction. So what to do in order to achieve to way data binding?<span id="more-1476"></span></p>
<p>In MXML you have to add <strong>twoWay=&#8221;true&#8221;</strong> attribute to your Binding tag.</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&lt;</span>fx:Binding source=<span style="color: #ff0000;">&quot;slider_1.value&quot;</span> destination=<span style="color: #ff0000;">&quot;slider_2.value&quot;</span> twoWay=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
<br />
<span style="color: #66cc66;">&lt;</span>s:HSlider id=<span style="color: #ff0000;">&quot;slider_1&quot;</span><span style="color: #66cc66;">/&gt;</span><br />
<span style="color: #66cc66;">&lt;</span>s:HSlider id=<span style="color: #ff0000;">&quot;slider_2&quot;</span><span style="color: #66cc66;">/&gt;</span></div></div>
<p>In ActionScript you have to add <strong>@</strong> before binded variable in component&#8217;s property.</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #66cc66;">&#91;</span>Bindable<span style="color: #66cc66;">&#93;</span><br />
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> value:<span style="color: #0066CC;">Number</span>;<br />
<br />
<span style="color: #66cc66;">&lt;</span>s:HSlider value=<span style="color: #ff0000;">&quot;@{value}&quot;</span><span style="color: #66cc66;">/&gt;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexmaniak.pl/flex/two-way-data-binding/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>png2swf: a way to keep transparency and small PNG file size</title>
		<link>http://blog.flexmaniak.pl/flex/png2swf-a-way-to-keep-transparency-and-small-png-file-size</link>
		<comments>http://blog.flexmaniak.pl/flex/png2swf-a-way-to-keep-transparency-and-small-png-file-size#comments</comments>
		<pubDate>Sun, 07 Aug 2011 19:06:59 +0000</pubDate>
		<dc:creator>Piotr Wierzgała</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[PNG]]></category>
		<category><![CDATA[SWF]]></category>
		<category><![CDATA[SWFTools]]></category>
		<category><![CDATA[transparency]]></category>

		<guid isPermaLink="false">http://blog.flexmaniak.pl/?p=1451</guid>
		<description><![CDATA[png2swf utility is a part of SWFTools package. It is capable of converting PNG to SWF format and it can really save your life if you are in need of having small PNG files. PNG supports transparency and it has good compression for images consisting of solid blocks of colors but if it comes to [...]]]></description>
			<content:encoded><![CDATA[<p>png2swf utility is a part of <a href="http://www.swftools.org/download.html">SWFTools</a> package. It is capable of converting PNG to SWF format and it can really save your life if you are in need of having small PNG files.<span id="more-1451"></span></p>
<p>PNG supports transparency and it has good compression for images consisting of solid blocks of colors but if it comes to photo-like quality PNG is really terrible. With png2swf you can combine transparency of PNG and small size of JPEG format. In order to compress your PNG image (with preservation of transparent pixels) you need to specify -j flag with it&#8217;s quality level (1-100).</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">png2swf -j 70 -o output_file.swf input_file.png</div></div>
<p>Here are several examples of my results (quality 70):</p>
<ol>
<li>315KB (PNG) -> 58KB (SWF) output is 18% of input</li>
<li>294KB (PNG) -> 60KB (SWF) output is 20% of input</li>
<li>101KB (PNG) -> 29KB (SWF) output is 28% of input</li>
<li>193KB (PNG) -> 45KB (SWF) output is 23% of input</li>
<li>203KB (PNG) -> 72KB (SWF) output is 35% of input</li>
</ol>
<p>If you are going to use this solution you may be also interested in the follwing two posts:</p>
<ul>
<li><a href="http://blog.flexmaniak.pl/actionscript/bytearray-to-bitmapdata-loading-image-in-swf-format">ByteArray to BitmapData. Loading image in SWF format</a>.</li>
<li><a href="http://blog.flexmaniak.pl/actionscript/bitmapdata-and-transparency">BitmapData and transparency</a>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexmaniak.pl/flex/png2swf-a-way-to-keep-transparency-and-small-png-file-size/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>BitmapData and transparency</title>
		<link>http://blog.flexmaniak.pl/actionscript/bitmapdata-and-transparency</link>
		<comments>http://blog.flexmaniak.pl/actionscript/bitmapdata-and-transparency#comments</comments>
		<pubDate>Thu, 04 Aug 2011 21:06:09 +0000</pubDate>
		<dc:creator>Piotr Wierzgała</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[transparency]]></category>

		<guid isPermaLink="false">http://blog.flexmaniak.pl/?p=1446</guid>
		<description><![CDATA[If you used draw method from BitmapData class to copy some DisplayObject with transparency you may notice that all transparent pixels turned white. This is because you didn&#8217;t set properly parameters in BitmapData construcotr. BitmapData&#40;width:int, height:int, transparent:Boolean=true, fillColor:uint=0xffffffff&#41; By default BitmapData fills it&#8217;s background with white and to avoid this you have to set fillColor [...]]]></description>
			<content:encoded><![CDATA[<p>If you used draw method from BitmapData class to copy some DisplayObject with transparency you may notice that all transparent pixels turned white. This is because you didn&#8217;t set properly parameters in BitmapData construcotr.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span style="color: #004993;">BitmapData</span></a><span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">transparent</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a>=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> fillColor<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=uint%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:uint.html"><span style="color: #004993;">uint</span></a>=0xffffffff<span style="color: #000000;">&#41;</span></div></div>
<p>By default BitmapData fills it&#8217;s background with white and to avoid this you have to set fillColor parameter to any transparent color.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span style="color: #004993;">BitmapData</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span style="color: #004993;">BitmapData</span></a><span style="color: #000000;">&#40;</span>someWidth<span style="color: #000066; font-weight: bold;">,</span> someHeight<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> 0x00ffffff<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span>someDisplayObject<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexmaniak.pl/actionscript/bitmapdata-and-transparency/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ByteArray to BitmapData. Loading image in SWF format.</title>
		<link>http://blog.flexmaniak.pl/actionscript/bytearray-to-bitmapdata-loading-image-in-swf-format</link>
		<comments>http://blog.flexmaniak.pl/actionscript/bytearray-to-bitmapdata-loading-image-in-swf-format#comments</comments>
		<pubDate>Thu, 04 Aug 2011 20:32:19 +0000</pubDate>
		<dc:creator>Piotr Wierzgała</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[ByteArray]]></category>
		<category><![CDATA[SWF]]></category>

		<guid isPermaLink="false">http://blog.flexmaniak.pl/?p=1443</guid>
		<description><![CDATA[If you load an image saved in SWF format and you would like to have it as BitmapData then the following three functions will solve the problem. private function loadSWF&#40;url:String&#41;:void &#123; &#160; &#160; &#160; &#160; &#160; var swfLoader:SWFLoader = new SWFLoader; &#160; &#160; swfLoader.load&#40;url&#41;; &#160; &#160; swfLoader.addEventListener&#40;Event.COMPLETE, swfLoader_COMPLETE&#41;; &#125; private function swfLoader_COMPLETE&#40;event:Event&#41;:void &#123; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>If you load an image saved in SWF format and you would like to have it as BitmapData then the following three functions will solve the problem.<span id="more-1443"></span></p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> loadSWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">url</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <br />
<span style="color: #000000;">&#123;</span> &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> swfLoader<span style="color: #000066; font-weight: bold;">:</span>SWFLoader = <span style="color: #0033ff; font-weight: bold;">new</span> SWFLoader<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; swfLoader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">url</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <br />
&nbsp; &nbsp; swfLoader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> swfLoader_COMPLETE<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> swfLoader_COMPLETE<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> bytesLoader<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; bytesLoader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">loadBytes</span><span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">content</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">loaderInfo</span><span style="color: #000066; font-weight: bold;">.</span>bytes<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; bytesLoader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentLoaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> bytesLoader_COMPLETE<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> bytesLoader_COMPLETE<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">content</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=displayobject%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:displayobject.html"><span style="color: #004993;">DisplayObject</span></a> = event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">content</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span style="color: #004993;">BitmapData</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span style="color: #004993;">BitmapData</span></a><span style="color: #000000;">&#40;</span><span style="color: #004993;">content</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">content</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">,</span> 0x00ffffff<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">content</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #000000;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexmaniak.pl/actionscript/bytearray-to-bitmapdata-loading-image-in-swf-format/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ByteArray to BitmapData. Loading image with FileReference.</title>
		<link>http://blog.flexmaniak.pl/actionscript/conversion-from-bytearray-to-bitmapdata-loading-image-with-filereference</link>
		<comments>http://blog.flexmaniak.pl/actionscript/conversion-from-bytearray-to-bitmapdata-loading-image-with-filereference#comments</comments>
		<pubDate>Wed, 03 Aug 2011 17:02:31 +0000</pubDate>
		<dc:creator>Piotr Wierzgała</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[ByteArray]]></category>

		<guid isPermaLink="false">http://blog.flexmaniak.pl/?p=1439</guid>
		<description><![CDATA[If you load a graphic file with the FileReference class you will get it as a ByteArray and you will probably like to convert it to BitmapData. Let&#8217;s assume that you have successfully browsed, selected and loaded the image. After that you have to use Loader object to load ByteArray available in fileReference.data field. Finally, [...]]]></description>
			<content:encoded><![CDATA[<p>If you load a graphic file with the FileReference class you will get it as a ByteArray and you will probably like to convert it to BitmapData.<span id="more-1439"></span></p>
<p>Let&#8217;s assume that you have successfully browsed, selected and loaded the image. After that you have to use Loader object to load ByteArray available in fileReference.data field. Finally, in Loader COMPLETE event you will have Bitmap object in content property of the target.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> fileReference_COMPLETE<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentLoaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> loader_COMPLETE<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">loadBytes</span><span style="color: #000000;">&#40;</span>fileReference<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> loader_COMPLETE<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> bitmap<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bitmap%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmap.html"><span style="color: #004993;">Bitmap</span></a> = event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">content</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span style="color: #004993;">BitmapData</span></a> = bitmap<span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span style="color: #004993;">BitmapData</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexmaniak.pl/actionscript/conversion-from-bytearray-to-bitmapdata-loading-image-with-filereference/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>FlexPrintJob, TypeError: Error #1009: Cannot access a property or method of a null object reference.</title>
		<link>http://blog.flexmaniak.pl/wrrors-and-warnings/flex-errors/flexprintjob-typeerror-error-1009-cannot-access-a-property-or-method-of-a-null-object-reference</link>
		<comments>http://blog.flexmaniak.pl/wrrors-and-warnings/flex-errors/flexprintjob-typeerror-error-1009-cannot-access-a-property-or-method-of-a-null-object-reference#comments</comments>
		<pubDate>Wed, 03 Aug 2011 12:07:33 +0000</pubDate>
		<dc:creator>Piotr Wierzgała</dc:creator>
				<category><![CDATA[Flex Errors]]></category>
		<category><![CDATA[FlexPrintJob]]></category>

		<guid isPermaLink="false">http://blog.flexmaniak.pl/?p=1434</guid>
		<description><![CDATA[Full error text: TypeError: Error #1009: Cannot access a property or method of a null object reference. &#160; &#160; at mx.printing::FlexPrintJob/addObject()[E:\dev\hero_private\frameworks\projects\framework\src\mx\printing\FlexPrintJob.as:252] What caused the warning? I was trying to print dynamically created image. The error occured in function addObject from FlexPrintJob class. What is the solution? You have to add printed object to a stage [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Full error text:</strong></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">TypeError: Error #1009: Cannot access a property or method of a null object reference.<br />
&nbsp; &nbsp; at mx.printing::FlexPrintJob/addObject()[E:\dev\hero_private\frameworks\projects\framework\src\mx\printing\FlexPrintJob.as:252]</div></div>
<p><strong>What caused the warning?</strong><br />
I was trying to print dynamically created image. The error occured in function addObject from FlexPrintJob class.</p>
<p><strong>What is the solution?</strong><br />
You have to add printed object to a stage before you add it to FlexPrintJob.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6699cc; font-weight: bold;">var</span> flexPrintJob<span style="color: #000066; font-weight: bold;">:</span>FlexPrintJob = <span style="color: #0033ff; font-weight: bold;">new</span> FlexPrintJob<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
addElement<span style="color: #000000;">&#40;</span>image<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <br />
<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>flexPrintJob<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; removeElement<span style="color: #000000;">&#40;</span>image<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span> &nbsp; &nbsp; <br />
<span style="color: #000000;">&#125;</span><br />
flexPrintJob<span style="color: #000066; font-weight: bold;">.</span>addObject<span style="color: #000000;">&#40;</span>image<span style="color: #000066; font-weight: bold;">,</span> FlexPrintJobScaleType<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SHOW_ALL</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
flexPrintJob<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">send</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <br />
removeElement<span style="color: #000000;">&#40;</span>image<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>Note that the printed object will not be visible on a stage even for a second because it&#8217;s immediately removed from the stage after sending to FlexPrintJob.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexmaniak.pl/wrrors-and-warnings/flex-errors/flexprintjob-typeerror-error-1009-cannot-access-a-property-or-method-of-a-null-object-reference/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Nested inner functions as event listeners</title>
		<link>http://blog.flexmaniak.pl/actionscript/nested-inner-functions-as-event-listeners</link>
		<comments>http://blog.flexmaniak.pl/actionscript/nested-inner-functions-as-event-listeners#comments</comments>
		<pubDate>Wed, 03 Aug 2011 11:47:47 +0000</pubDate>
		<dc:creator>Piotr Wierzgała</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[event listerner]]></category>

		<guid isPermaLink="false">http://blog.flexmaniak.pl/?p=1423</guid>
		<description><![CDATA[Sometimes it happens that you need to pass some paremeters to you event listener function but because it can&#8217;t be done you declare additional class fields specially for this purpose. Let&#8217;s consider the following sitiation: We have a function that takes three parameters: url to some image, x coordinate and y coordinate at which the [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes it happens that you need to pass some paremeters to you event listener function but because it can&#8217;t be done you declare additional class fields specially for this purpose. Let&#8217;s consider the following sitiation:<span id="more-1423"></span></p>
<p>We have a function that takes three parameters: url to some image, x coordinate and y coordinate at which the image should be drawn. Before the image will be drawn it should be loaded and here&#8217;s the moment where our parameters stuck. We have to assign them to class fields in order to use them in loader COMPLETE event listener.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> imageX<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> imageY<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> addImage<span style="color: #000000;">&#40;</span><span style="color: #004993;">url</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">,</span> imageX<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000066; font-weight: bold;">,</span> imageY<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>imageX = imageX<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>imageY = imageY<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a><span style="color: #000000;">&#40;</span><span style="color: #004993;">url</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentLoaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> loader_COMPLETE<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> loader_COMPLETE<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span style="color: #004993;">BitmapData</span></a> = event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">content</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">beginBitmapFill</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">bitmapData</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span>imageX<span style="color: #000066; font-weight: bold;">,</span> imageY<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>To avoid such inconvenient situation we can use nested inner function as event listener (closure). Here&#8217;s how it looks:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> addImage<span style="color: #000000;">&#40;</span><span style="color: #004993;">url</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">,</span> imageX<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000066; font-weight: bold;">,</span> imageY<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <br />
<br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=loader%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:loader.html"><span style="color: #004993;">Loader</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=urlrequest%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:urlrequest.html"><span style="color: #004993;">URLRequest</span></a><span style="color: #000000;">&#40;</span><span style="color: #004993;">url</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">contentLoaderInfo</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span style="color: #004993;">BitmapData</span></a> = event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">content</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">beginBitmapFill</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">bitmapData</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span>imageX<span style="color: #000066; font-weight: bold;">,</span> imageY<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Using this solution: </p>
<ul>
<li>You have access to local variables in the scope outer function.</li>
<li>You keep all the logic in one place.</li>
<li>You don&#8217;t end up with lots of functions.</li>
</ul>
<p>But:</p>
<ul>
<li>You do not have access to inner function from any other place in you code.</li>
<li>Functions with inner functions are usually not as readable as their casual equvalents.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexmaniak.pl/actionscript/nested-inner-functions-as-event-listeners/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get RGB color values from BitmapData?</title>
		<link>http://blog.flexmaniak.pl/actionscript/how-to-get-rgb-color-values-from-bitmapdata</link>
		<comments>http://blog.flexmaniak.pl/actionscript/how-to-get-rgb-color-values-from-bitmapdata#comments</comments>
		<pubDate>Sat, 30 Jul 2011 08:51:03 +0000</pubDate>
		<dc:creator>Piotr Wierzgała</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[RGB]]></category>

		<guid isPermaLink="false">http://blog.flexmaniak.pl/?p=1419</guid>
		<description><![CDATA[BitmapData object has two methods: getPixel() and getPixel32 which return hexadecimal color value without and with alpha channel respectively. You can easily extract RGB values from hexadecimal notation using the code below: var pixel:uint = bitmapData.getPixel32&#40;x, y&#41;; var alpha:uint = pixel &#62;&#62; 24 &#38; 0xff; var red:uint = pixel &#62;&#62; 16 &#38; 0xff; var green:uint [...]]]></description>
			<content:encoded><![CDATA[<p>BitmapData object has two methods: getPixel() and getPixel32 which return hexadecimal color value without and with alpha channel respectively. You can easily extract RGB values from hexadecimal notation using the code below:</p>
<div class="codecolorer-container actionscript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">var</span> pixel:uint = bitmapData.<span style="color: #006600;">getPixel32</span><span style="color: #66cc66;">&#40;</span>x, y<span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #000000; font-weight: bold;">var</span> alpha:uint = pixel <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #cc66cc;">24</span> <span style="color: #66cc66;">&amp;</span> 0xff;<br />
<span style="color: #000000; font-weight: bold;">var</span> red:uint = pixel <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #cc66cc;">16</span> <span style="color: #66cc66;">&amp;</span> 0xff;<br />
<span style="color: #000000; font-weight: bold;">var</span> green:uint = pixel <span style="color: #66cc66;">&gt;&gt;</span> <span style="color: #cc66cc;">8</span> <span style="color: #66cc66;">&amp;</span> 0xff;<br />
<span style="color: #000000; font-weight: bold;">var</span> blue:uint = pixel <span style="color: #66cc66;">&amp;</span> 0xff;</div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexmaniak.pl/actionscript/how-to-get-rgb-color-values-from-bitmapdata/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to disable mouse events on transparent parts of PNG image?</title>
		<link>http://blog.flexmaniak.pl/actionscript/how-to-disable-mouse-events-on-transparent-parts-of-png-image</link>
		<comments>http://blog.flexmaniak.pl/actionscript/how-to-disable-mouse-events-on-transparent-parts-of-png-image#comments</comments>
		<pubDate>Fri, 29 Jul 2011 22:43:08 +0000</pubDate>
		<dc:creator>Piotr Wierzgała</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[mask]]></category>
		<category><![CDATA[transparent]]></category>

		<guid isPermaLink="false">http://blog.flexmaniak.pl/?p=1412</guid>
		<description><![CDATA[Transparent area in vector graphics doesn&#8217;t generate any mouse events simply because it holds no data. In case of raster graphics every transparent area is a solid block of pixels with aplha channel equal zero. All transparent pixels in a PNG file behave like non-tranparent ones what sometimes can be treated as unwanted feature. There [...]]]></description>
			<content:encoded><![CDATA[<p>Transparent area in vector graphics doesn&#8217;t generate any mouse events simply because it holds no data. In case of raster graphics every transparent area is a solid block of pixels with aplha channel equal zero. All transparent pixels in a PNG file behave like non-tranparent ones what sometimes can be treated as unwanted feature.<span id="more-1412"></span></p>
<p>There are at least two solutions to that problem: the first uses masks and the second checks alpha channel value of a selected pixel. </p>
<h3>First solution</h3>
<p>In first solution you have to add a mask to your PNG layer (Sprite, UIComponent) which will cover every non-transparent pixel of a PNG image. Here is a helper function which you can use to create such mask:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createMask<span style="color: #000000;">&#40;</span><span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span style="color: #004993;">BitmapData</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=sprite%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sprite.html"><span style="color: #004993;">Sprite</span></a><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">mask</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=sprite%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sprite.html"><span style="color: #004993;">Sprite</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=sprite%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sprite.html"><span style="color: #004993;">Sprite</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">mask</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #004993;">mask</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span>0xff0000<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=uint%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:uint.html"><span style="color: #004993;">uint</span></a>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> y<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=uint%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:uint.html"><span style="color: #004993;">uint</span></a>=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> x<span style="color: #000066; font-weight: bold;">&lt;</span><span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">bitmapData</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getPixel32</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">y</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> 0x000000ff<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">mask</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #004993;">mask</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">graphics</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">mask</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Pixels covered with mask will respond to mouse events and the others not.</p>
<h3>Second solution</h3>
<p>Let&#8217;s say you want to move PNG layer with mouse only if your cursor is over non-transparent pixel. In such case you can check alpha channel value of selected pixel and if it is different than zero (non-transparent) perform move action. This approach is much more efficient than the previous one. Here is a helper function which returns TRUE if specified pixel is transparent.</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> isClickedPixelTransparent<span style="color: #000000;">&#40;</span>pixelX<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000066; font-weight: bold;">,</span> pixelY<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a><span style="color: #000066; font-weight: bold;">,</span> bd<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bitmapdata%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bitmapdata.html"><span style="color: #004993;">BitmapData</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=boolean%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:boolean.html"><span style="color: #004993;">Boolean</span></a><br />
<span style="color: #000000;">&#123;</span> &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000;">&#40;</span>bd<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">getPixel32</span><span style="color: #000000;">&#40;</span>pixelX<span style="color: #000066; font-weight: bold;">,</span> pixelY<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> 0x000000ff<span style="color: #000000;">&#41;</span> == <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.flexmaniak.pl/actionscript/how-to-disable-mouse-events-on-transparent-parts-of-png-image/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

