<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>SnippetRepoBrowser</title>
    <link>http://snippet.gnstudio.com/snippetrepobrowser/index</link>    
    <description>RSS Feed of SnippetRepoBrowser (Global RSS)</description>    
    <language>en-us</language>
    <pubDate>Thu, 09 Feb 2012 20:56:51 +0100</pubDate>
    <docs>SnippetRepoBrowser/index</docs>
    <generator>SnippetRepoBrowser Feed Generator</generator>
    <item>
      <title><![CDATA[Duplicate SWF or raster content of an Image component]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/94</link>
      <description><![CDATA[Using the BitmapData class is quite easy and fast copy or manipulate an external image loaded into a Flex application, it&#39;s quite interesting the difference between the data type of the content property of an Image component because it changes if a bitmap or a SWF has been loaded: <br /><ul><li>the first one is a Bitmap </li><li>the second on is a MovieClipLoaderAsset </li></ul><br /><br />In order to let you copy the content also with a SWF file loaded into the Image component you can use a Loader and the loadBytes() method.<br />]]><![CDATA[<div class="divcode"><pre lang="actionscript">&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&quot;" target="_blank"><a href="http://www.adobe.com/2006/mxml&quot;" target="_blank">http://www.adobe.com/2006/mxml&quot;</a></a><br />        layout=&quot;vertical&quot;<br />        verticalAlign=&quot;middle&quot;<br />        backgroundColor=&quot;white&quot;&gt;<br /> <br />    &lt;mx:Script&gt;<br />        &lt;![CDATA[<br />        	import mx.core.MovieClipLoaderAsset;<br />        	import mx.core.BitmapAsset;<br />            import mx.collections.ArrayCollection;<br />            <br />            [Embed(source=&quot;placeholder.swf&quot;)]<br />			private const ARTWORK_PLACE_HOLDER_SWF:Class;<br />			<br />			[Embed(source=&quot;placeholder.png&quot;)]<br />			private const ARTWORK_PLACE_HOLDER_PNG:Class;<br /> <br />            [Bindable]<br />            private var collection:ArrayCollection = new ArrayCollection();<br /> 			<br /> 			private function handleImage(e:Event):void{<br /> 				<br /> 				if(e.currentTarget.selectedValue == &quot;PNG&quot;){<br /> 					<br /> 					img.source = ARTWORK_PLACE_HOLDER_PNG;<br /> 					<br /> 				}else{<br /> 					<br /> 					img.source = ARTWORK_PLACE_HOLDER_SWF;<br /> 					<br /> 				}<br /> 				<br /> 			}<br /> 			<br />            private function dumpImage(source:Image):void {<br />            	<br />            	var asset:* = source.content;<br />            	var data:BitmapData;<br />            	var bitmap:Bitmap;<br />            	<br />            	try{<br />            		<br />            		data = Bitmap(source.content).bitmapData;<br />                	bitmap = new Bitmap(data);<br />                	<br />                	collection.addItem({image:bitmap, label:&quot;item #&quot; + (collection.length + 1)});<br />            		<br />            	}catch(error:Error){<br />            		<br />            		var loader:Loader = new Loader();<br />            		<br />            		loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onBitmapData); <br />            		           		<br />            		var swf:MovieClipLoaderAsset = asset as MovieClipLoaderAsset;            		<br />            		loader.loadBytes(swf.movieClipData);<br />            		<br />            	}<br />            	<br />            }<br />            <br />            private function onBitmapData(e:Event):void{<br />            			<br />            	e.target.removeEventListener(e.type, arguments.callee);<br />            			<br />            	var content: MovieClip = MovieClip((e.currentTarget as LoaderInfo).content)<br />            	var data:BitmapData = new BitmapData(content.width, content.height);<br />            	data.draw(content, null, null, null, null, true)<br />            	var bitmap:Bitmap = new Bitmap(data)<br />            			<br />            	collection.addItem({image:bitmap, label:&quot;item #&quot; + (collection.length + 1)});<br />            			<br />            }<br />            <br />        ]]&gt;<br />    &lt;/mx:Script&gt;<br /> <br />    &lt;mx:HBox&gt;<br />        &lt;mx:Panel title=&quot;Source image&quot;&gt;<br />            &lt;mx:HBox verticalAlign=&quot;middle&quot; horizontalAlign=&quot;center&quot; width=&quot;100%&quot; height=&quot;100%&quot;&gt;<br />                &lt;mx:Image id=&quot;img&quot; source=&quot;{ARTWORK_PLACE_HOLDER_SWF}&quot; /&gt;<br />            &lt;/mx:HBox&gt;<br />            <br />            &lt;mx:RadioButtonGroup id=&quot;imageSelector&quot; change=&quot;handleImage(event)&quot; /&gt;<br />            &lt;mx:RadioButton label=&quot;SWF&quot; selected=&quot;true&quot; group=&quot;{imageSelector}&quot; /&gt;<br />            &lt;mx:RadioButton label=&quot;PNG&quot; group=&quot;{imageSelector}&quot; /&gt;<br /> <br />            &lt;mx:ControlBar&gt;<br />                &lt;mx:Button label=&quot;Copy image&quot; click=&quot;dumpImage(img)&quot; /&gt;<br />            &lt;/mx:ControlBar&gt;<br />        &lt;/mx:Panel&gt;<br /> <br />        &lt;mx:TileList id=&quot;tileList&quot; dataProvider=&quot;{collection}&quot; width=&quot;450&quot; height=&quot;500&quot; columnCount=&quot;4&quot; verticalScrollPolicy=&quot;on&quot;&gt;<br />            &lt;mx:itemRenderer&gt;<br />                &lt;mx:Component&gt;<br />                    &lt;mx:VBox&gt;<br />                        &lt;mx:Image source=&quot;{data.image}&quot; /&gt;<br />                        &lt;mx:Label text=&quot;{data.label}&quot; /&gt;<br />                    &lt;/mx:VBox&gt;<br />                &lt;/mx:Component&gt;<br />            &lt;/mx:itemRenderer&gt;<br />        &lt;/mx:TileList&gt;<br />    &lt;/mx:HBox&gt;<br /> <br />&lt;/mx:Application&gt;</pre></div><br /><br />]]></description>
      <author>giorgionatili</author>
      <pubDate>Mon, 04 Oct 2010 06:02:28 +0200</pubDate>
      <category>Flex 4.x</category>
      <guid>http://snippet.gnstudio.com/viewtopic/94</guid>
   </item><item>
      <title><![CDATA[Center image content]]></title>
      <link>http://snippet.gnstudio.com/viewtopic/20</link>
      <description><![CDATA[If you get a bitmap data as source of an image component and you want to center it you have to create a new bitmap, create a new matrix, apply a transformation (in the snippet the translation is done accordingly to the component with) and then use again the BitmapData class to draw the new data accordingly to the transoformation<br />]]><![CDATA[<div class="divcode"><pre lang="actionscript">var imageData:BitmapData = BitmapData(someRawBitmapData);<br />					<br />var bmp:Bitmap =  new Bitmap(imageData);<br />					<br />var matrix:Matrix = new Matrix();<br />matrix.translate(-((imageData.width - this.width) / 2), -((imageData.height - this.height) / 2));<br /><br />var matriximage:BitmapData = new BitmapData(bmp.height, bmp.width, false, 0x00000000);<br />matriximage.draw(bmp, matrix);<br />					<br />// Suppose imgThumbnail	is the ID of your component			<br />imgThumbnail.source = new Bitmap(matriximage);<br />					</pre></div><br /><br />]]></description>
      <author>Giorgio Natili</author>
      <pubDate>Tue, 29 Sep 2009 11:27:25 +0200</pubDate>
      <category>Flex 3.x</category>
      <guid>http://snippet.gnstudio.com/viewtopic/20</guid>
   </item>
  </channel>
</rss>
