<?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>Flex Examples &#187; ByteArray</title>
	<atom:link href="http://blog.flexexamples.com/category/bytearray/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flexexamples.com</link>
	<description>Just a bunch of Adobe Flex Examples</description>
	<lastBuildDate>Wed, 26 Jan 2011 18:09:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Taking screenshots in Flex 3 using the ImageSnapshot.captureImage() method</title>
		<link>http://blog.flexexamples.com/2007/11/16/taking-screenshots-in-flex-using-the-imagesnapshotcaptureimage-method/</link>
		<comments>http://blog.flexexamples.com/2007/11/16/taking-screenshots-in-flex-using-the-imagesnapshotcaptureimage-method/#comments</comments>
		<pubDate>Sat, 17 Nov 2007 06:54:47 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ByteArray]]></category>
		<category><![CDATA[ImageSnapshot]]></category>
		<category><![CDATA[captureImage()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/11/16/taking-screenshots-in-flex-using-the-imagesnapshotcaptureimage-method/</guid>
		<description><![CDATA[<p>The following example shows how you can use the static captureImage() method in the mx.graphics.ImageSnapshot class to take a screenshot of an item on the display list, convert it into a ByteArray, and display the ByteArray using a SWFLoader control.</p> <p>Full code after the jump.</p> <p></p> <p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ImageSnapshot_captureImage_test/main.mxml">View MXML</a></p> &#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62; &#60;!-- http://blog.flexexamples.com/2007/11/16/taking-screenshots-in-flex-using-the-imagesnapshotcaptureimage-method/ [...]]]></description>
			<content:encoded><![CDATA[<p>The following example shows how you can use the static <code>captureImage()</code> method in the mx.graphics.ImageSnapshot class to take a screenshot of an item on the display list, convert it into a ByteArray, and display the ByteArray using a SWFLoader control.</p>
<p>Full code after the jump.</p>
<p><span id="more-307"></span></p>
<p class="download"><a href="http://blog.flexexamples.com/wp-content/uploads/ImageSnapshot_captureImage_test/main.mxml">View MXML</a></p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- http://blog.flexexamples.com/2007/11/16/taking-screenshots-in-flex-using-the-imagesnapshotcaptureimage-method/ --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span></span>
<span style="color: #000000;">        layout=<span style="color: #ff0000;">&quot;vertical&quot;</span></span>
<span style="color: #000000;">        verticalAlign=<span style="color: #ff0000;">&quot;middle&quot;</span></span>
<span style="color: #000000;">        backgroundColor=<span style="color: #ff0000;">&quot;white&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">        &lt;![CDATA[</span>
<span style="color: #339933;">            import mx.core.IUIComponent;</span>
<span style="color: #339933;">            import mx.graphics.ImageSnapshot;</span>
&nbsp;
<span style="color: #339933;">            private function takeSnapshot(source:IBitmapDrawable):void {</span>
<span style="color: #339933;">                var imageSnap:ImageSnapshot = ImageSnapshot.captureImage(source);</span>
<span style="color: #339933;">                var imageByteArray:ByteArray = imageSnap.data as ByteArray;</span>
<span style="color: #339933;">                swfLoader.load(imageByteArray);</span>
<span style="color: #339933;">            }</span>
<span style="color: #339933;">        ]]&gt;</span>
<span style="color: #339933;">    &lt;/mx:Script&gt;</span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Array</span> id=<span style="color: #ff0000;">&quot;arr&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> col1=<span style="color: #ff0000;">&quot;Row 1, Col 1&quot;</span> col2=<span style="color: #ff0000;">&quot;Row 1, Col 2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> col1=<span style="color: #ff0000;">&quot;Row 2, Col 1&quot;</span> col2=<span style="color: #ff0000;">&quot;Row 2, Col 2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> col1=<span style="color: #ff0000;">&quot;Row 3, Col 1&quot;</span> col2=<span style="color: #ff0000;">&quot;Row 3, Col 2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> col1=<span style="color: #ff0000;">&quot;Row 4, Col 1&quot;</span> col2=<span style="color: #ff0000;">&quot;Row 4, Col 2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> col1=<span style="color: #ff0000;">&quot;Row 5, Col 1&quot;</span> col2=<span style="color: #ff0000;">&quot;Row 5, Col 2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Object</span> col1=<span style="color: #ff0000;">&quot;Row 6, Col 1&quot;</span> col2=<span style="color: #ff0000;">&quot;Row 6, Col 2&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Array</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:ApplicationControlBar</span> dock=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;Take snapshot of DataGrid&quot;</span></span>
<span style="color: #000000;">                click=<span style="color: #ff0000;">&quot;takeSnapshot(dataGrid);&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:ApplicationControlBar</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HBox</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGrid</span> id=<span style="color: #ff0000;">&quot;dataGrid&quot;</span> dataProvider=<span style="color: #ff0000;">&quot;{arr}&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:SWFLoader</span> id=<span style="color: #ff0000;">&quot;swfLoader&quot;</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:filters</span><span style="color: #7400FF;">&gt;</span></span>
                <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DropShadowFilter</span> <span style="color: #7400FF;">/&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:filters</span><span style="color: #7400FF;">&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:SWFLoader</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:HBox</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p class="information"><a href="http://blog.flexexamples.com/wp-content/uploads/ImageSnapshot_captureImage_test/bin/srcview/index.html">View source</a> is enabled in the following example.</p>
<p><iframe src="http://blog.flexexamples.com/wp-content/uploads/ImageSnapshot_captureImage_test/bin/main.html" width="100%" height="300"></iframe></p>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Taking screenshots in Flex 3 using the ImageSnapshot.captureImage() method on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/11/16/taking-screenshots-in-flex-using-the-imagesnapshotcaptureimage-method/',contentID: 'post-307',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'captureImage()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/11/16/taking-screenshots-in-flex-using-the-imagesnapshotcaptureimage-method/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
		<item>
		<title>Displaying sound data using the SoundMixer.computeSpectrum() method</title>
		<link>http://blog.flexexamples.com/2007/08/16/displaying-sound-data-using-the-soundmixercomputespectrum-method/</link>
		<comments>http://blog.flexexamples.com/2007/08/16/displaying-sound-data-using-the-soundmixercomputespectrum-method/#comments</comments>
		<pubDate>Fri, 17 Aug 2007 05:44:00 +0000</pubDate>
		<dc:creator>Peter deHaan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[ByteArray]]></category>
		<category><![CDATA[SoundMixer]]></category>
		<category><![CDATA[computeSpectrum()]]></category>

		<guid isPermaLink="false">http://blog.flexexamples.com/2007/08/16/displaying-sound-data-using-the-soundmixercomputespectrum-method/</guid>
		<description><![CDATA[<p>The following example looks at making a simple spectrum analyzer app using the drawing API and the SoundMixer.computeSpectrum() method. This is basically a revised version of the example I did on my other blog last year, the poorly named <a href="http://blogs.adobe.com/pdehaan/2006/06/soundmixercomputespectrum.html">&#8220;SoundMixer.computeSpectrum()&#8221;</a> entry.</p> <p>I&#8217;ve updated the code somewhat to make it a bit prettier. You can [...]]]></description>
			<content:encoded><![CDATA[<p>The following example looks at making a simple spectrum analyzer app using the drawing API and the <code>SoundMixer.computeSpectrum()</code> method. This is basically a revised version of the example I did on my other blog last year, the poorly named <a href="http://blogs.adobe.com/pdehaan/2006/06/soundmixercomputespectrum.html">&#8220;SoundMixer.computeSpectrum()&#8221;</a> entry.</p>
<p>I&#8217;ve updated the code somewhat to make it a bit prettier. You can find more information on the SoundMixer class and the <code>computeSpectrum()</code> method in the Adobe Flash CS3 documentation <a href="http://livedocs.adobe.com/flash/9.0/main/00000296.html" target="_blank">&#8220;Accessing raw sound data&#8221;</a> in the Programming ActionScript 3.0 book.</p>
<p><span id="more-93"></span></p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        creationComplete="init()"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.core.SoundAsset;

            [Embed('assets/song1.mp3')]
            private const song1:Class;

            private var mySong:SoundAsset = SoundAsset(new song1());

            private var byteArray:ByteArray = new ByteArray();

            private var timer:Timer;

            private function init():void {
                timer = new Timer(50);
                timer.addEventListener(TimerEvent.TIMER, doTimer);
            }

            private function doTimer(evt:TimerEvent):void {
                SoundMixer.computeSpectrum(byteArray, true);

                spr.graphics.clear();
                drawChannel(LEFT_CHANNEL_COLOR);
                drawChannel(RIGHT_CHANNEL_COLOR);
            }

            private function drawChannel(color:uint):void {
                var f:Number;
                var i:int;

                spr.graphics.lineStyle(1, color);
                spr.graphics.beginFill(color, 0.6);
                spr.graphics.moveTo(0, GRAPH_HEIGHT);
                for (i = 0; i &lt; 256; i++) {
                    f = byteArray.readFloat();
                    spr.graphics.lineTo(i * 2, GRAPH_HEIGHT - ((f * GRAPH_HEIGHT)) * 0.75);
                }
                spr.graphics.lineTo(512, GRAPH_HEIGHT);
                spr.graphics.endFill();
            }

            private function playSong():void {
                mySong.play();
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:Number id="GRAPH_WIDTH"&gt;512&lt;/mx:Number&gt;
    &lt;mx:Number id="GRAPH_HEIGHT"&gt;256&lt;/mx:Number&gt;

    &lt;mx:Number id="LEFT_CHANNEL_COLOR"&gt;0xFF0000&lt;/mx:Number&gt;
    &lt;mx:Number id="RIGHT_CHANNEL_COLOR"&gt;0x0000FF&lt;/mx:Number&gt;

    &lt;mx:ApplicationControlBar width="{GRAPH_WIDTH}"&gt;
        &lt;mx:Label text="Left:" color="{LEFT_CHANNEL_COLOR}" fontWeight="bold" /&gt;
        &lt;mx:Label text="Right:" color="{RIGHT_CHANNEL_COLOR}" fontWeight="bold" /&gt;
        &lt;mx:Spacer width="100%" /&gt;
        &lt;mx:Button label="Play" click="playSong(); timer.start()" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:VBox id="hbox" width="{GRAPH_WIDTH}" height="{GRAPH_HEIGHT}" backgroundColor="white"&gt;
        &lt;mx:Box id="spr" width="100%" height="100%" /&gt;
    &lt;/mx:VBox&gt;

&lt;/mx:Application&gt;
</pre>
<p class="new">Here&#8217;s the modified version which uses the Flex 2 Charting components.</p>
<pre class="code">
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init()"&gt;

    &lt;mx:Script&gt;
        &lt;![CDATA[
            import mx.charts.chartClasses.NumericAxis;
            import mx.core.SoundAsset;

            [Embed('assets/song1.mp3')]
            private const song1:Class;

            private var mySong:SoundAsset;
            private var byteArray:ByteArray;
            private var timer:Timer;

            private function init():void {
                byteArray = new ByteArray();

                timer = new Timer(50); /* 50 milliseconds (20x/sec) */
                timer.addEventListener(TimerEvent.TIMER, doTimer);
                timer.start();

                mySong = SoundAsset(new song1());
                // mySong.play();
            }

            private function doTimer(evt:TimerEvent):void {
                var i:int;
                var f:Number;

                SoundMixer.computeSpectrum(byteArray, true);

                leftCh.removeAll();
                for (i = 0; i &lt; 256; i++) {
                    f = byteArray.readFloat();
                    leftCh.addItem({data:f});
                }

                rightCh.removeAll();
                for (i = 0; i &lt; 256; i++) {
                    f = byteArray.readFloat();
                    rightCh.addItem({data:f});
                }
            }
        ]]&gt;
    &lt;/mx:Script&gt;

    &lt;mx:ArrayCollection id="leftCh" /&gt;
    &lt;mx:ArrayCollection id="rightCh" /&gt;

    &lt;mx:ApplicationControlBar dock="true"&gt;
        &lt;mx:Button label="play audio" click="mySong.play();" /&gt;
    &lt;/mx:ApplicationControlBar&gt;

    &lt;mx:ColumnChart id="barChart" width="100%" height="100%"&gt;
        &lt;mx:verticalAxis&gt;
            &lt;mx:LinearAxis minimum="0" maximum="1.4" /&gt;
        &lt;/mx:verticalAxis&gt;

        &lt;mx:series&gt;
            &lt;mx:ColumnSeries dataProvider="{leftCh}" yField="data" displayName="Left" /&gt;
            &lt;mx:ColumnSeries dataProvider="{rightCh}" yField="data" displayName="Right" /&gt;
        &lt;/mx:series&gt;
    &lt;/mx:ColumnChart &gt;

&lt;/mx:Application&gt;
</pre>
<div class="evernoteSiteMemory"><a href="javascript:" onclick="Evernote.doClip({title: 'Displaying sound data using the SoundMixer.computeSpectrum() method on FlexExamples.com',url: 'http://blog.flexexamples.com/2007/08/16/displaying-sound-data-using-the-soundmixercomputespectrum-method/',contentID: 'post-93',code: 'Pete9667',suggestNotebook: 'FlexExamples',suggestTags: 'computeSpectrum()',providerName: 'FlexExamples.com',styling: 'text' });return false" class="evernoteSiteMemoryLink"><img src="http://static.evernote.com/article-clipper-remember.png" class="evernoteSiteMemoryButton" />
				</a>				<div class="evernoteSiteMemoryClear">&nbsp;</div>
</div>]]></content:encoded>
			<wfw:commentRss>http://blog.flexexamples.com/2007/08/16/displaying-sound-data-using-the-soundmixercomputespectrum-method/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

