<?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>Design Reviver &#187; actionscript</title>
	<atom:link href="http://designreviver.com/tag/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://designreviver.com</link>
	<description></description>
	<lastBuildDate>Mon, 15 Mar 2010 09:04:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Create an Interactive Stack of Photos</title>
		<link>http://designreviver.com/tutorials/create-an-interactive-stack-of-photos/</link>
		<comments>http://designreviver.com/tutorials/create-an-interactive-stack-of-photos/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 20:38:55 +0000</pubDate>
		<dc:creator>Henry</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[photography]]></category>
		<category><![CDATA[popular]]></category>

		<guid isPermaLink="false">http://designreviver.com/?p=150</guid>
		<description><![CDATA[In this tutorial, you will learn how to build an interactive stack of photos using Flash. This is a great technique to display numerous images in a limited amount of space, and the best part is that it is extremely easy to execute.
Check out the final result. Click on the photos.
writeFlash("http://designreviver.com/wp-content/uploads/2008/06/stack.swf", 500, 338, "");
Step 1
First, [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, you will learn how to build an interactive stack of photos using Flash. This is a great technique to display numerous images in a limited amount of space, and the best part is that it is extremely easy to execute.<span id="more-150"></span></p>
<p>Check out the final result. Click on the photos.</p>
<p><script>writeFlash("http://designreviver.com/wp-content/uploads/2008/06/stack.swf", 500, 338, "");</script></p>
<h4>Step 1</h4>
<p>First, open up a new ActionScript 3 document in Flash, and create three layers: actions, photos, and background. In the properties panel, set the size of your stage. I used 500 x 338 for this example. </p>
<p><img src="http://designreviver.com/wp-content/uploads/2008/06/stack_step1.jpg" /></p>
<h4>Step 2</h4>
<p>Our photos need something to lay on, so import a texture to the &#8220;background&#8221; layer. I chose a nice wood texture. </p>
<p>Select the &#8220;photos&#8221; layer and import one of your photos to the stage(File > Import > Import to Stage). Before importing, make sure your photos have been resized to fit well on your stage. My photos are 173px x 260px. Select the photo and convert it to a MovieClip(Modify > Convert to Symbol). Make sure that registration point is in the middle and name it &#8220;photo1&#8243;.</p>
<p><img src="http://designreviver.com/wp-content/uploads/2008/06/stack_step2.jpg" /></p>
<h4>Step 3</h4>
<p>Once the image has been converted to a MovieClip, double click on it to view it&#8217;s time line. Create a new layer below the one that the photo is on. On this layer, we are going to create a border. Using the Rectangle Tool, create a box that is 20px taller and wider than the photo, and make sure that it is aligned with it&#8217;s center.</p>
<p><img src="http://designreviver.com/wp-content/uploads/2008/06/stack_step3.jpg" /></p>
<h4>Step 4</h4>
<p>Now lets lift our photo off the table a bit by adding a shadow. To do this, back out to the main time line and select your photo. Next to the properties panel, click on the &#8220;Filters&#8221; tab and add a Glow filter. Set the color to black and the blur to 10. Now position the photo on the left side of your stage, so there is enough room on the right for it to slide out. Make sure to give it an instance name of &#8220;photo1&#8243;.</p>
<p><img src="http://designreviver.com/wp-content/uploads/2008/06/stack_step4.jpg" /></p>
<h4>Step 5</h4>
<p>Repeat steps 2 &#8211; 4 for each of your photos, each time incrementing the number in the name (photo1, photo2, etc).</p>
<h4>Step 6</h4>
<p>Before we start adding any ActionScript, download the AS3 version of <a href="http://code.google.com/p/tweener/" target="_blank">tweener</a>, a class that makes it easy to move things with code. Then extract the &#8220;caurina&#8221; folder into your projects directory.</p>
<h4>Step 7</h4>
<p>On the main time line, select frame 1 on the &#8220;actions&#8221; layer. The first line of our code imports tweener, so we can have access the class. Then we need to define some variables that will make it easy to customize the photo stack later without having to alter the main code.</p>
<pre><code>
import caurina.transitions.*;

var photoOriginX:Number = photo1.x;
var photoDestX:Number = photoOriginX + 200;
var speed:Number = .5;
var rotationRange:Number = 10;
var photoCount:Number = 3;
var easeType:String = "easeoutquad";
</code></pre>
<h4>Step 8</h4>
<p>Now lets add two functions. The first is called when a photo is clicked. It moves the photo to the x position that we defined in step 7. It also rotates the photo to a random value.</p>
<p>The second function moves the photo back to it&#8217;s origin and changes the depth so that it is on the bottom of the stack. It is called when the first tween is complete.</p>
<pre><code>
function photoSlideOut(e:Event):void
{
	e.target.parent.setChildIndex(e.target, e.target.parent.numChildren - 1);
	Tweener.addTween(e.target, {x: photoDestX, time: speed, transition: easeType, onComplete:photoSlideIn, onCompleteParams:[e.target]});
	Tweener.addTween(e.target, {rotation: Math.floor(Math.random()*(rotationRange*2))-rotationRange, time: speed*2, transition: easeType});
}

function photoSlideIn(p:MovieClip)
{
	p.parent.setChildIndex(p, 1);
	Tweener.addTween(p, {x: photoOriginX, time: speed, transition: easeType});
}
</code></pre>
<h4>Step 9</h4>
<p>Initialize the photos by looping through each one and adding the mouse down event and setting an initial random rotation.</p>
<pre><code>
for(var i=1; i<=photoCount; i++)
{
	this["photo"+i].addEventListener(MouseEvent.MOUSE_DOWN, photoSlideOut);
	this["photo"+i].rotation =  Math.floor(Math.random()*(rotationRange*2))-rotationRange;
}
</code></pre>
<p>That's it. Feel free to experiment with the speed and rotation variables to achieve different types of motion.</p>
<p><a href="http://designreviver.com/wp-content/uploads/2008/06/stack.zip" class="downloadLink">Download Example</a></p>
]]></content:encoded>
			<wfw:commentRss>http://designreviver.com/tutorials/create-an-interactive-stack-of-photos/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
		<item>
		<title>ActionScript 3 Jpeg Encoder Revealed: Saving Images from Flash</title>
		<link>http://designreviver.com/tutorials/actionscript-3-jpeg-encoder-revealed-saving-images-from-flash/</link>
		<comments>http://designreviver.com/tutorials/actionscript-3-jpeg-encoder-revealed-saving-images-from-flash/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 04:48:57 +0000</pubDate>
		<dc:creator>Henry</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://designreviver.com/tutorials/actionscript-3-jpeg-encoder-revealed-saving-images-from-flash</guid>
		<description><![CDATA[Some amazing things can be done with images in ActionScript 3. One of these is the ability to encode a display object as a jpeg, and thanks to the JPEG Encoder included in the AS3 Core Library, doing this is actually quite simple. In this article, I will show you how to create a flash [...]]]></description>
			<content:encoded><![CDATA[<p>Some amazing things can be done with images in ActionScript 3. One of these is the ability to encode a display object as a jpeg, and thanks to the JPEG Encoder included in the AS3 Core Library, doing this is actually quite simple. In this article, I will show you how to create a flash file that encodes a movieclip as a jpeg and allows the user to download it to their own computer.<span id="more-126"></span></p>
<p>To give you an idea of how this can be used, try out the sketch pad below:</p>
<p class="center"> <script>writeFlash("http://designreviver.com/wp-content/uploads/2008/06/sketch.swf", 250, 250, "transparent");</script></p>
<h4>First Things First</h4>
<p>Before we get started, make sure to grab the <a href="http://code.google.com/p/as3corelib/" target="_blank">ActionScript 3 Core Library</a>. The Core Library contains several classes and utilities that make it easy to do things such as MD5 hashing, date formatting, and image encoding to name a few. Once you have the library, just drop it into your classes folder and you are ready to go. Now we can import the JPGEncoder.</p>
<pre><code>
import com.adobe.images.JPGEncoder;

</code></pre>
<h4>Encoding the MovieClip</h4>
<p>In this example, we are going to assume that our MovieClip of interest is named sketch_mc. In order to make use of the JPEGEncoder, our MovieClip needs to become a bitmap. To do this, we are going to use the BitmapData class. The  contructor for this class requires two arguments: width and height. Since we want our jpeg to be the same size as sketch_mc, we use it&#8217;s width and height properties. Then by using sketch_mc as an argument, the draw method draws our MovieClip on to the bitmap.</p>
<pre><code>
import com.adobe.images.JPGEncoder;

var jpgSource:BitmapData = new BitmapData (sketch_mc.width, sketch_mc.height);
jpgSource.draw(sketch_mc);

</code></pre>
<p>Now that sketch_mc is in bitmap form, we can use the JPGEncoder. When creating a new instance of this class, you can set the level of compression by passing in a number from 1 &#8211; 100. Then to create our jpeg, we call the encode method and use our BitmapData instance as the argument. The encode method returns the jpeg in the form of a ByteArray, which is simply an AS3 class that makes working with binary data a little easier.</p>
<pre><code>
import com.adobe.images.JPGEncoder;

var jpgSource:BitmapData = new BitmapData (sketch_mc.width, sketch_mc.height);
jpgSource.draw(sketch_mc);

var jpgEncoder:JPGEncoder = new JPGEncoder(85);
var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);

</code></pre>
<h4>From the Flash Player to the Hard Drive</h4>
<p>ActionScript 3 has done all the work neccessary to turn our MovieClip into a jpeg, but it needs a little help in making it available to download. To make this happen, we will need to post our ByteArray to a server side script using the URLRequest class. Since we are posting binary data, we must set the content-type to &#8220;application/octet-stream&#8221;. It is also important to note that the file being downloaded will need a name, so we pass that to our server side script as a query string.</p>
<pre><code>
import com.adobe.images.JPGEncoder;

var jpgSource:BitmapData = new BitmapData (sketch_mc.width, sketch_mc.height);
jpgSource.draw(sketch_mc);

var jpgEncoder:JPGEncoder = new JPGEncoder(85);
var jpgStream:ByteArray = jpgEncoder.encode(jpgSource);

var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");
var jpgURLRequest:URLRequest = new URLRequest("jpg_encoder_download.php?name=sketch.jpg");
jpgURLRequest.requestHeaders.push(header);
jpgURLRequest.method = URLRequestMethod.POST;
jpgURLRequest.data = jpgStream;
navigateToURL(jpgURLRequest, "_blank");

</code></pre>
<p>Below is the php script to where we are posting our jpeg. I chose to use php for this example, but any server side script will do.</p>
<pre><code>
if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{
	// get bytearray
	$jpg = $GLOBALS["HTTP_RAW_POST_DATA"];

	// add headers for download dialog-box
	header('Content-Type: image/jpeg');
	header("Content-Disposition: attachment; filename=".$_GET['name']);
	echo $jpg;
}

</code></pre>
<p><em>Note: I originally wrote this article for <a href="http://henryjones.us" target="_blank">HenryJones.us</a>. Since it was incredibly useful to a lot of people, I decided to make it available to all of the Design Reviver readers.</em></p>
<p><a href="http://designreviver.com/free/jpeg_encoder_example.zip" class="downloadLink" title="Jpeg Encoder Example">Download Sample Code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://designreviver.com/tutorials/actionscript-3-jpeg-encoder-revealed-saving-images-from-flash/feed/</wfw:commentRss>
		<slash:comments>92</slash:comments>
		</item>
	</channel>
</rss>
