<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Activetuts+</title>
	
	<link>http://active.tutsplus.com</link>
	<description>Flash, Flex &amp; ActionScript Tutorials</description>
	<lastBuildDate>Fri, 12 Mar 2010 17:01:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Flashtuts" /><feedburner:info uri="flashtuts" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><image><link>http://active.tutsplus.com</link><url>http://envato.s3.amazonaws.com/rss_images/activetuts.jpg</url><title>Activetuts+</title></image><feedburner:emailServiceId>Flashtuts</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Extend your Flash Application Using the Context Menu</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/jdDhXFDFrGo/</link>
		<comments>http://active.tutsplus.com/tutorials/actionscript/extend-your-flash-application-using-the-context-menu/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 12:00:26 +0000</pubDate>
		<dc:creator>Carlos Yanez</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=3377</guid>
		<description><![CDATA[A Context Menu is a menu in a graphical user interface that appears upon user interaction, such as a right-mouse click. The Flash Player context menu allows you to add custom menu items, control the display of the built-in context menu items (for example, Zoom In and Print) and create copies of menus.
In this tutorial, [...]]]></description>
			<content:encoded><![CDATA[<p>A Context Menu is a menu in a graphical user interface that appears upon user interaction, such as a right-mouse click. The Flash Player context menu allows you to add custom menu items, control the display of the built-in context menu items (for example, Zoom In and Print) and create copies of menus.</p>
<p>In this tutorial, we&#8217;ll learn how to take advantage of these items.</p>
<p><span id="more-3377"></span></p>
<hr />
<h2>Final Result Preview</h2>
<p>Let&#8217;s take a look at the final result we will be working towards:</p>
<div class="tutorial_image">
<object width="600" height="300" data="http://activetuts.s3.cdn.plus.org/tuts/077_contextMenus/Preview/ContextMenu.swf" type="application/x-shockwave-flash"><param name="src" value="http://activetuts.s3.cdn.plus.org/tuts/077_contextMenus/Preview/ContextMenu.swf" /></object></p>
<p>Right-click on the different areas of the SWF to see how the context menu changes.</p>
</div>
<hr />
<h2><span>Step 1:</span> Brief Overview</h2>
<p>We&#8217;ll make use of the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/ui/ContextMenu.html">ContextMenu</a> class to create an application showing the different methods and properties of this class.</p>
<hr />
<h2><span>Step 2:</span> Create New Document</h2>
<p>Open Flash and create a new Flash File (ActionScript 3.0).</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/077_contextMenus/Tutorial/1.jpg" alt="" /></div>
<p>Set the stage size to 600&#215;300 and add a black radial background (#555555 to #252525).</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/077_contextMenus/Tutorial/2.jpg" alt="" /></div>
<hr />
<h2><span>Step 3:</span> Add Target MovieClips</h2>
<p>We will create four MovieClips that will each show a different context menu when right-clicked.</p>
<p>Select the Rectangle Tool (R) and create four squares of 100&#215;100 px each, with some writing inside. Convert them to separate MovieClip symbols and align them to the corners of the stage; use the image below as a guide. The instance names are in italics.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/077_contextMenus/Tutorial/3.jpg" alt="" /></div>
<hr />
<h2><span>Step 4:</span> Add Simple Instructions</h2>
<p>Add some text to the stage to indicate to the user what action to perform.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/077_contextMenus/Tutorial/4.jpg" alt="" /></div>
<hr />
<h2><span>Step 5:</span> Create the Document Class</h2>
<p>Create a new ActionScript Document and save it as <em>Main.as</em>. This will form our document class. If you are not sure how to use a document class, please read <a href="http://active.tutsplus.com/tutorials/actionscript/quick-tip-how-to-use-a-document-class-in-flash/">this Quick Tip</a>.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/077_contextMenus/Tutorial/5.jpg" alt="" /></div>
<hr />
<h2><span>Step 6:</span> Start Writing the Document Class</h2>
<p>The package keyword allows you to organize your code into groups that can be imported by other scripts, it&#8217;s recommended to name them starting with a lowercase letter and use intercaps for subsequent words &#8211; for example: <em>myClasses</em>.</p>
<p>If you don&#8217;t want to group your files in a package or you have only one class you can use it right from your source folder.</p>
<pre name="code" class="javascript">
package
{</pre>
<hr />
<h2><span>Step 7:</span> Import Required Classes</h2>
<p>We&#8217;ll make use of the following classes, so import them in the document class:</p>
<pre name="code" class="javascript">
import flash.display.Sprite;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;
import flash.events.ContextMenuEvent;
import flash.net.navigateToURL;
import flash.net.URLRequest;
</pre>
<hr />
<h2><span>Step 8:</span> Extend MovieClip</h2>
<p>We&#8217;re going to use MovieClip-specific methods and properties so we extend that class.</p>
<pre name="code" class="javascript">
public class Main extends MovieClip
{
</pre>
<hr />
<h2><span>Step 9:</span> Define Variables</h2>
<p>These are the variables we&#8217;ll use. They are basically ContextMenu and ContextMenuItem instances.</p>
<pre name="code" class="javascript">
/* When a ContextMenu item is created you can specify: the name of the item, whether to use a separator line,
   whether the item should be enabled by default, and whether it is visible to the user */

var builtInItems:ContextMenu = new ContextMenu();
var customItemEnabled:ContextMenu = new ContextMenu();
var customEnabled:ContextMenuItem = new ContextMenuItem('ActiveTuts+');
var customItemDisabled:ContextMenu = new ContextMenu();
var customDisabled:ContextMenuItem = new ContextMenuItem('Disabled Item', false, false);
var linkedItem:ContextMenu = new ContextMenu();
var linkText:ContextMenuItem = new ContextMenuItem('Go to TutsPlus.com', true);
var textCM:ContextMenu = new ContextMenu();
</pre>
<hr />
<h2><span>Step 10:</span> Write Main() Constructor Function</h2>
<p>This function is executed when the class is loaded. It calls the functions that will handle the ContextMenu elements.</p>
<pre name="code" class="javascript">
public function Main():void
{
	handleBuiltIn();
	handleCustom();
	handleDisabled();
	handleLink();
	handleClipboard();
}</pre>
<p>We&#8217;ll write these functions in the next steps.</p>
<hr />
<h2><span>Step 11:</span> Write handleBuiltIn() Function</h2>
<p>This is the function that handles the built-in items. Here we take builtInItems, a ContextMenu we defined earlier, remove the built-in items, and set it as the context menu for the builtIn square symbol.</p>
<pre name="code" class="javascript">
private function handleBuiltIn():void
{
	builtInItems.hideBuiltInItems(); //Hides all built-in menu items (except Settings)
	builtIn.contextMenu = builtInItems;
}</pre>
<p>You can see a list of the built-in menu items <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/ui/ContextMenuBuiltInItems.html">here</a>.</p>
<p>Alternatively, you can enable/disable specific menu items using the builtInItems property as shown in the following code:</p>
<pre name="code" class="javascript">
var defaultItems:ContextMenuBuiltInItems = myContextMenu.builtInItems;
defaultItems.print = true; //You can replace "print" with a valid default context menu item
</pre>
<p>Again, visit <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/ui/ContextMenuBuiltInItems.html">livedocs.adobe.com</a> for a list of such items.</p>
<hr />
<h2><span>Step 12:</span> Add a Custom Item</h2>
<p>To add a custom item to the context menu, we&#8217;ll make use of two of the variables we created.</p>
<pre name="code" class="javascript">private function handleCustom():void
{
	customItemEnabled.customItems.push(customEnabled); // Adds the customItemEnabled ContextMenuItem value to the ContextMenu instance
	custom.contextMenu = customItemEnabled; // Sets the ContextMenu instance to the MovieClip
}
</pre>
<p>As you can see, we can push() a ContextMenuItem onto a context menu&#8217;s <em>customItems</em> property, because it is an array.</p>
<hr />
<h2><span>Step 13:</span> Add a Disabled Item</h2>
<p>The same action is performed by this function, but using the <em>customItemDisabled</em> parameter in the ContextMenuItem.</p>
<pre name="code" class="javascript">
private function handleDisabled():void
{
	customItemDisabled.customItems.push(customDisabled);
	disabled.contextMenu = customItemDisabled;
}
</pre>
<p>This makes the item look grayed-out and unclickable.</p>
<hr />
<h2><span>Step 14:</span> Add an Action</h2>
<p>We know how to add a custom item to the context menu list, so far it can be used as a message or a notice but it will be more useful if an action can be performed when clicked. Let&#8217;s see how to do it.</p>
<pre name="code" class="javascript">
//A webpage will be opened when the menu is clicked

private function handleLink():void
{
	linkedItem.customItems.push(linkText);	//remember we set the text of this link earlier
	linkText.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, onMenuSelect);
	link.contextMenu = linkedItem;
}

private function onMenuSelect(e:ContextMenuEvent):void
{
	navigateToURL(new URLRequest('http://tutsplus.com'))
}
</pre>
<hr />
<h2><span>Step 15:</span> Alter the Clipboard Context Menu</h2>
<p>The ContextMenuClipboardItems class determines which items are enabled or disabled on the clipboard context menu. These settings are used when ContextMenu.clipboardMenu = true and when the object with focus is not a TextField.</p>
<pre name="code" class="javascript">
private function handleClipboard():void
{
	textCM.clipboardMenu = true;
	textCM.clipboardItems.selectAll = false;
	contextMenu = textCM;
}</pre>
<p>Note that these settings only apply in Flash Player 10, so cannot be used in Flash CS3 (they will cause a compiler error if you try to use them).</p>
<hr />
<h2><span>Step 16:</span> Document Class</h2>
<p>Go back to the .fla file and in the Properties Panel set the Class field to &#8216;Main&#8217; to make this the Document Class.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/077_contextMenus/Tutorial/10.jpg" alt="" /></div>
<hr />
<h2>Conclusion</h2>
<p>Customizing the Context Menu in your movies or applications can extend its functionality in a very usable way, try it!</p>
<p>Thanks for reading!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=jdDhXFDFrGo:nNV8IVwmsMU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=jdDhXFDFrGo:nNV8IVwmsMU:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=jdDhXFDFrGo:nNV8IVwmsMU:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=jdDhXFDFrGo:nNV8IVwmsMU:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=jdDhXFDFrGo:nNV8IVwmsMU:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=jdDhXFDFrGo:nNV8IVwmsMU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=jdDhXFDFrGo:nNV8IVwmsMU:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=jdDhXFDFrGo:nNV8IVwmsMU:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=jdDhXFDFrGo:nNV8IVwmsMU:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=jdDhXFDFrGo:nNV8IVwmsMU:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/jdDhXFDFrGo" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/actionscript/extend-your-flash-application-using-the-context-menu/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/tutorials/actionscript/extend-your-flash-application-using-the-context-menu/</feedburner:origLink></item>
		<item>
		<title>Quick Tip: How to Communicate Between Flash and HTML</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/8JhY4HVKU0s/</link>
		<comments>http://active.tutsplus.com/tutorials/actionscript/quick-tip-how-to-communicate-between-flash-and-html-with-externalinterface/#comments</comments>
		<pubDate>Thu, 11 Mar 2010 12:41:05 +0000</pubDate>
		<dc:creator>Jeremy Green</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=3370</guid>
		<description><![CDATA[In this Quick Tip, we&#8217;ll look at how to use the ExternalInterface class. This allows us to write AS3 which can run JavaScript code, and vice-versa. That means you can use Flash to alter parts of the webpage in which it&#8217;s running!


Step 1: Set up the Flash Document
Create a new Flash ActionScript 3 document.  [...]]]></description>
			<content:encoded><![CDATA[<p>In this Quick Tip, we&#8217;ll look at how to use the ExternalInterface class. This allows us to write AS3 which can run JavaScript code, and vice-versa. That means you can use Flash to alter parts of the webpage in which it&#8217;s running!</p>
<p><span id="more-3370"></span></p>
<hr />
<h2><span>Step 1:</span> Set up the Flash Document</h2>
<p>Create a new Flash ActionScript 3 document.  Resize the stage to be 600&#215;300.  With the rectangle tool, draw out a rectangle that is the size of the stage.  Give it a color of #CCCCCC.  Also, give it a black stroke of 2px.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/079_QTexternalInterface/Tutorial/1.jpg" alt="" /></div>
<hr />
<h2><span>Step 2:</span> Set up the Flash UI</h2>
<p>Here&#8217;s the layout we&#8217;ll be working towards:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/079_QTexternalInterface/Tutorial/2.jpg" alt="" /></div>
<p>Open the Components Panel (Window > Components) and, from the User Interface folder, drag a ColorPicker component onto the stage.  Give it an instance name of &#8216;cp&#8217;.</p>
<p>Next create a dynamic text field called &#8216;resizeText&#8217;; place and size it however you please (you can&#8217;t see the one in my image; it&#8217;s empty, and in the top-right of the stage.)</p>
<p>Now, create another dynamic text field.  Give it an instance name of &#8216;jsText&#8217;. Then create a button symbol and give it an instance name of &#8216;prompt&#8217;.  After that, create another button and give it an instance name of &#8216;change&#8217;.</p>
<p>Finally, create two input text fields.  Place one next to your &#8216;prompt&#8217; button, and give it a name of &#8216;promptText&#8217;.  Take the second text field, move it next to your &#8216;change&#8217; button and name it &#8216;changeText&#8217;.</p>
<p>Also, add any labels you want; refer to my image to see how I set it up.</p>
<hr />
<h2><span>Step 3:</span> Set up the HTML UI</h2>
<p>In order for the ExternalInterface to work, the document has to be on the internet.  First, create a new text file, and save it as &#8216;externalInterface.html&#8217;.  Next, open a text editor and add all the code below. Save the HTML file.</p>
<pre name="code" class="html">
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;title&gt;externalInterface&lt;/title&gt;
&lt;style type="text/css"&gt;

body {
	font-family:Arial;
}

#asSend {
	padding-top:20px;
	font-size:12px;
}
#htmlWrap {
	margin-top:10px;
	width:578px;
	padding-left:20px;
	border-width:1px;
	border-style:solid;
}
#sender {
	margin-top:10px;
}
#textChange {
	font-size:13px;
	font-weight:bold;
	padding-top:10px;
	padding-bottom:20px;
}

&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="600" height="300" id="externalInterface" align="middle"&gt;
  &lt;param name="allowScriptAccess" value="sameDomain" /&gt;
  &lt;param name="allowFullScreen" value="false" /&gt;
  &lt;param name="movie" value="externalInterface.swf" /&gt;
  &lt;param name="quality" value="high" /&gt;
  &lt;param name="bgcolor" value="#ffffff" /&gt;
  &lt;embed src="externalInterface.swf" quality="high" bgcolor="#ffffff" width="600" height="300" name="externalInterface" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /&gt;
&lt;/object&gt;
&lt;div id="htmlWrap"&gt;
&lt;div id="asSend"&gt;
  &lt;label for="textArea"&gt;Send to actionscript:&lt;/label&gt;&lt;br /&gt;
  &lt;textarea cols="50" rows="4" id="textArea" name="textArea"&gt;&lt;/textarea&gt;
  &lt;br /&gt;
  &lt;button id="sender" name="sender"&gt;Send&lt;/button&gt;
&lt;/div&gt;
&lt;div id="textChange"&gt;Use Actionscript to change me!&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The key areas are:</p>
<ul>
<li>The &lt;object&gt; section, which embeds the SWF you&#8217;ll create from the Flash file.</li>
<li>The &lt;div&gt;s and &lt;textarea&gt;, which have <em>id</em> properties so that we can access them from the SWF.</li>
</ul>
<p>Your HTML should appear as below:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/079_QTexternalInterface/Tutorial/3.jpg" alt="" /></div>
<p>When the code has been replaced, upload the file to your webserver, so we can get started with the ActionScript.</p>
<hr />
<h2><span>Step 4:</span> Set up a Document Class</h2>
<p>Create a document class for your Flash file; call it Main.as. If you&#8217;re not familiar with document classes, read <a href="http://active.tutsplus.com/tutorials/actionscript/quick-tip-how-to-use-a-document-class-in-flash/">this Quick Tip</a>.</p>
<pre name="code" class="javascript">
package
{
	import flash.display.MovieClip;
	public class Main extends MovieClip {
		public function Main() {

		}
	}
}
</pre>
<hr />
<h2><span>Step 5:</span> Calling JavaScript Functions from Flash</h2>
<p>The first thing we&#8217;ll do with the ExternalInterface is call a JavaScript function that will change the background color of our webpage. So, attach an event listener to our ColorPicker component.  When the color changes, it will send the hex value to a javascript function called receiveColor():</p>
<pre name="code" class="javascript">
package
{
	import fl.events.ColorPickerEvent;
	import flash.display.MovieClip;
	public class Main extends MovieClip {
		public function Main() {
			cp.addEventListener(ColorPickerEvent.CHANGE, colorChange);
		}

		public function colorChange(event:ColorPickerEvent):void {
			ExternalInterface.call("receiveColor", event.target.hexValue);	//calls receiveColor(event.target.hexValue) in the javascript
		}
	}
}
</pre>
<p>Now we have to write this receiveColor() function. In the head of our HTML document, we start the javascript by defining this function. It simply takes the value sent to it from Flash and changes the background color.</p>
<pre name="code" class="html">
<script type="text/javascript">
function receiveColor(value) {
	document.bgColor = "#" + value;
}
</script>
</pre>
<p>Put that right after &lt;head&gt; in your HTML file. If all&#8217;s well, when you run the HTML page in a browser and change the color in the ColorPicker, it should change the background color of the webpage.</p>
<hr />
<h2><span>Step 6:</span> Calling ActionScript Functions from JavaScript</h2>
<p>The next example will be to send data from JavaScript to Flash.  In the HTML document, paste the following code within the &lt;script&gt; tag you added in the last step: </p>
<pre name="code" class="html">
window.onload = function() {
	var sender = document.getElementById("sender");		//getElementById finds an element according to its "id" property
	sender.onclick = function() {
		var ta = document.getElementById("textArea");
		document['externalInterface'].receiveText(ta.value);
		ta.value = "";
	};
};
</pre>
<p>Here&#8217;s what this does: after the document is loaded, we get the &#8217;sender&#8217; button and attach an event listener to it.  When the &#8217;sender&#8217; button is clicked, it will call the receiveText() function in Flash that we will set up now.</p>
<p>Back in Flash, we tell the ExteralInterface to register the ActionScript function so that it can be called from JavaScript.  Then we set up our receiveText() function:</p>
<pre name="code" class="javascript">
package
{
	import fl.events.ColorPickerEvent;
	import flash.display.MovieClip;
	public class Main extends MovieClip {
		public function Main() {
			cp.addEventListener(ColorPickerEvent.CHANGE, colorChange);
			ExternalInterface.addCallback("receiveText", receiveText);	//allows JavaScript to access the receiveText() function.
		}

		public function colorChange(event:ColorPickerEvent):void {
			ExternalInterface.call("receiveColor", event.target.hexValue);
		}

		//this is the new receiveText function
		public function receiveText(value:String):void {
			jsText.text = value;
		}
	}
}
</pre>
<p>(New lines are 8 and 15-18.)</p>
<hr />
<h2><span>Step 7:</span> Calling JavaScript Alerts, Confirms and Prompts from ActionScript</h2>
<p>We can also call alerts very easily from ActionScript.  Here we simply tell the ExternalInterface to call a &#8216;prompt&#8217;.  We can also use the ExternalInterface to pass parameters to functions.  Here we tell the &#8216;prompt&#8217; function to ask the user his or her name.  When our user enters the info, it&#8217;s passed back to the &#8216;promptText&#8217; text field.</p>
<pre name="code" class="javascript">
package
{
	import fl.events.ColorPickerEvent;
	import flash.display.MovieClip;
	public class Main extends MovieClip {
		public function Main() {
			cp.addEventListener(ColorPickerEvent.CHANGE, colorChange);
			ExternalInterface.addCallback("receiveText", receiveText);
			prompt.addEventListener(MouseEvent.CLICK, promptClick);	//makes promptClick() run when prompt button is clicked
		}

		public function colorChange(event:ColorPickerEvent):void {
			ExternalInterface.call("receiveColor", event.target.hexValue);
		}

		public function receiveText(value:String):void {
			jsText.text = value;
		}

		//function to be called when prompt button is clicked. Will ask for user's name using a JS prompt.
		public function promptClick(event:MouseEvent):void {
			promptText.text = "You said your name is: " + ExternalInterface.call("prompt", "What is your name?");
		}
	}
}
</pre>
<p>(New lines are 9 and 20-23.)</p>
<hr />
<h2><span>Step 8:</span> Calling Anonymous JavaScript Functions</h2>
<p>Another thing we can do is write our own JavaScript functions as strings, then call them from the ExternalInterface.  Here we create a JavaScript function that receives a parameter.  We take that parameter and assign its value to the innerHTML attribute of our &#8216;textChange&#8217; div in the HTML document.  You&#8217;ll notice that there are no external JavaScript functions being called &#8211; it is all contained within the ActionScript.</p>
<pre name="code" class="javascript">
package
{
	import fl.events.ColorPickerEvent;
	import flash.display.MovieClip;
	public class Main extends MovieClip {
		public function Main() {
			cp.addEventListener(ColorPickerEvent.CHANGE, colorChange);
			ExternalInterface.addCallback("receiveText", receiveText);
			prompt.addEventListener(MouseEvent.CLICK, promptClick);
			change.addEventListener(MouseEvent.CLICK, changeClick);	//makes changeClick() run when change button is clicked
		}

		public function colorChange(event:ColorPickerEvent):void {
			ExternalInterface.call("receiveColor", event.target.hexValue);
		}

		public function receiveText(value:String):void {
			jsText.text = value;
		}

		public function promptClick(event:MouseEvent):void {
			promptText.text = "You said your name is: " + ExternalInterface.call("prompt", "What is your name?");
		}

		//changes text inside the HTML to match text field inside Flash
		public function changeClick(event:MouseEvent):void {
			ExternalInterface.call("function(param){ document.getElementById('textChange').innerHTML = param; }", changeText.text);
			changeText.text = "";
		}
	}
}
</pre>
<p>(New lines are 10 and 25-29.)</p>
<hr />
<h2><span>Step 9:</span> Calling Anonymous JavaScript and ActionScript Functions</h2>
<p>Finally, we can call anonymous functions on both sides.  In the &#8216;anonymous&#8217; function, we register an anonymous ActionScript function with the ExternalInterface.  The function fills in some text, then starts a timer.  Next, we call an anonymous JavaScript function.  This function tells the window, when it&#8217;s been resized, it must call back to our anonymous ActionScript function.</p>
<pre name="code" class="javascript">
package
{
	import fl.events.ColorPickerEvent;
	import flash.display.MovieClip;
	public class Main extends MovieClip {
		public function Main() {
			cp.addEventListener(ColorPickerEvent.CHANGE, colorChange);
			ExternalInterface.addCallback("receiveText", receiveText);
			prompt.addEventListener(MouseEvent.CLICK, promptClick);
			change.addEventListener(MouseEvent.CLICK, changeClick);

			//create a new timer with a one second tick, and add an event listener
			var timer:Timer = new Timer(1000);
			timer.addEventListener(TimerEvent.TIMER, onTimer);

			anonymous();   //set up the anonymous functions
		}

		public function colorChange(event:ColorPickerEvent):void {
			ExternalInterface.call("receiveColor", event.target.hexValue);
		}

		public function receiveText(value:String):void {
			jsText.text = value;
		}

		public function promptClick(event:MouseEvent):void {
			promptText.text = "You said your name is: " + ExternalInterface.call("prompt", "What is your name?");
		}

		public function changeClick(event:MouseEvent):void {
			ExternalInterface.call("function(param){ document.getElementById('textChange').innerHTML = param; }", changeText.text);
			changeText.text = "";
		}

		//clear the text after one second has passed
		public function onTimer(event:TimerEvent):void {
			resizeText.text = "";
			timer.stop();
		}

		public function anonymous():void {
			//see how we're defining a function inside another function?
			ExternalInterface.addCallback("anon", function(){
				resizeText.text = "The window has been resized.";
				timer.start();
			});

			//same applies here
			ExternalInterface.call("function(){ window.onresize = function(){ document['externalInterface'].anon(); }; }");
		}
	}
}
</pre>
<p>(New lines are 12-16 and 36-51.)</p>
<hr />
<h2><span>Conclusion</h2>
<p>The ExternalInterface is an extremely powerful and useful class. With it, you can receive values and events, all outside of the SWF. Have fun with it and thanks for reading!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=8JhY4HVKU0s:PNEKKc1C9pk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=8JhY4HVKU0s:PNEKKc1C9pk:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=8JhY4HVKU0s:PNEKKc1C9pk:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=8JhY4HVKU0s:PNEKKc1C9pk:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=8JhY4HVKU0s:PNEKKc1C9pk:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=8JhY4HVKU0s:PNEKKc1C9pk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=8JhY4HVKU0s:PNEKKc1C9pk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=8JhY4HVKU0s:PNEKKc1C9pk:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=8JhY4HVKU0s:PNEKKc1C9pk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=8JhY4HVKU0s:PNEKKc1C9pk:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/8JhY4HVKU0s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/actionscript/quick-tip-how-to-communicate-between-flash-and-html-with-externalinterface/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/tutorials/actionscript/quick-tip-how-to-communicate-between-flash-and-html-with-externalinterface/</feedburner:origLink></item>
		<item>
		<title>Create a Retro CRT Distortion Effect Using RGB Shifting</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/E6OzkTX_FiE/</link>
		<comments>http://active.tutsplus.com/tutorials/effects/create-a-retro-crt-distortion-effect-using-rgb-shifting/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 12:00:54 +0000</pubDate>
		<dc:creator>Cadin Batrack</dc:creator>
				<category><![CDATA[Effects]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=3359</guid>
		<description><![CDATA[In this tutorial you&#8217;ll learn how to separate an image&#8217;s three different color channels to create an RGB shift effect. I&#8217;ll also show you some graphics tricks to mimic an old CRT display.


Final Result Preview
Here&#8217;s an example of the effect we&#8217;ll be creating:



The main takeaway in this tutorial is going to be the RGB shifting [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial you&#8217;ll learn how to separate an image&#8217;s three different color channels to create an RGB shift effect. I&#8217;ll also show you some graphics tricks to mimic an old CRT display.</p>
<p><span id="more-3359"></span></p>
<hr/>
<h2>Final Result Preview</h2>
<p>Here&#8217;s an example of the effect we&#8217;ll be creating:</p>
<div class="tutorial_image">
<object width="550" height="300" data="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/Preview.swf" type="application/x-shockwave-flash"><param name="src" value="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/Preview.swf" /></object>
</div>
<p>The main takeaway in this tutorial is going to be the RGB shifting effect, but I&#8217;ll also demonstrate how to create the CRT scan lines, noise, and roll bar graphics.</p>
<hr/>
<h2><span>Step 1:</span> About RGB Images</h2>
<p>Every image on your computer screen is displayed using the colors red, blue and green. By mixing these three colors in various amounts your computer can create the other colors in the spectrum.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/1.jpg" alt="RGB Color Channels" /></div>
<p>If the three color channels don&#8217;t align properly the image won&#8217;t be composited correctly, and you&#8217;ll start to see the edges of the individual channels &#8216;bleeding&#8217; out of the sides of the image.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/2.jpg" alt="Misaligned Color Channels" /></div>
<p>This is exactly what we&#8217;re going to be doing in this tutorial; separating an image into its three color channels and then transforming each individually to create a distortion effect. Let&#8217;s get to it!</p>
<p>(You can learn a lot more about how RGB color works at <a href="http://en.wikipedia.org/wiki/RGB_color_model">Wikipedia</a>.)</p>
<hr/>
<h2><span>Step 2:</span> Create A Title Screen</h2>
<p>You&#8217;ll need to create a graphic to apply the effect to. I chose to create a video game title screen, but you can make whatever kind of graphic you want. </p>
<p>Create a new Movie Clip called &#8216;titleScreen&#8217; and put your title screen (or other graphics) inside.</p>
<p>I think something retro-themed works best with this effect since it reminds me of an old malfunctioning arcade screen. I created my title screen with a font called <a href="http://www.dafont.com/commodore-64-pixele.font">Commodore 64 Pixeled</a>. I added a Glow filter to the text to give it that smeary, blown out CRT look.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/3.jpg" alt="Glow Filter on Text" /></div>
<p>Once you&#8217;re happy with your design, add the <em>titleScreen</em> MovieClip to the stage and give it the instance name &#8216;titleScreen&#8217;.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/4.jpg" alt="titleScreen Instance" /></div>
<hr/>
<h2><span>Step 3:</span> Create the <em>RGBShift</em> class</h2>
<p>Create a new Actionscript file named &#8216;RGBShift.as&#8217;. Save this file in the same directory as your main Flash file. Add this code to create the shell for the class:</p>
<pre name="code" class="javascript">
package {

	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.display.BitmapData;
	import flash.display.Bitmap;
	import flash.display.BitmapDataChannel;
	import flash.display.BlendMode;
	import flash.events.Event;
	import flash.geom.Point;

	public class RGBShift extends Sprite {

		private var _centerX:Number;
		private var _centerY:Number;

		// CONSTRUCTOR
		public function RGBShift(dObj:DisplayObject) {

        }

	}

}
</pre>
<p><strong>Editor&#8217;s note:</strong> Not comfortable with class-based coding yet? Check out <a href="http://active.tutsplus.com/tutorials/actionscript/quick-tip-how-to-use-a-document-class-in-flash/">this Quick Tip</a> to help you get started.</p>
<p>This code doesn&#8217;t really do anything yet. The first 10 lines or so import all the extra classes we&#8217;re going to need. I have two private variables named &#8216;_centerX&#8217; and &#8216;_centerY&#8217; (I use the underscores to signify private variables). These two variables will hold the x and y coordinates of the center of our graphic.</p>
<p>Notice that the constructor function (empty for now) accepts a DisplayObject. This will allow us to use any type of DisplayObject with this effect (MovieClip, Sprite, Bitmap, etc.) We&#8217;re going to be using the <em>titleScreen</em> MovieClip from the stage, but having the class accept any DisplayObject keeps it flexible for later uses.</p>
<hr/>
<h2><span>Step 4:</span> Add the <em>createBMD</em> Function</h2>
<p>We made our class flexible by allowing it to accept any DisplayObject, but we&#8217;re actually going to need a BitmapData object to do the RGB shifting effect. Let&#8217;s create a function that can create BitmapData from a DisplayObject.</p>
<p>Add this function to your RGBShift class just below the constructor:</p>
<pre name="code" class="javascript:firstline[23]">
private function createBMD(dObj:DisplayObject):BitmapData {
	// create a new BitmapData object the size of our DisplayObject
	var bmd:BitmapData = new BitmapData(dObj.width, dObj.height,
										true, 0xFF000000);

	// draw the display object to the bitmap data
	bmd.draw(dObj);

	return bmd;
}
</pre>
<p>Take a look at what this function does. The first line uses the DisplayObject&#8217;s width and height to create a new transparent BitmapData object the same size as the DisplayObject. Next, it draws the DisplayObject to the BitmapData. Finally it returns the BitmapData to the caller.</p>
<hr/>
<h2><span>Step 5:</span> Add the <em>createRGB</em> Function</h2>
<p>Here&#8217;s where the actual color separation takes place. Add this function to your class:</p>
<pre name="code" class="javascript:firstline[33]">
private function createRGB(dObj:DisplayObject):Array {
	 var bmd:BitmapData = createBMD(dObj); // create bitmapData from the display object

	// create a new bitmap data object for each color channel
	var r:BitmapData = new BitmapData(bmd.width, bmd.height, true, 0xFF000000);
	var g:BitmapData = new BitmapData(bmd.width, bmd.height, true, 0xFF000000);
	var b:BitmapData = new BitmapData(bmd.width, bmd.height, true, 0xFF000000);

	// copy the data from each channel into the corresponding bitmap data
	r.copyChannel(bmd, bmd.rect, new Point(),
					BitmapDataChannel.RED, BitmapDataChannel.RED);
	g.copyChannel(bmd, bmd.rect, new Point(),
					BitmapDataChannel.GREEN, BitmapDataChannel.GREEN);
	b.copyChannel(bmd, bmd.rect, new Point(),
					BitmapDataChannel.BLUE, BitmapDataChannel.BLUE);

	// return an array with the bitmap data for the 3 color channels
	return [r, g, b];
}
</pre>
<p>This function also accepts a DisplayObject. It then passes that to the <em>createBMD()</em> function we wrote in the previous step, which converts it to BitmapData. Next we create three new transparent BitmapData objects; one for each color. We create them at the exact same size as our source BitmapData (from the DisplayObject).</p>
<p>We then use BitmapData&#8217;s <em>copyChannel()</em> method to copy a single color channel from the source BitmapData into each of the three new BitmapData objects.</p>
<p>The final line simply returns the three new BitmapData objects wrapped in an array.</p>
<hr/>
<h2><span>Step 6:</span> Use the <em>createRGB</em> Function in the Constructor</h2>
<p>Now that we have our <em>createBMD</em> and <em>createRGB</em> classes working together, let&#8217;s put them to use. Add this as the first line of code in the constructor function for the RGBShift class:</p>
<pre name="code" class="javascript:firstline[19]">
var rgbBMD:Array = createRGB(dObj);
</pre>
<p>This line just passes the DisplayObject to the <em>createRGB()</em> function. <em>createRGB()</em> uses the <em>createBMD()</em> function to convert it to BitmapData and then separates it onto three separate BitmapData objects (one for each channel). Finally it returns the array of those three objects to our local <em>rgbBMD</em> array. Make sense? Good.</p>
<hr/>
<h2><span>Step 7:</span> Create Bitmaps from the RGB Channels</h2>
<p>We now have an array of three BitmapData objects. We need to create a Bitmap from each in order to display them on the screen. Add this <em>for</em> loop to the constructor function of RGBShift just below  the last line we added:</p>
<p><strong>Editor&#8217;s note:</strong> Sorry for the inconvenience folks, displaying this particular bit of ActionScript trips FireFox over. Feel free to <a href="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/step7.as">download it here</a>.</p>
<p><!--
<pre name="code" class="javascript:firstline[21]">
</pre>
<p>--></p>
<p>Most of this is pretty simple. Let's take a look.</p>
<ul>
<li>With each BitmapData object in our rgbBMD array we're creating a new Bitmap.</li>
<li>We set smoothing to true so we can scale and rotate it without it getting pixelated. (line 23)</li>
<li>Next we create a container Sprite and add the new Bitmap to the container's display list. (lines 25 &amp; 26)</li>
<li>Now we finally start using the _centerX and _centerY variables. We set each to the center of the Bitmap by dividing the width and height in half.</li>
<li>We use this center point to offset the Bitmap inside the container Sprite, and then to offset the container Sprite on the stage. I'll explain why in the next step.</li>
<li>Finally we add the container Sprite to the stage (remember there is a container for each of our three color channels).</li>
</ul>
<hr/>
<h2><span>Step 8:</span> Why Use the Container Sprite?</h2>
<p>You could create this effect without the container Sprite by just adding the Bitmaps directly to the stage. I like to wrap them in a container because it makes it easier to control the transform point when you do things like scale and rotate.</p>
<p>Normally, when you perform a scale or a rotate on an object it transforms from the origin point (0,0) of that object. That's seldom what I want to happen. Usually I want the transformations to be applied from the center of the object.</p>
<p>Notice that in the last section we set the x and y of the Bitmaps to <em>negative</em> one half the width and height. This places the Bitmap so that its center point is at 0,0 in the container Sprite. If we perform any transformations on the container Sprite it will transform from 0,0 of the container, which is now the center of our Bitmap.</p>
<p>The only problem is that only the bottom corner of our Bitmap is visible now, so I set the container Sprite x and y to half the height and width of the Bitmap to get everything back its correct position.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/5.jpg" alt="Container Sprite Offset" /></div>
<hr/>
<h2><span>Step 9:</span> RGBShift Class</h2>
<p>Here's the RGBShift class up to this point in case you got lost along the way:</p>
<p><strong>Editor's note:</strong> Me again, once more you'll have to <a href="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/step9.as">download the AS here</a>. Sorry for the inconvenience.</p>
<p><!--
<pre name="code" class="javascript">
</pre>
<p>--></p>
<hr/>
<h2><span>Step 10:</span> Create the Main Document Class</h2>
<p>So, we have our RGBShift class, but how do we use it? Begin by creating a new Actionscript file called Main.as, then add this code:</p>
<pre name="code" class="javascript">
package {

	import flash.display.MovieClip;

	public class Main extends MovieClip {

		public function Main() {

			var rgb = new RGBShift(titleScreen); // create a new RGBShift from the titleScreen
			removeChild(titleScreen); // remove the original title screen from the stage

			// add it to the stage
			addChild(rgb);

		}
	}

}
</pre>
<p>Here we're creating a new instance of the RGBShift class and passing it the <em>titleScreen</em> MovieClip from the stage. We no longer need that MovieClip, so we remove it from the stage and add the new RGBShift instance instead.</p>
<p>Now we just have to link this class to our Flash document. Go back to Flash and set the document class to 'Main'.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/6.jpg" alt="Set the Document Class" /></div>
<hr/>
<h2><span>Step 11:</span> Test</h2>
<p>You should now be able to test your Flash file (Control -> Test Movie) without getting any errors or warnings.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/7.jpg" alt="First Test" /></div>
<p>Hmm, that doesn't look quite right does it?</p>
<p>What's happening here is we've layered the three color channels on top of each other, but they're not combining and mixing the colors, so we're only seeing the top layer (blue). Let's fix that now.</p>
<hr/>
<h2><span>Step 12:</span> Change the Blend Mode</h2>
<p>To get the color channels to blend properly we need to change their BlendMode to SCREEN. We only want to change the blend mode of the second and third layers though. We'll leave the first (bottom) layer normal and blend the other two layers into it.</p>
<p>Add this code to the <em>for</em> loop in the RGBShift class constructor function:</p>
<pre name="code" class="code javascript:firstline[25]">
if(i>0) {
	// set SCREEN blend mode for the 2nd and 3rd images
	bmp.blendMode = BlendMode.SCREEN;
}
</pre>
<p>This checks to make sure the current image is not the first image (0) and then sets the blendMode property to SCREEN.</p>
<hr/>
<h2><span>Step 13:</span> Test Again</h2>
<p>Test your movie again and you should see something that looks identical to your titleScreen MovieClip.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/8.jpg" alt="Successful Test" /></div>
<p>I know what you're thinking; 'That was a lot of work to recreate the same graphic that was already there.'</p>
<p>But now the graphic is made up of three objects that we can transform individually to create our distortion. So quit your whining and let's continue...</p>
<hr/>
<h2><span>Step 14:</span> Download the Tweener Library</h2>
<p>We're going to use the Tweener Library to do our animation. <a href="http://tweener.googlecode.com/files/tweener_1_33_74_as3.zip">Download it here</a> if you don't already have it.</p>
<p>To use Tweener, place the main 'caurina' folder in the same directory as your Flash file and add this import statement to the top of the RGBShift class:</p>
<pre name="code" class="javascript:firstline[12]">
import caurina.transitions.Tweener;
</pre>
<hr/>
<h2><span>Step 15:</span> Add the <em>randRange</em> File</h2>
<p>I use this <em>randRange</em> function as an easy way to generate random integers within a given range. You could just add this function to the RGBShift class, but I use this function so often that I like to keep it in a separate file, so it's easier to share among different projects.</p>
<p>Create a new Actionscript file named 'randRange.as' in the same folder as your main Flash file. Add this code:</p>
<pre name="code" class="javascript">
package {
	// returns a random number between specified range (inclusive)
	public function randRange(min:int, max:int):int {
	    var randomNum:int = Math.floor(Math.random() * (max - min + 1)) + min;
	    return randomNum;
	}
}
</pre>
<p>As you can see it's just a single function wrapped in a package declaration. We can now use this function as if it were a part of our class.</p>
<p>(For more information on how this function works, check out <a href="http://active.tutsplus.com/tutorials/actionscript/quick-tip-get-a-random-number-within-a-specified-range-using-as3/">Carlos's Quick Tip</a>.)</p>
<hr/>
<h2><span>Step 16:</span> Add the <em>distort()</em> Function</h2>
<p>Here's where the magic happens. Add this function to the RGBShift class:</p>
<pre name="code" class="javascript:firstline[52]">
private function distort(img:Sprite):void {
	Tweener.addTween(img, {
			y: randRange(_centerY-3, _centerY+3),	// randomize y shift
			time:randRange(1,2) /10, 		// randomize time
			alpha: randRange(8,10) /10,		// randomize alpha
			transition:"easeInOutSine",

			onComplete:distort, 			// when finished start the distortion again
			onCompleteParams:[img]
			}
	);
}
</pre>
<p>We're going to run this <em>distort()</em> function on each of our color channels separately to create the distortion effect. </p>
<p>The function accepts a Sprite (one of our color channel containers). It then starts a Tweener animation on the channel using a random Y value (between -3 and 3), and a random length of time (between 1 and 2 seconds). This will make each channel shift up and down by different amounts at different speeds.</p>
<p>Notice I'm using the _centerY variable here again to offset the Y value. We also tween to a random alpha value (between .8 and 1) to make each channel flicker a bit. When the tween finishes we use the onComplete property to call the same <em>distort()</em> function again. Using onCompleteParams we send it the same color channel Sprite. This causes the distort function to loop over and over on each of our color channels.</p>
<p>See, what did I tell you..? Magic!</p>
<p>To kick off this distortion loop we need to call it once on each of our color channel Sprites. Add this line to the end of the <em>for</em> loop in the RGBShift constructor function:</p>
<pre name="code" class="javascript:firstline[46]">
distort(container);  // start the bitmap distortion
</pre>
<hr/>
<h2><span>Step 17:</span> Experiment</h2>
<p>You should now be able to test your movie and see the distortion effect in action.</p>
<p>Personally, I like the subtle Y shift that we've got going here, but you can do a lot of crazy stuff with the distortion now that we've got the channels animating separately.</p>
<p>To experiment with the distortion you can just modify the properties and values in the Tweener call in the <em>distort</em> function. Check the <a href="http://hosted.zeh.com.br/tweener/docs/en-us/">Tweener Documentation</a> for a complete list of tweenable properties.</p>
<p>Here's an example of some severe distortion I created by simply adding a few more properties to the Tweener call:</p>
<div class="tutorial_image">
<object width="550" height="300" data="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/milestone1.swf" type="application/x-shockwave-flash"><param name="src" value="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/milestone1.swf" /></object>
</div>
<p>Check out the <em>distort()</em> function that created the effect:</p>
<pre name="code" class="javascript:firstline[52]">
private function distort(img:Sprite):void {
	Tweener.addTween(img, {
			y: randRange(_centerY-3, _centerY+3), 	// ranomize y shift
			x: randRange(_centerX-10, _centerX+10),
			time:randRange(1,2) /10, 		// randomize time
			scaleX: randRange(9,11)/10,		// randimize x scale

			alpha: randRange(5,10) /10,		// randomize alpha
			transition:"easeInOutSine",

			onComplete:distort, 			// when finished start the distortion again
			onCompleteParams:[img]
			}
	);
}
</pre>
<hr/>
<h2><span>Step 18:</span> Enhance the CRT Look</h2>
<p>You can stop here if you want. The RGB separation and distortion should be working at this point.</p>
<p>To enhance the CRT effect I think we need to add a few more graphical elements. In the next few steps we'll be adding scan lines, a rolling black bar, some static, and a shiny reflection.</p>
<hr/>
<h2><span>Step 19:</span> Add the Scan Lines</h2>
<p>Create a new MovieClip on the stage called 'lines'. Inside the MovieClip draw a 1 pixel horizontal line that spans the entire width of your movie. Set the stroke color to black with 40% alpha.</p>
<p>Now copy and paste this line over and over, moving it down 2 pixels each time, until you have lines covering the entire height of your movie. The effect you want is a 1 pixel line, then a 1 pixel space before the next line.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/9.jpg" alt="Scan Lines" /></div>
<hr/>
<h2><span>Step 20:</span> Add the Rolling Bar</h2>
<p>Now we'll add the rolling black bar. Create a new MovieClip called 'bar'. Inside, draw a solid black rectangle that spans the entire width of your movie. Make it about 40 pixels high. Set the Color Style of the MovieClip to Alpha at 30%.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/10.jpg" alt="Bar MovieClip" /></div>
<hr/>
<h2><span>Step 21:</span> Animate the Rolling Bar</h2>
<p>Create a new MovieClip called 'animatingBar' and place your <em>bar</em> clip inside. Create a short motion tween animation of the bar moving from the top of your movie to the bottom. This animation will loop to give us the rolling bar effect.</p>
<p>Place the animatingBar clip on the stage. Select it and add a blur filter. Unlink the X and Y blur settings and set the Blur Y to 20 and the Blur X to 0.</p>
<p>Set the blend mode to Overlay. This is similar to the Screen blend mode we used earlier, but not exactly the same.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/11.jpg" alt="AnimatingBar Blur Filter" /></div>
<hr/>
<h2><span>Step 22:</span> Create the Static Image</h2>
<p>Create a new Photoshop file the same size as your movie. Fill the background layer with neutral grey (#808080). Choose Filter > Noise > Add Noise...<br />
	Set the filter to 100%, Gaussian, Monochromatic.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/12.jpg" alt="Noise Filter Settings" /></div>
<p>Save the image as 'noise.jpg'. If you don't have Photoshop, you can get my 'noise.jpg' from the Source zip file.</p>
<hr/>
<h2><span>Step 23:</span> Animate the Static</h2>
<p>Import the <em>noise.jpg</em> image into your flash file. Create a new MovieClip called 'noise' and add the image to it. Create a new keyframe on frame 2 (F6) and rotate the image 180 degrees. Create another keyframe on frame 3 and flip the image horizontally (Modify > Transform > Flip Horizontal). Create a fourth keyframe on frame 4 and again rotate the image 180 degrees. We now have a 4 frame animation of flickering static.</p>
<p>You could also generate this noise effect using ActionScript, but that is beyond the scope of this tutorial.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/13.gif" alt="Animating Noise" /></div>
<hr/>
<h2><span>Step 24:</span> Add the Reflection</h2>
<p>Create a new MovieClip on the stage called 'shine'. Inside it draw a large oval that extends halfway above the top of your movie. Select the top portion of the oval and delete it. </p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/14.jpg" alt="Create Shine Oval" /></div>
<p>Change the fill to a linear gradient and set it so it blends from white 20% alpha at the top to white 5% alpha at the bottom. Grab the top of the shape and pull it up a little to give it a slight curve.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/076_rgbShift/Tutorial/15.jpg" alt="Color the Oval" /></div>
<hr/>
<h2><span>Step 25:</span> Fix Element Layering</h2>
<p>If you test your movie now you won't see any of the new graphics we just added because the RGB layers are being added on top of everything. To fix this go into the <em>Main</em> class and change this line:</p>
<pre name="code" class="javascript:firstline[13]">
addChild(rgb);
</pre>
<p>To this:</p>
<pre name="code" class="javascript:firstline[13]">
addChildAt(rgb, 0);
</pre>
<p>That adds the RGBShift object at the lowest level of <a href="http://active.tutsplus.com/tutorials/actionscript/as3-101the-display-list/">the display list</a>, below all the other graphics.</p>
<hr/>
<h2>Conclusion</h2>
<p>This tutorial is meant to be a starting place, not a final solution. Now that you have the RGB channels separated and animating individually there are a lot of different things you can do with this technique. The effect would look really nice if it were combined with the static distortion technique from my <a href="http://active.tutsplus.com/tutorials/effects/create-a-static-distortion-effect-using-the-displacement-map-filter/">earlier tutorial</a>.</p>
<p>As always, post a comment and let me know what you think. Good luck! </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=E6OzkTX_FiE:PV0VDGhq91U:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=E6OzkTX_FiE:PV0VDGhq91U:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=E6OzkTX_FiE:PV0VDGhq91U:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=E6OzkTX_FiE:PV0VDGhq91U:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=E6OzkTX_FiE:PV0VDGhq91U:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=E6OzkTX_FiE:PV0VDGhq91U:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=E6OzkTX_FiE:PV0VDGhq91U:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=E6OzkTX_FiE:PV0VDGhq91U:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=E6OzkTX_FiE:PV0VDGhq91U:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=E6OzkTX_FiE:PV0VDGhq91U:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/E6OzkTX_FiE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/effects/create-a-retro-crt-distortion-effect-using-rgb-shifting/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/tutorials/effects/create-a-retro-crt-distortion-effect-using-rgb-shifting/</feedburner:origLink></item>
		<item>
		<title>Quick Tip: How to use Google Analytics for Tracking in Flash</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/PvWZ4dYEOno/</link>
		<comments>http://active.tutsplus.com/tutorials/seo/quick-tip-how-to-use-google-analytics-for-tracking-in-flash/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 12:00:47 +0000</pubDate>
		<dc:creator>Peter Eeckelaert</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[S.E.O.]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=3331</guid>
		<description><![CDATA[In this Quick Tip I&#8217;ll show you how to examine the way visitors are using your websites, widgets and games. Then we&#8217;ll look at how to improve them based on this info!


Introduction
Building nice looking websites is great; building websites that have a high Return Of Investment is priceless. 

Recently I joined the web team of [...]]]></description>
			<content:encoded><![CDATA[<p>In this Quick Tip I&#8217;ll show you how to examine the way visitors are using your websites, widgets and games. Then we&#8217;ll look at how to improve them based on this info!</p>
<p><span id="more-3331"></span></p>
<hr/>
<h2>Introduction</h2>
<p>Building nice looking websites is great; building websites that have a high Return Of Investment is priceless. </p>
<p>
Recently I joined the web team of a Brussels based communication agency, a team with expert knowledge in the fields of user experience design, content strategies, software development, and interaction design. We spend a lot of time on wireframes, storyboards, and prototypes, which guarantees that the functionality and the content of the websites are optimal before <em>any</em> graphical design takes place. This means our websites have a solid base to be built upon, which results in a higher ROI with less time spent on development.</p>
<p>A huge part of our work is under the hood: Google Analytics inside Flash.</p>
<p>This tool allows us to measure how well our sites are doing against our predefined goals: bounce rate, click paths and even custom measurements like how many people scrolled a certain page. Our specialists analyze all this information and use it to optimize the website. If you&#8217;re not measuring how people are using your site, you can only guess about its successes and failures.</p>
<p>The following setup is a stripped-down version of an image gallery; Google Analytics allowed the client to discover which images triggered the most interest. I&#8217;ve left out the actual gallery building as it is beyond the scope of this tutorial; there are plenty on Activetuts+ already though &#8211; <a href="http://active.tutsplus.com/?s=gallery">just search for &#8220;gallery&#8221;</a>.</p>
<p>We will focus on how to set up Google Analytics to put a smile on your clients&#8217; faces (and probably yours too&#8230;)</p>
<hr/>
<h2>Google Analytics in Action</h2>
<p>Here&#8217;s the simplified image gallery:</p>
<div class="tutorial_image">
<object width="550" height="400" data="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Preview/google_analytics_example.swf" type="application/x-shockwave-flash"><param name="src" value="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Preview/google_analytics_example.swf" /></object>
</div>
<p>As you can see, when an image is clicked, its identity gets sent over to my Google Analytics account. Later on, I can look at all the statistics of which images were clicked, at which times, in which countries, and so on.</p>
<p>(Of course, you&#8217;ll remove all that overlaid information when it&#8217;s live on your own site!)</p>
<hr/>
<h2><span>Step 1:</span> Understand the Benefits</h2>
<p>Imagine yourself working hours, weeks, even months on a website. You successfully deliver the files before the deadline, but a few months later it&#8217;s clear that &#8211; despite being beautiful &#8211; the site is not attracting as many customers as your client expected. Google Analytics helps you to review visitors&#8217; browsing habits and discover which parts of the site could be better highlighted. Beauty is great, but I believe that Return Of Investment should be your main priority.</p>
<p>In another scenario this same tool helps you to understand what area of your website has the most page views, how many times visitors wanted to contact you, or which elements of your portfolio visitors love the most. How many benefits can you think of for your site?</p>
<hr/>
<h2><span>Step 2:</span> Set Up a Google Analytics Account</h2>
<p>If you don&#8217;t have a Google account already, sign up for one <a href="https://www.google.com/accounts/NewAccount">here</a> &#8211; it only takes a few seconds.</p>
<p>Once that&#8217;s done, head to <a href="http://google.com/analytics">http://google.com/analytics</a> and sign up for an Analytics account. There you can give an account name for the websites you want to track.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/1.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<hr/>
<h2><span>Step 3:</span> Inside the Machine</h2>
<p>Head to <a href="https://google.com/accounts/ManageAccount" target="_blank">https://google.com/accounts/ManageAccount</a><br />
and use your mouse skills to click Analytics.</p>
<p>Great, we are now in the Overview page. You should see your Analytics account name; click it and you&#8217;ll find yourself at the website profiles.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/2.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<p>If you haven&#8217;t set up a website to track, simply click &#8216;Add Website Profile&#8217;. Enter your domain name and Country, then click Finish.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/3.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/4.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/5.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<hr/>
<h2><span>Step 4:</span> Retrieve your UA Code and Tracking Status</h2>
<p>The Tracking Status page will automatically appear:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/6.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<p>The most important part is your web property ID. This is a unique number Google Analytics will use to send and store your website&#8217;s traffic. (Copy this UA code for use later in Flash, or write it down.) For this introduction we&#8217;ll simply keep all the options at their defaults.</p>
<p>If you&#8217;re going to embed your SWF on your own webpage, the javascript code must be pasted right before the &lt;/body&gt; tag in the page&#8217;s HTML. This will allow you to keep statistics for the actual page itself, as well as for within the SWF. It&#8217;s worth inserting this code in every page on your site.</p>
<p>All this is great, but you still won&#8217;t be able to pinpoint your visitors&#8217; interaction in great detail, as the HTML is blind to your actual SWF / Flash content.</p>
<hr/>
<h2><span>Step 5:</span> Gathering Wood</h2>
<p>To make sure you can see which parts of your SWF are being used, head to <a href="http://code.google.com/p/gaforflash/" target="_blank">http://code.google.com/p/gaforflash/</a>.</p>
<p>This amazing open source AS3 API has a lot of great features for integrating GA into Flash, but even with our biggest and most complex websites, we&#8217;ve only ever used two functions. (More about these later on.) Make sure you download the latest installment on the right of the page. (Come back any time to read the wiki, issues etc, to learn more about this vast API.)</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/7.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<hr/>
<h2><span>Step 6:</span> Install the Components</h2>
<p>The zip contains a documentation folder with the entire API layout to help you along the way; a library folder (lib) where you&#8217;ll find the two components; and some text files you probably won&#8217;t ever read. At least I didn&#8217;t ;]</p>
<p>To install the components, make sure Flash is closed, then navigate to:</p>
<ul>
<li>Windows users: <em>C:\Program Files\Adobe\Adobe Flash CS X\language\Configuration\Components</em></li>
<li>Mac users: <em>Macintosh HD/Applications/Adobe Flash CS X/Configuration/Components</em></li>
</ul>
<p>At this point you need to create a directory named &#8216;Google&#8217; and copy the files from the \lib\ folder in the zip to it.</p>
<p>Basically the two components give you the same functionality but are developed for two different purposes. The Analytics component is for those who are unfamiliar with AS3. I assume most of you are already using AS3, so we&#8217;ll use the AnalyticsLibrary component.</p>
<hr/>
<h2><span>Step 7:</span> Feeding the Fire</h2>
<p>Inside Flash, open the FLA for the project you&#8217;re working on, click <em>Window > Components</em>, and drag the AnalyticsLibrary component to your library.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/8.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<hr/>
<h2><span>Step 8:</span> Action! (Script)</h2>
<p>Whether you&#8217;re coding on the timeline or using a document class, you&#8217;ll need to do some imports:</p>
<pre name="code" class="javascript">
//import the Analytics classes
import com.google.analytics.AnalyticsTracker;
import com.google.analytics.GATracker;
</pre>
<p>Also, in your code, create a new instance of the AnalyticsTracker:</p>
<pre name="code" class="javascript">
var tracker:AnalyticsTracker = new GATracker( this, "UA-XXXXXX", "AS3", true );
</pre>
<p>The parameters are: stage, UA code, actionscript 3 mode, visual debugger on/off. Leave them all as I&#8217;ve set them, apart from the UA code which you&#8217;ll need to swap for your own. Set the last parameter to <em>false</em> when you are done with your testing phases, as when <em>true</em> it will create an overlay on top of your SWF file like in the example above.</p>
<p>Test this out by adding a Click event listener and handler to one of your movie clips or buttons:</p>
<pre name="code" class="javascript">
myMc.addEventListener (MouseEvent.CLICK,onClick);
</pre>
<pre name="code" class="javascript">
function onClick (event:MouseEvent):void
{
	//make your clients happy.
    //use 'event.target.name' instead of 'event.target'
	//this will display 'myMc' instead of [object myMc], which is obviously a nicer output.
	var mySelection:String = event.target.name;
	tracker.trackPageview ("gallery = " + mySelection);
}
</pre>
<p>Here we&#8217;re using the <em>trackPageView()</em> function. Use this for navigation purposes. You can add a string so your client knows what part is being tracked. In this case we&#8217;re tracking which gallery has been triggered. So copy and paste this code everywhere you want to track your interactions and give an understandable String to the data.</p>
<p>For example, if you have a &#8220;call to action&#8221; button on stage to lure potential new clients, you could write:</p>
<pre name="code" class="javascript">
tracker.trackPageview("Hire me");
</pre>
<p>&#8230;in the Click event handler for that button. Or if you want to track how many times they have read your disclaimer:</p>
<pre name="code" class="javascript">
tracker.trackPageview("Disclaimer");
</pre>
<p>I&#8217;m sure you get the idea.</p>
<hr/>
<h2><span>Step 9:</span> Event Tracking</h2>
<p>Use event tracking if you want to track what video or MP3 event is being played, or when the user pauses it &#8211; things like that. It&#8217;s basically for any action that doesn&#8217;t represent opening a &#8220;page&#8221;.</p>
<p>The code looks like this:</p>
<pre name="code" class="javascript">
trackEvent(category, action, label);
</pre>
<p>For example:</p>
<pre name="code" class="javascript">
tracker.trackEvent("profile videos", "play", "first video: introduction");
</pre>
<p>Additionally you can add a fourth parameter. This can represent any value you like, but it must be an integer (whole number). For example, you might want to pinpoint the exact time when the video was paused.</p>
<p>This is great to see how well your streaming or downloading performs for your visitors (not everyone has top class Internet connections):</p>
<pre name="code" class="javascript">
var currentTime:Date = new Date().time;	//get the current time
//load the video here
var readyToRoll:Date = new Date().time - currentTime;	//get time taken to load the video
tracker.trackEvent("profile videos", "playing the video", "video 1/3: introduction", readyToRoll);
</pre>
<hr/>
<h2><span>Step 10:</span> See the Data in Google Analytics</h2>
<p>Go to <a href="http://google.com/analytics/settings/">http://google.com/analytics/settings/</a> and click your account name. Next to your domain name, click View Report.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/9.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<p>Here you will see a timeline. (Please note: depending on your server response time it can take a while before the data gets stored, but it shouldn&#8217;t take too long.) Select the dates for when you have been testing using the calendar in the top-right:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/10.jpg" alt="google-analytics-for-flash" width="600" height="253" /></div>
<p>Locate the Content Overview; here you can see which events or buttons were triggered:</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/11.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<p>As you can see, as I explained a few steps back, <em>event.target.name</em> displays a &#8220;nice&#8221; name like &#8220;/gallery = gallery 1&#8243;, while <em>event.target</em> returns something like &#8220;[object picture1]&#8220;</p>
<p> Clicking on one of these links &#8211; for example, &#8220;/gallery = gallery2&#8243; &#8211; you will be able to see in-depth information, like what screen resolution your users have, when you choose an option in the drop-down menu.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/072_QTgoogleAnalytics/Tutorial/12.jpg" alt="google-analytics-for-flash" width="600" height="352" /></div>
<p>There&#8217;s a deep and rich information source in nearly every single branch of the Google Analytics module. It&#8217;s nearly impossible to list all of them. Don&#8217;t be afraid; look around and see what data you can provide to your clients and yourself.</p>
<hr/>
<h2><span>Step 11:</span> Eliminate Yourself from the Stats using Filters</h2>
<p>It&#8217;s a good idea to filter out your own behaviour; otherwise, it will give you incorrect data since you will probably test this in great detail.</p>
<p>You can do this by filtering all activity coming from your IP address &#8211; though please note, this will only work if you have a static IP address. There is a lot of documentation in the help files; I can&#8217;t cover it all here. Check out <a href="http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&#038;answer=55481">http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&#038;answer=55481</a></p>
<p>Filters can also be useful for other reasons. Here is some more information: <a href="http://www.google.com/support/googleanalytics/bin/topic.py?hl=en&#038;topic=11091">http://www.google.com/support/googleanalytics/bin/topic.py?hl=en&#038;topic=11091</a></p>
<hr/>
<h2><span>Step 12:</span> The End is the Beginning&#8230;</h2>
<p>In this Quick Tip I&#8217;ve only covered a snowflake on the tip of the iceberg of what you can do with this amazing API. It&#8217;s a quick overview on the two most beneficial functions that we deal with to improve our websites and match our clients&#8217; wishes.</p>
<p>You can also set predefined goals, group users that (for example) use widescreen monitors, base your Analytics on search engine keywords and so on. For your clients, you can send an email with daily, weekly or monthly reports (as xml, PDF, or other formats), or even give them access to your Analytics page. If you&#8217;d like more information, please ask in the comments!</p>
<hr/>
<h2>My Opinions on Search Engine Friendly Flash Websites</h2>
<p>Although it is beneficial to read and trace your visitors&#8217; interactions, this is a long way from using Flash in an SEO-friendly world. I&#8217;ve warmed you up for optimal website design and focusing on Return of Investment, but we&#8217;re not there yet.</p>
<p>A good next step would be to look into the <a href="http://www.gaiaflashframework.com/">Gaia framework</a>, and use its mighty setup to work with swfaddress and deeplinking. This will allow you to track individual pages of your website project and in combination with your newly learned Google Analytics magic, I am sure not only your clients will smile.</p>
<p><strong>Editor&#8217;s Note:</strong> We have some Gaia tutorials lined up, don&#8217;t worry <img src='http://active.tutsplus.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>I&#8217;ve been working for over 10 years in the graphic design world, and never had so much power to know exactly what my clients and visitors want. I often like to call it &#8220;free marketing and research from your desktop&#8221;. (If you are wondering why my own site isn&#8217;t using this technology, well honestly&#8230; I hope to re-launch by mid 2010 *sips coffee*)</p>
<p>I hope this opens new doors for you and boosts your skill set. Good luck and have fun!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=PvWZ4dYEOno:9-1_u1yM1Qw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=PvWZ4dYEOno:9-1_u1yM1Qw:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=PvWZ4dYEOno:9-1_u1yM1Qw:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=PvWZ4dYEOno:9-1_u1yM1Qw:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=PvWZ4dYEOno:9-1_u1yM1Qw:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=PvWZ4dYEOno:9-1_u1yM1Qw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=PvWZ4dYEOno:9-1_u1yM1Qw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=PvWZ4dYEOno:9-1_u1yM1Qw:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=PvWZ4dYEOno:9-1_u1yM1Qw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=PvWZ4dYEOno:9-1_u1yM1Qw:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/PvWZ4dYEOno" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/seo/quick-tip-how-to-use-google-analytics-for-tracking-in-flash/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/tutorials/seo/quick-tip-how-to-use-google-analytics-for-tracking-in-flash/</feedburner:origLink></item>
		<item>
		<title>Create 3D Effects With the Stardust Particle Engine</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/WEL23dWQd1A/</link>
		<comments>http://active.tutsplus.com/tutorials/effects/create-3d-effects-with-the-stardust-particle-engine/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 12:00:51 +0000</pubDate>
		<dc:creator>Allen Chou</dc:creator>
				<category><![CDATA[3D]]></category>
		<category><![CDATA[Effects]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=3323</guid>
		<description><![CDATA[In my previous tutorial Shoot Out Stars with the Stardust Particle Engine, I explained the basic workflow of Stardust. This time, we&#8217;ll take things further and examine a couple of techniques for creating true 3D particle effects!


Introduction

We&#8217;ll begin with a demonstration of how to use the Stardust&#8217;s native 3D engine. Then, I&#8217;ll show you how [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous tutorial <a href="http://active.tutsplus.com/tutorials/effects/shoot-out-stars-with-the-stardust-particle-engine/">Shoot Out Stars with the Stardust Particle Engine</a>, I explained the basic workflow of Stardust. This time, we&#8217;ll take things further and examine a couple of techniques for creating true 3D particle effects!</p>
<p><span id="more-3323"></span></p>
<hr/>
<h2>Introduction</h2>
<p>
We&#8217;ll begin with a demonstration of how to use the <a href="http://code.google.com/p/stardust-particle-engine/">Stardust&#8217;s</a> native 3D engine. Then, I&#8217;ll show you how to get Stardust to work with Papervision3D; we&#8217;ll be creating 3D particle effects with Papervision3D&#8217;s Particles class and DisplayObject3D class.
</p>
<hr/>
<h2>Previously&#8230;</h2>
<p>
We&#8217;re going to pick up where we left off in the <a href="http://active.tutsplus.com/tutorials/effects/shoot-out-stars-with-the-stardust-particle-engine/"/>first tutorial</a>. Last time we created star and circle particles shooting out from a point, growing to a maximum size and then shrinking to nothing, while moving gradually slower over time (called a damping effect). This time, we&#8217;ll do the same thing, but in 3D. Instead of the particles moving out in a circle, they&#8217;ll move out in a sphere.
</p>
<hr/>
<h2><span>Step 1:</span> Create a New Flash Document</h2>
<p>
Just as <a href="http://active.tutsplus.com/tutorials/effects/shoot-out-stars-with-the-stardust-particle-engine/">before</a>, first create a new Flash document with dimensions of 640&#215;400, a frame rate of 60fps, and a dark background (I used a dark blue gradient).
</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/075_stardust3D/Tutorial/1.jpg"/></div>
<hr/>
<h2><span>Step 2:</span> Draw the Particles</h2>
<p>
Draw a star and a white circle, then convert them to symbols, separately. These are the two symbols we are going to use as particles later. Name the star symbol &#8220;Star&#8221; and circle symbol &#8220;Circle&#8221;, exported for ActionScript with the same class names.
</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/075_stardust3D/Tutorial/2.jpg"/></div>
<p>(If you&#8217;re not much of an artist, you can download the source at the top of the page and use my symbols from the library of my FLA.)</p>
<hr/>
<h2><span>Step 3:</span> Create the Pause Button</h2>
<p>
Click <em>Window > Components</em> to bring up the Components Panel, then drag a Button from the User Interface folder onto the stage. Set the label to &#8220;Pause&#8221; and name it &#8220;pause_btn&#8221;. We are going to use this button to pause the 3D particle effects, thereby allowing users to spin the camera around in order to get a better taste of the 3D environment.
</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/075_stardust3D/Tutorial/3.jpg"/></div>
<hr/>
<h2><span>Step 4:</span> Create the Document Class</h2>
<p>
Create a new document class and name it StarParticles3D.
</p>
<pre name="code" class="javascript">
package {
	import flash.display.Sprite;

	public class StarParticles3D extends Sprite {

		public function StarParticles() {

		}
	}
}
</pre>
<p>Not sure how to use a document class? <a href="http://active.tutsplus.com/tutorials/actionscript/quick-tip-how-to-use-a-document-class-in-flash/">Read this Quick Tip.</a></p>
<hr/>
<h2>3D Initializers and Actions</h2>
<p>
The three main packages in Stardust are:
</p>
<ul>
<li>
<em>idv.cjcat.stardust.common</em>: contains general elements for both 2D and 3D particle effects.
</li>
<li>
<em>idv.cjcat.stardust.twoD</em>: contains specific elements for 2D particle effects.
</li>
<li>
<em>idv.cjcat.stardust.threeD</em>: contains specific elements for 3D particle effects.
</li>
</ul>
<p>
In the previous tutorial we used initializers and actions from the common and twoD packages. In this tutorial, we&#8217;ll still be using elements from the common package, but not from the twoD package. Instead, we will use elements from the threeD package.
</p>
<p>The class structure of the threeD package is pretty much the same as in the twoD package, except that the elements have an extra dimension. A 3D element possesses the same name as its 2D counterpart, but its name ends with &#8220;3D&#8221;. For example, the <em>Move3D</em> action in the 3D package updates particle positions in 3D space according to the velocities, just like its 2D counterpart in the 2D package, the <em>Move</em> action.
</p>
<hr/>
<h2><span>Step 5:</span> Extend the Emitter</h2>
<p>
Create a new AS file called <em>StarEmitter.as</em>; inside it, create a new class <em>StarEmitter</em>, which extends the Emitter3D class:
</p>
<pre name="code" class="javascript">
package {
	import idv.cjcat.stardust.threeD.emitters.Emitter3D;	//don't forget to import this!

	public class StarEmitter extends Emitter3D {

		public function StarEmitter(clock:Clock) {
			//pass the clock object to the superclass's constructor
			super(clock);
		}
	}
}
</pre>
<p>Remember the Clock parameter? It&#8217;s used to control the rate of particle creation. We need to include it in the constructor function, so that we can pass a Clock to it later.</p>
<p>
Since we are allowing users to pause the particle effects, we&#8217;re going to pack all the actions into a single CompositeAction object, which is essentially a group of actions. By deactivating this single composite action, we can &#8220;turn off&#8221; all the underlying actions. Declare a variable for a composite action in the emitter class. We&#8217;ll access this variable in the document class, so it needs to be public:
</p>
<pre name="code" class="javascript">
public var pausibleActions:CompositeAction;
</pre>
<hr/>
<h2><span>Step 6:</span> Declare the Particle Constants</h2>
<p>
Declare constants that will be used as particle parameters in the emitter class. We already covered the purpose of these constants in the previous tutorial. Most of the names are self-explanatory. These go inside the class but outside the constructor function. Feel free to come back here later and alter the numbers to see the effects.
</p>
<pre name="code" class="javascript">
private static const LIFE_AVG:Number = 30;
private static const LIFE_VAR:Number = 10;
private static const SCALE_AVG:Number = 1;
private static const SCALE_VAR:Number = 0.4;
private static const GROWING_TIME:Number = 5;
private static const SHRINKING_TIME:Number = 10;
private static const SPEED_AVG:Number = 30;
private static const SPEED_VAR:Number = 10;
private static const OMEGA_AVG:Number = 0;
private static const OMEGA_VAR:Number = 5;
private static const DAMPING:Number = 0.1;
</pre>
<hr/>
<h2><span>Step 7:</span> The Switch Initializer for Particle Display Objects</h2>
<p>
In the previous tutorial I demonstrated how to use the SwitchInitializer to create particles with different display objects. I was using the DisplayObjectClass initializer, which initializes particle appearance with display Objects. That was for 2D particle effects; here we are going to use its 3D counterpart, the DisplayObject3D initializer.</p>
<p>Add the following code to the emitter&#8217;s constructor function:</p>
<pre name="code" class="javascript">
//switch initializers for star and circle particles
var doc1:DisplayObjectClass3D = new DisplayObjectClass3D(Star);
var doc2:DisplayObjectClass3D = new DisplayObjectClass3D(Circle);
var si:SwitchInitializer = new SwitchInitializer([doc1, doc2], [1, 1]);
addInitializer(si);
</pre>
<hr/>
<h2><span>Step 8:</span> Add the Remaining Initializers</h2>
<p>
Same as the previous tutorial; add the other initializers shown below. Note that some of them have similar names to those in the previous tutorial, but end in &#8220;3D&#8221;.
</p>
<ul>
<li>
The Position3D initializer initializes particle positions. Just as its 2D counterpart, the Position initializer, it accepts one constructor parameter, a zone object. However, this time it does not accept a Zone object, which represents a 2D zone; instead, it accepts a Zone3D object, representing a zone in 3D space. The SinglePoint3D class extends the Zone3D class and is the 3D version of the SinglePoint class.
</li>
<li>
The same goes for the Velocity3D class. The SphereShell class is essentially the 3D version of the SectorZone class. Here we set the center of the sphere shell to (0, 0, 0), average radius to SPEED_AVG, and radius variation to SPEED_VAR.
</li>
<li>
The Rotation3D and Omega3D initializers work exactly the same as their 2D counterparts, Rotation and Omega. However, there is one little difference about the constructor parameters: they accept three Random objects instead of one. That is because now, in 3D space, there are three axes of rotation, so they require three random rotation values for these axes. In this example we are creating &#8220;2D billboards&#8221; in 3D space (i.e. flat objects), so only the rotation for the Z axis is apparent; that&#8217;s why the first two parameters, Random objects for the X and Y axes, are assigned with null values.
</li>
</ul>
<p>This code goes in the StarEmitter&#8217;s constructor function:</p>
<pre name="code" class="javascript">
addInitializer(new Life(new UniformRandom(LIFE_AVG, LIFE_VAR)));
addInitializer(new Scale(new UniformRandom(SCALE_AVG, SCALE_VAR)));
addInitializer(new Position3D(new SinglePoint3D()));
addInitializer(new Velocity3D(new SphereShell(0, 0, 0, SPEED_AVG, SPEED_VAR)));
addInitializer(new Rotation3D(null, null, new UniformRandom(0, 180)));
addInitializer(new Omega3D(null, null, new UniformRandom(OMEGA_AVG, OMEGA_VAR)));
</pre>
<hr/>
<h2><span>Step 9:</span> Add the Actions</h2>
<p>
Create a composite action, and add some actions to it. Then add this composite action to the emitter; this will make the particles perform the actions. You&#8217;ve seen these actions in the previous tutorial (some of them in 2D version), so I won&#8217;t explain them all over again. Again, this code goes in the StarEmitter&#8217;s constructor function:
</p>
<pre name="code" class="javascript">
pausibleActions = new CompositeAction();
pausibleActions.addAction(new Age());
pausibleActions.addAction(new DeathLife());
pausibleActions.addAction(new Move3D());
pausibleActions.addAction(new Spin3D());
pausibleActions.addAction(new Damping3D(DAMPING));
pausibleActions.addAction(new ScaleCurve(GROWING_TIME, SHRINKING_TIME));
addAction(pausibleActions);
</pre>
<hr/>
<h2><span>Step 10:</span> Back to The Document Class</h2>
<p>
All right, we&#8217;re done with the emitter. Now it&#8217;s time to build our document class.
</p>
<p>
First, declare constants for the orbiting camera&#8217;s radius, the camera distance from the origin and the emitter&#8217;s rate:
</p>
<pre name="code" class="javascript">
private static const CAMERA_RADIUS:Number = 250;
private static const PARTICLE_RATE:Number = 0.5;
</pre>
<p>(As before, consts go inside the class but outside the constructor function.)</p>
<p>
Then, declare variables for an emitter, a steady clock and a DisplayObjectRenderer3D (in the same place as the consts):
</p>
<pre name="code" class="javascript">
private var emitter:StarEmitter;
private var clock:SteadyClock;
private var renderer:DisplayObjectRenderer3D;
</pre>
<p>
In the constructor, initialize the clock, emitter and renderer. Also, set the initial camera&#8217;s position and direction, making it look at the origin:
</p>
<pre name="code" class="javascript">
//create the clock and emitter
clock = new SteadyClock(PARTICLE_RATE);
emitter = new StarEmitter(clock);	//we can do this because we gave StarEmitter's constructor a clock parameter

//create the renderer and its container sprite
var container:Sprite = new Sprite();
container.x = 320, container.y = 200;
renderer =  new DisplayObjectRenderer3D(container);
renderer.addEmitter(emitter);

//add the container to the stage
addChild(container);
//add the pause button again so that it is on top of the container
addChild(pause_btn);

//set the camera's initial position and direction
renderer.camera.position.set(0, 0, -CAMERA_RADIUS);
renderer.camera.direction.set(0, 0, CAMERA_RADIUS);
</pre>
<hr/>
<h2><span>Step 11:</span> Program the Pause</h2>
<p>
Create a handler function in the document class to handle the click event of the pause button:
</p>
<pre name="code" class="javascript">
private function togglePause(e:MouseEvent):void {
	if (e.target.label == "Pause") {
		e.target.label = "Resume";
		clock.ticksPerCall = 0;		//stop the clock
		emitter.pausibleActions.active = false;	//deactivate the emitter's actions
	} else {
		e.target.label = "Pause";
		clock.ticksPerCall = PARTICLE_RATE;		//restart the clock
		emitter.pausibleActions.active = true;	//reactivate the emitter's actions
	}
}
</pre>
<p>
..then register the listener for the pause button, in the constructor function:
</p>
<pre name="code" class="javascript">
pause_btn.addEventListener(MouseEvent.CLICK, togglePause);
</pre>
<hr/>
<h2><span>Step 12:</span> The Main Loop</h2>
<p>
Create a handler for the ENTER_FRAME event. This is our main loop. It updates the camera&#8217;s position by calling the updateCamera() method (which we will code in a minute) and calls the emitter&#8217;s step() method, which keeps the particle effects running:
</p>
<pre name="code" class="javascript">
private function mainLoop(e:Event):void {
	updateCamera();
	emitter.step();
}
</pre>
<p>
Again, register a listener in the constructor:
</p>
<pre name="code" class="javascript">
addEventListener(Event.ENTER_FRAME, mainLoop);
</pre>
<hr/>
<h2><span>Step 13:</span> Update the Camera&#8217;s Position</h2>
<p>
Now define the updateCamera() method called in the previous step. This is used to move the camera in 3D space depending on the mouse&#8217;s position. (If you&#8217;d like more information on how it works check out <a href="http://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates">this Wikipedia article</a>.)</p>
<p>The magic numbers used to generate theta and phi are just the result of trial and error; feel free to try your own equations.</p>
<pre name="code" class="javascript">
private function updateCamera():void {
	var theta:Number = 0.02 * (mouseX - 320);
	var phi:Number = 0.02 * (mouseY - 200);
	phi = StardustMath.clamp(phi, -StardustMath.HALF_PI, StardustMath.HALF_PI);

	var x:Number = CAMERA_RADIUS * Math.cos(theta) * Math.cos(phi);
	var y:Number = CAMERA_RADIUS * Math.sin(phi);
	var z:Number = CAMERA_RADIUS * Math.sin(theta) * Math.cos(phi);
	renderer.camera.position.set(x, y, z);
	renderer.camera.direction.set(-x, -y, -z);
}
</pre>
<p>Note that I used the StardustMath.clamp() method; this makes sure the phi value is kept between positive and negative half PI.</p>
<hr/>
<h2><span>Milestone:</span> Native Stardust Engine Complete</h2>
<p>
Okay, we&#8217;re done! That&#8217;s all we need to do to get a 3D emitter working with Stardust&#8217;s native 3D engine. Let&#8217;s look at the result. You can click the pause button to pause the particle effect, and move the mouse around to orbit the camera:</p>
<div class="download_wrap">
<div class="big_btn">
		<a href="http://activetuts.s3.cdn.plus.org/tuts/075_stardust3D/Preview/Stardust Native 3D Engine/StarParticles3D.html" rel="external"><span>Demo</span> <small>View It Online</small></a>
	</div>
</div>
<p>If you&#8217;d like to see the full source code, look in the folder called &#8220;01 &#8211; Stardust Native 3D Engine&#8221; in the Source.</p>
<hr/>
<h2>Time for Papervision3D</h2>
<p>
To switch from Stardust&#8217;s native 3D engine to Papervision3D is easy. We&#8217;ll just have to use a different renderer and display object initializer.
</p>
<p>(Never used Papervision3D before? Take a look at <a href="http://active.tutsplus.com/tutorials/3d/journey-to-the-next-dimension-with-pv3d-and-funny-glasses-part-1/">this beginner&#8217;s tutorial</a>.)</p>
<p>
First we&#8217;ll use Papervision3D&#8217;s Particles class. You might not be familiar with this; I&#8217;ll show you how to use the more common DisplayObject3D class later.
</p>
<hr/>
<h2><span>Step 14:</span> Change the Display Object Initializer</h2>
<p>
Change the following code in the emitter class:
</p>
<pre name="code" class="javascript">
var doc1:DisplayObjectClass3D = new DisplayObjectClass3D(Star);
var doc2:DisplayObjectClass3D = new DisplayObjectClass3D(Circle);
</pre>
<p>to this:</p>
<pre name="code" class="javascript">
var mat1:MovieParticleMaterial = new MovieParticleMaterial(new Star());
var mat2:MovieParticleMaterial = new MovieParticleMaterial(new Circle());
var doc1:PV3DParticle = new PV3DParticle([mat1]);
var doc2:PV3DParticle = new PV3DParticle([mat2]);
</pre>
<p>
As you may already know, the MovieParticleMaterial class allows us to use display objects as particles&#8217; appearance in Papervision3D. We create a Star and Circle instance to be used as particle material. The PV3DParticle initializer takes the place of the DisplayObjectClass3D initializer; its constructor accepts an array of parameters, which will all be added to a Particles object.
</p>
<p>
This is all we have to do regarding the emitter. Next we&#8217;ll modify the document class.
</p>
<hr/>
<h2><span>Step 15:</span> Set Up the Papervision3D Environment</h2>
<p>
The target container for our renderer is no longer a Sprite object. Instead, we are going to create particles in a Particles object. We&#8217;ll have to switch the renderer&#8217;s type from DisplayObjectRenderer3D to PV3DParticleRenderer.
</p>
<p>
Declare the following variables for Papervision3D-related objects:
</p>
<pre name="code" class="javascript">
private var scene:SceneObject3D;
private var particles:Particles;
private var camera:Camera3D;
private var origin:DisplayObject3D;
private var renderEngine:BasicRenderEngine;
private var viewport:Viewport3D;
</pre>
<p>
The code in the document class&#8217;s constructor is now:
</p>
<pre name="code" class="javascript">
initPV3D();		//this is new!

clock = new SteadyClock(PARTICLE_RATE);
emitter = new StarEmitter(clock);

renderer =  new PV3DParticleRenderer(particles);	//this is new!
renderer.addEmitter(emitter);

pause_btn.addEventListener(MouseEvent.CLICK, togglePause);
addEventListener(Event.ENTER_FRAME, mainLoop);
</pre>
<p>
The initPV3D() method sets up the Papervision3D Environment. Here&#8217;s the code:
</p>
<pre name="code" class="javascript">
private function initPV3D():void {

	//create the scene
	scene = new SceneObject3D();

	//create the Particles object
	particles = new Particles();

	//create the camera and initialize its position
	camera = new Camera3D();
	camera.position.x = 0;
	camera.position.y = 0;
	camera.position.z = -CAMERA_RADIUS;

	//create a DO3D representing the origin
	origin = new DisplayObject3D();
	origin.x = origin.y = origin.z = 0;

	//point the camera to the origin
	camera.target = origin;

	scene.addChild(origin);
	scene.addChild(particles);

	//create the render engine and viewport
	renderEngine = new BasicRenderEngine();
	viewport = new Viewport3D(640, 400);

	//add the viewport to the stage
	addChild(viewport);
	//add the pause button again so that it is on top of the viewport
	addChild(pause_btn);
}
</pre>
<hr/>
<h2><span>Step 16:</span> The New Main Loop</h2>
<p>
Now Stardust only updates the 3D objects&#8217; properties; Papervision3D&#8217;s render engine is taking over the responsibility of rendering. This is what our new main loop looks like:
</p>
<pre name="code" class="javascript">
private function mainLoop(e:Event):void {
	updateCamera();
	emitter.step();
	renderEngine.renderScene(scene, camera, viewport);	//this is new!
}
</pre>
<hr/>
<h2><span>Step 17:</span> Updating the Camera</h2>
<p>
Now that we are using Papervision3D&#8217;s camera, we&#8217;ll also have to modify the updateCamera() method:
</p>
<pre name="code" class="javascript">
private function updateCamera():void {
	var theta:Number = 0.02 * (mouseX - 320);
	var phi:Number = 0.02 * (mouseY - 200);
	phi = StardustMath.clamp(phi, -StardustMath.HALF_PI, StardustMath.HALF_PI);

	var x:Number = CAMERA_RADIUS * Math.cos(theta) * Math.cos(phi);
	var y:Number = -CAMERA_RADIUS * Math.sin(phi);	//note this is negative now
	var z:Number = CAMERA_RADIUS * Math.sin(theta) * Math.cos(phi);
	camera.x = x;	//we update each of the x, y, z properties of PV3D's camera separately
	camera.y = y;
	camera.z = z;
}
</pre>
<hr/>
<h2><span>Milestone:</span> Papervision3D with Particles Completed</h2>
<p>
Okay, we have successfully switched from Stardust&#8217;s native 3D engine to Papervision3D. Now let&#8217;s check out the result. Note the pixelation effect on the particles. That is because Papervision3D first draws vector objects into bitmaps before using them as particle materials.
</p>
<div class="download_wrap">
<div class="big_btn">
		<a href="http://activetuts.s3.amazonaws.com/tuts/075_stardust3D/Preview/Papervision3D Particles/StarParticles3D.html" rel="external"><span>Demo</span> <small>View It Online</small></a>
	</div>
</div>
<p>You can find all the source code for this in the &#8220;02 &#8211; Papervision3D Particles&#8221; folder.</p>
<hr/>
<h2>Papervision3D&#8217;s DisplayObject3D Class</h2>
<p>
So far, we have been working with &#8220;2D billboards&#8221; &#8211; flat objects, like paper. It&#8217;s possible to create &#8220;real&#8221; 3D particle objects, like Papervision3D&#8217;s DisplayObject3D objects. We&#8217;re just going to have to use another initializer. Now let&#8217;s get down to the final part of this tutorial. We will create red and blue cube particles.
</p>
<hr/>
<h2><span>Step 18:</span> Change the Display Object Initializer, Again</h2>
<p>
We&#8217;re going to change the initializer concerning the particle appearance for the last time.
</p>
<p>
Before that, declare a LightObject3D variable in the emitter class. We are going to use the FlatShadeMaterial for the DisplayObject3D objects, which require a light source. Also, declare the following constants &#8211; we&#8217;ll use these as parameters for the FlastShadeMaterial, and for determining the cubes&#8217; sizes:
</p>
<pre name="code" class="javascript">
public var light:LightObject3D;

private static const LIGHT_COLOR_1:uint = 0xCC3300;
private static const LIGHT_COLOR_2:uint = 0x006699;
private static const AMBIENT_COLOR_1:uint = 0x881100;
private static const AMBIENT_COLOR_2:uint = 0x002244;
private static const CUBE_SIZE:Number = 15;
</pre>
<p>
Now change the following code in the emitter class:
</p>
<pre name="code" class="javascript">
var mat1:MovieParticleMaterial = new MovieParticleMaterial(new Star());
var mat2:MovieParticleMaterial = new MovieParticleMaterial(new Circle());
var doc1:PV3DParticle = new PV3DParticle([mat1]);
var doc2:PV3DParticle = new PV3DParticle([mat2]);
</pre>
<p>to this:</p>
<pre name="code" class="javascript">
light = new LightObject3D();
var mat1:FlatShadeMaterial = new FlatShadeMaterial(light, LIGHT_COLOR_1, AMBIENT_COLOR_1);
var mat2:FlatShadeMaterial = new FlatShadeMaterial(light, LIGHT_COLOR_2, AMBIENT_COLOR_2);
var matList1:MaterialsList = new MaterialsList({all:mat1});
var matList2:MaterialsList = new MaterialsList({all:mat2});
var params1:Array = [matList1, CUBE_SIZE, CUBE_SIZE, CUBE_SIZE];
var params2:Array = [matList2, CUBE_SIZE, CUBE_SIZE, CUBE_SIZE];
var doc1:PV3DDisplayObject3DClass = new PV3DDisplayObject3DClass(Cube, params1);
var doc2:PV3DDisplayObject3DClass = new PV3DDisplayObject3DClass(Cube, params2);
</pre>
<p>
The new particle appearance will be initialized as red and blue 3D cubes. The first constructor parameter for the PV3DDisplayObject3DClass initializer is the class we wish to instantiate for the particles (so here, it is the Cube class) and the second parameter is an array of constructor parameters for this Cube class.
</p>
<hr/>
<h2><span>Step 19:</span> The Three Axes of Rotation</h2>
<p>
Previously, because we were working with &#8220;2D billboards&#8221;, only the rotation about the Z axis mattered. Now that we are working with true 3D objects, we need to pass three Random object references to the Rotation3D and Omega3D constructors, one for each axis.
</p>
<p>
Change the following code in the emitter class:
</p>
<pre name="code" class="javascript">
addInitializer(new Rotation3D(null, null, new UniformRandom(0, 180)));
addInitializer(new Omega3D(null, null, new UniformRandom(OMEGA_AVG, OMEGA_VAR)));
</pre>
<p>
to this:
</p>
<pre name="code" class="javascript">
var rotationRandom:UniformRandom = new UniformRandom(0, 180);
var omegaRandom:UniformRandom = new UniformRandom(OMEGA_AVG, OMEGA_VAR);
addInitializer(new Rotation3D(rotationRandom, rotationRandom, rotationRandom));
addInitializer(new Omega3D(omegaRandom, omegaRandom, omegaRandom));
</pre>
<hr/>
<h2><span>Step 20:</span> Modify the Document Class</h2>
<p>
This time, instead of using a Particles object as our particle container, we&#8217;re using a DisplayObject3D as the container. Declare a variable for this container in the document class:
</p>
<pre name="code" class="javascript">
private var container:DisplayObject3D;
</pre>
<p>
Also, we&#8217;ll need another type of renderer for creating particles in the new container. Change the renderer&#8217;s type from PV3DParticleRenderer to PV3DDisplayObject3DRenderer. The code in the document class&#8217;s constructor should now look like this:
</p>
<pre name="code" class="javascript">
initPV3D();

clock = new SteadyClock(PARTICLE_RATE);
emitter = new StarEmitter(clock);

renderer =  new PV3DDisplayObject3DRenderer(container);	 //this has changed!
renderer.addEmitter(emitter);

pause_btn.addEventListener(MouseEvent.CLICK, togglePause);
addEventListener(Event.ENTER_FRAME, mainLoop);
</pre>
<hr/>
<h2><span>Step 21:</span> Modify the initPV3D() Method</h2>
<p>
In the initPV3D() function, we now need to initialize the container variable and add it to the scene. Add these two lines to the end of that function:
</p>
<pre name="code" class="javascript">
container = new DisplayObject3D();
scene.addChild(container);
</pre>
<hr/>
<h2><span>Step 22:</span> Modify the updateCamera() Method</h2>
<p>
In the updateCamera() method, we wish to make the light follow the camera, so we&#8217;ll have an illusion that the light always &#8220;shoots&#8221; out from our eyes. Change the following code:
</p>
<pre name="code" class="javascript">
camera.x = x;
camera.y = y;
camera.z = z;
</pre>
<p>to this:</p>
<pre name="code" class="javascript">
emitter.light.x = camera.x = x;
emitter.light.y = camera.y = y;
emitter.light.z = camera.z = z;
</pre>
<p>Now the light source is always at the same point as the camera.</p>
<hr/>
<h2><span>Milestone:</span> Papervision3D with DisplayObject3D Completed</h2>
<p>
Yep, we&#8217;re finally done with this tutorial. No more coding. Let&#8217;s take a look at our final result, with fancy red and blue 3D cubes!
</p>
<div class="download_wrap">
<div class="big_btn">
		<a href="http://activetuts.s3.cdn.plus.org/tuts/075_stardust3D/Preview/Papervision3D DisplayObject3D/StarParticles3D.html" rel="external"><span>Demo</span> <small>View It Online</small></a>
	</div>
</div>
<p>The source code for this can be found in the &#8220;Papervision3D DisplayObject3D&#8221; folder.</p>
<hr/>
<h2>Conclusion</h2>
<p>
The workflow for creating 3D particle effects with Stardust is pretty much the same as that for 2D effects. You just choose a different set of initializers, actions, and renderers. Stardust also supports other 3D engines, including <a href="http://code.google.com/p/zedbox/">ZedBox</a> and <a href="http://code.google.com/p/nd3d/">ND3D</a>. The usage is almost the same. You&#8217;ll just have to use a different set of initializers and renderers. You may even extend the Initializer, Action, and Renderer classes to work with whichever 3D engines you like!
</p>
<p>Now you&#8217;ve got the basics, why not go back to the consts created in Step 6 and play with them to see the effects?</p>
<p>
I hope this tutorial helps you understand Stardust more and makes you more familiar and comfortable with Stardust&#8217;s workflow. Thanks for reading!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=WEL23dWQd1A:jx2FopOyPgc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=WEL23dWQd1A:jx2FopOyPgc:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=WEL23dWQd1A:jx2FopOyPgc:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=WEL23dWQd1A:jx2FopOyPgc:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=WEL23dWQd1A:jx2FopOyPgc:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=WEL23dWQd1A:jx2FopOyPgc:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=WEL23dWQd1A:jx2FopOyPgc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=WEL23dWQd1A:jx2FopOyPgc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=WEL23dWQd1A:jx2FopOyPgc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=WEL23dWQd1A:jx2FopOyPgc:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/WEL23dWQd1A" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/effects/create-3d-effects-with-the-stardust-particle-engine/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/tutorials/effects/create-3d-effects-with-the-stardust-particle-engine/</feedburner:origLink></item>
		<item>
		<title>Redesign and Other Tuts News</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/vaUaRYXgEa4/</link>
		<comments>http://active.tutsplus.com/articles/news/redesign-and-other-tuts-news/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 07:13:02 +0000</pubDate>
		<dc:creator>Collis</dc:creator>
				<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=3353</guid>
		<description><![CDATA[<img src='http://psd.tutsplus.com/wp-content/uploads/2010/03/200.jpg'>]]></description>
			<content:encoded><![CDATA[<p>Over the last three days we&#8217;ve been steadily rolling out a new Tuts+ theme across all 8 sites. The new design is a refinement more than a big change, with lots of little improvements in usability and more suited to big screens. Read on to learn more about the redesign and lots of news about Plus!</p>
<p><span id="more-3353"></span></p>
<div style="text-align:center"><img src="http://psd.tutsplus.com/wp-content/uploads/2010/03/laptop.jpg"></div>
<hr />
<h2><span>1</span> The Plus Project</h2>
<p>As you may know we have some pretty big plans for these Tuts+ sites. While today they are humble little tutorial blogs, we&#8217;ve thought for some time that it would be cool to build an entire platform for education. We&#8217;re going to call that platform Plus. You&#8217;ll know Plus content as our premium content, but no longer.<br />
Our premium content is now &#8216;Premium&#8217; (go figure!) and Plus is the brand for the educational platform we&#8217;re building, which, just like Psdtuts+, will be completely free for the most part.</p>
<p>With Tuts+ well established now, we&#8217;ve finally begun work on the project! We&#8217;ve acquired the domain Plus.org which will be the home of the new platform (yay for our first four letter domain!) We&#8217;ve also brought over our resident code genius Ryan Allen (who built our <a href="http://activeden.net">ActiveDen</a> platform all by himself back in 2006) to team up with Tuts+ developer extraordinaire Fred Wu and kick ass front-end guru Derek Herman. And Skellie and I have been busy spec&#8217;ing out the plans for the new site, and it&#8217;s pretty, damn cool if I do say so myself!</p>
<p>Right now the Tuts+ sites are fairly passive, but we&#8217;d like to get the whole community involved in writing, teaching, answering questions and generally learning. The new Plus.org platform promises to incorporate all that plus some nifty ideas we&#8217;ve taken from gaming to come together into a social education platform. </p>
<p>It&#8217;s going to take a long time and we&#8217;re going to roll it all out in pieces over the next 2 years. We&#8217;re super excited about it all, and I hope I&#8217;ll have more updates in the coming months!</p>
<hr />
<h2><span>2</span> Creative Sessions and Mobiletuts+ </h2>
<p>While Plus.org will take a long time, we do have some new goodies coming much sooner including Creative Sessions which is being built now, and also Mobiletuts+ which will be all about mobile development!</p>
<hr />
<h2><span>3</span> Server Update</h2>
<p>About a week and a half ago we had some major problems with our servers. I&#8217;m happy to say that we&#8217;ve now completely resolved these issues by moving hosts and reengineering our hosting setup completely from scratch. The new setup is much quicker and has a much greater capacity for growth, so fingers crossed, that will be the last server outage for a long time to come!</p>
<hr />
<h2><span>4</span> The Redesign</h2>
<p>The new theme has a few neat features you may want to check out including:</p>
<ul>
<li><strong>Basix!</strong><br />While Tuts+ has always been known for intermediate to advanced level content, we&#8217;ve been thinking it&#8217;d be good to separate out tutorials and articles better suited to people just getting started. So we&#8217;ve created the Basix tag for quick browsing. You&#8217;ll find it in the top menu, and expect to see more Basix content soon as we beef up our library of novice-friendly content.
</li>
<li><strong>Easy access to Videos, Tips and Premium Posts</strong><br />We&#8217;ve also started tagging videos, tips and Premium membership posts so that along with Basix content you can quickly find what you&#8217;re after. We&#8217;re generally going to be working to clean up our category/tagging across the network in the coming months to get it more standardized.
</li>
<li><strong>Tutorial Details on Posts</strong><br />We&#8217;re also going to start standardizing all tutorials to have a &quot;Tutorial Details&quot; section at the top with difficulty and other pertinent details. Eventually we&#8217;ll get all the archives updated &#8230; but with over 2000 tutorials, that will take a while!
</li>
<li><strong>Bigger, more readable content area</strong><br />We&#8217;ve expanded the site to be optimized for bigger 1280px wide screens, with a bit of JavaScript to resize for smaller resolutions. This has given us the space to clean up the content area to be a bit bigger and more readable generally.
</li>
<li><strong>Latest Creattica content for inspiration</strong><br />We&#8217;ve also started porting over the latest Creattica content into our sidebars. There&#8217;s actually a redesign of Creattica coming in the next few weeks and we&#8217;ll be expanding the gallery to cover even more types of inspiration. The new sidebar widget will give even more exposure to those talented creatives on Creattica!
</li>
<li><strong>General UI Improvements</strong><br />Most of the improvements on the new design are small, subtle improvements such as a reduction in the number of clicks needed to browse categories, a clearer search field, faster loading pages and generally cleaner, more optimized code.</li>
</ul>
<p>One change that we have also made is to remove the community link feed. Over the years this was a great way to get exposure to community links, but unfortunately was also home to a lot of spam. So with this iteration we&#8217;ve left it behind. </p>
<p>Also at the moment sites with Flickr groups don&#8217;t have it showing, but don&#8217;t worry that&#8217;ll be back. There&#8217;s just a problem with our Flickr plugin at the moment!!</p>
<p>There are still some more tweaks to do to the new design and a lot of post formatting to do to get our archives matching up with the new theme. But for all intents and purposes the new theme is now alive and well! Enjoy!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=vaUaRYXgEa4:y3W-JOcCyOs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=vaUaRYXgEa4:y3W-JOcCyOs:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=vaUaRYXgEa4:y3W-JOcCyOs:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=vaUaRYXgEa4:y3W-JOcCyOs:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=vaUaRYXgEa4:y3W-JOcCyOs:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=vaUaRYXgEa4:y3W-JOcCyOs:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=vaUaRYXgEa4:y3W-JOcCyOs:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=vaUaRYXgEa4:y3W-JOcCyOs:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=vaUaRYXgEa4:y3W-JOcCyOs:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=vaUaRYXgEa4:y3W-JOcCyOs:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/vaUaRYXgEa4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/articles/news/redesign-and-other-tuts-news/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/articles/news/redesign-and-other-tuts-news/</feedburner:origLink></item>
		<item>
		<title>Quick Tip: FireWorks to Flash in About Ten Seconds</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/c7J0cVu4PnM/</link>
		<comments>http://active.tutsplus.com/tutorials/design/quick-tip-fireworks-to-flash-in-about-ten-seconds/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 12:00:51 +0000</pubDate>
		<dc:creator>Tom Green</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Videos]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=3187</guid>
		<description><![CDATA[<img src="http://activetuts.s3.cdn.plus.org/tuts/068_QTfireworksToFlash/preview.jpg" alt="Quick Tip: FireWorks to Flash in About Ten Seconds">]]></description>
			<content:encoded><![CDATA[<p>Sometimes, Flash just isn&#8217;t the right tool for the job at hand. It&#8217;s not great at creating textured buttons, for example. Luckily for us Adobe users, Fireworks is &#8211; and we can drag an object from Fireworks to Flash in about ten seconds.</p>
<p>This Quick Tip will show you how.</p>
<p><span id="more-3187"></span></p>
<div class="tutorial_image">
<embed src="http://blip.tv/play/haIJgcf5BAA" type="application/x-shockwave-flash" width="600" height="469" allowscriptaccess="always" allowfullscreen="true"></embed></p>
<p>Don&#8217;t like ads? <a href="http://blip.tv/file/get/Activetuts-QuickTipFireWorksToFlashInAboutTenSeconds907.flv" target="_blank">Download the screencast</a>.</p>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=c7J0cVu4PnM:AWE_3EwOyUE:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=c7J0cVu4PnM:AWE_3EwOyUE:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=c7J0cVu4PnM:AWE_3EwOyUE:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=c7J0cVu4PnM:AWE_3EwOyUE:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=c7J0cVu4PnM:AWE_3EwOyUE:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=c7J0cVu4PnM:AWE_3EwOyUE:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=c7J0cVu4PnM:AWE_3EwOyUE:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=c7J0cVu4PnM:AWE_3EwOyUE:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=c7J0cVu4PnM:AWE_3EwOyUE:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=c7J0cVu4PnM:AWE_3EwOyUE:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/c7J0cVu4PnM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/design/quick-tip-fireworks-to-flash-in-about-ten-seconds/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
<enclosure url="http://blip.tv/file/get/Activetuts-QuickTipFireWorksToFlashInAboutTenSeconds907.flv" length="12270112" type="video/x-flv" />
		<feedburner:origLink>http://active.tutsplus.com/tutorials/design/quick-tip-fireworks-to-flash-in-about-ten-seconds/</feedburner:origLink></item>
		<item>
		<title>Getting to Grips With Alpha Channel Video – Basix</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/3ER7BXaQ_6M/</link>
		<comments>http://active.tutsplus.com/tutorials/screencasts/getting-to-grips-with-alpha-channel-video/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 12:00:54 +0000</pubDate>
		<dc:creator>Tom Green</dc:creator>
				<category><![CDATA[Screencasts]]></category>
		<category><![CDATA[Basix]]></category>
		<category><![CDATA[Videos]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=2790</guid>
		<description><![CDATA[The creative uses for alpha channel video aren&#8217;t limited to your local weatherman. In this Basix installment I&#8217;m going to show you how to pull a key in After Effects CS4, how to create an alpha channel video in the Adobe Media encoder, how to use that video in Flash and then we&#8217;ll wind up [...]]]></description>
			<content:encoded><![CDATA[<p>The creative uses for alpha channel video aren&#8217;t limited to your local weatherman. In this <strong>Basix</strong> installment I&#8217;m going to show you how to pull a key in After Effects CS4, how to create an alpha channel video in the Adobe Media encoder, how to use that video in Flash and then we&#8217;ll wind up the lesson looking at ways to creatively use alpha channel video in Flash.</p>
<p>Ready? Let&#8217;s get started..</p>
<p><span id="more-2790"></span></p>
<hr/>
<h2><span>Section 1:</span> Introduction </h2>
<div class="tutorial_image">
<embed src="http://blip.tv/play/haIJgcf7QQA" type="application/x-shockwave-flash" width="600" height="469" allowscriptaccess="always" allowfullscreen="true"></embed></p>
<p>Don&#8217;t like ads? <a href="http://blip.tv/file/get/Activetuts-AlphaVideoPart1727.flv" target="_blank">Download the screencast</a>.</p>
</div>
<hr/>
<h2><span>Section 2:</span> Keying </h2>
<div class="tutorial_image">
<embed src="http://blip.tv/play/haIJgcqXHAA" type="application/x-shockwave-flash" width="600" height="469" allowscriptaccess="always" allowfullscreen="true"></embed></p>
<p>Don&#8217;t like ads? <a href="http://blip.tv/file/get/Activetuts-AlphaVideoPart2840.flv" target="_blank">Download the screencast</a>.</p>
</div>
<hr/>
<h2><span>Section 3:</span> Encode</h2>
<div class="tutorial_image">
<embed src="http://blip.tv/play/haIJgcqXRwA" type="application/x-shockwave-flash" width="600" height="469" allowscriptaccess="always" allowfullscreen="true"></embed></p>
<p>Don&#8217;t like ads? <a href="http://blip.tv/file/get/Activetuts-AlphaVideoPart3710.flv" target="_blank">Download the screencast</a>.</p>
</div>
<hr/>
<h2><span>Section Four:</span> Play Alpha Video</h2>
<div class="tutorial_image">
<embed src="http://blip.tv/play/haIJgcqXZAA" type="application/x-shockwave-flash" width="600" height="469" allowscriptaccess="always" allowfullscreen="true"></embed></p>
<p>Don&#8217;t like ads? <a href="http://blip.tv/file/get/Activetuts-AlphaVideoPart4667.flv" target="_blank">Download the screencast</a>.</p>
</div>
<hr/>
<h2><span>Section 5:</span> Effects </h2>
<div class="tutorial_image">
<embed src="http://blip.tv/play/haIJgcqYBgA" type="application/x-shockwave-flash" width="600" height="469" allowscriptaccess="always" allowfullscreen="true"></embed></p>
<p>Don&#8217;t like ads? <a href="http://blip.tv/file/get/Activetuts-AlphaVideoPart5749.flv" target="_blank">Download the screencast</a>.</p>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=3ER7BXaQ_6M:6QKL5GtetEA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=3ER7BXaQ_6M:6QKL5GtetEA:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=3ER7BXaQ_6M:6QKL5GtetEA:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=3ER7BXaQ_6M:6QKL5GtetEA:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=3ER7BXaQ_6M:6QKL5GtetEA:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=3ER7BXaQ_6M:6QKL5GtetEA:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=3ER7BXaQ_6M:6QKL5GtetEA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=3ER7BXaQ_6M:6QKL5GtetEA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=3ER7BXaQ_6M:6QKL5GtetEA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=3ER7BXaQ_6M:6QKL5GtetEA:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/3ER7BXaQ_6M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/screencasts/getting-to-grips-with-alpha-channel-video/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
<enclosure url="http://blip.tv/file/get/Activetuts-AlphaVideoPart3710.flv" length="15628595" type="video/x-flv" />
<enclosure url="http://blip.tv/file/get/Activetuts-AlphaVideoPart2840.flv" length="8933482" type="video/x-flv" />
<enclosure url="http://blip.tv/file/get/Activetuts-AlphaVideoPart1727.flv" length="12188437" type="video/x-flv" />
<enclosure url="http://blip.tv/file/get/Activetuts-AlphaVideoPart4667.flv" length="17933879" type="video/x-flv" />
<enclosure url="http://blip.tv/file/get/Activetuts-AlphaVideoPart5749.flv" length="18689357" type="video/x-flv" />
		<feedburner:origLink>http://active.tutsplus.com/tutorials/screencasts/getting-to-grips-with-alpha-channel-video/</feedburner:origLink></item>
		<item>
		<title>Quick Tip: How to Use a Document Class in Flash</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/HWTL7BaqBgs/</link>
		<comments>http://active.tutsplus.com/tutorials/actionscript/quick-tip-how-to-use-a-document-class-in-flash/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 12:00:34 +0000</pubDate>
		<dc:creator>Michael Williams</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Basix]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=3233</guid>
		<description><![CDATA[<img src="http://activetuts.s3.cdn.plus.org/tuts/071_QTdocClass/preview.jpg" alt="Quick Tip: How to Use a Document Class in Flash">]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re making some changes at Activetuts+. From now on, our tutorials will be using class-based code, instead of timeline code, wherever possible. This Quick Tip explains what you&#8217;ll need to know.</p>
<p><span id="more-3233"></span></p>
<hr />
<h2>Why Use Class Files?</h2>
<p>I&#8217;ll admit it &#8211; sometimes, coding entirely on the timeline is useful. It&#8217;s a quick way to test out an effect, and the easiest way to sync actions to specific frames of an animation.</p>
<p>But for any project that relies more on code than on animation, there are serious disadvantages. All your ActionScript is trapped inside the FLA file; you can&#8217;t split the programming between different developers, you have to copy and paste code if you want to re-use it, and you&#8217;re forced to use Flash&#8217;s Actions Panel.</p>
<p>Using class files sets your code free. And it&#8217;s really no harder than coding on the timeline; it just involves a little more setup. I&#8217;ll walk you through creating a Flash project that uses classes, then break down a class file in detail.</p>
<p>(Part of the reason we&#8217;re switching to classes is to make it easier for AS3 developers that don&#8217;t use Flash itself to follow our tutorials. If you&#8217;re one of them, I expect you&#8217;re used to dealing with classes already, but you can always read this Quick Tip as a refresher &#8211; just ignore the bits about Flash!)</p>
<hr />
<h2><span>Step 1:</span> Create a FLA</h2>
<p>I&#8217;m sure you already know how to do this. Open Flash and click <em>File > New &#8230; Flash File (ActionScript 3.0)</em>. Save it wherever you like. I&#8217;ve called mine <em>Example.fla</em>, but it doesn&#8217;t matter what name you choose.</p>
<hr />
<h2><span>Step 2:</span> Create an ActionScript File</h2>
<p>Click <em>File > New &#8230; ActionScript File</em>. Save this as <em>Main.as</em> in the same folder as your FLA.</p>
<p>This file is where we&#8217;re going to put the code that powers the FLA itself, but how will Flash know how to find it?</p>
<hr />
<h2><span>Step 3:</span> Link the FLA to the AS File</h2>
<p>You may have dozens of AS files in the same folder as the FLA, so Flash won&#8217;t want to guess which one to use. We&#8217;ll have to tell it.</p>
<p>Switch to the Selection tool (Shortcut: V), then make sure you have nothing selected (hit Ctrl-Shift-A). Open the Properties panel (<em>Window > Properties).</em></p>
<p>If you&#8217;re using Flash CS3, it&#8217;ll look like this:</p>
<div class="tutorial_image"><image src="http://activetuts.s3.cdn.plus.org/tuts/071_QTdocClass/-1.jpg" alt="Flash CS3 Properties Panel" /></div>
<p>Enter <em>Main</em> in the box labeled &#8220;Document class&#8221; &#8211; that&#8217;s to match the name of your ActionScript file, minus the &#8220;.as&#8221; file extension..</p>
<p>If you&#8217;re using Flash CS4, it&#8217;ll look like this:</p>
<div class="tutorial_image"><image src="http://activetuts.s3.cdn.plus.org/tuts/071_QTdocClass/-2.jpg" alt="Flash CS4 Properties Panel" /></div>
<p>In this case, you&#8217;ll need to enter <em>Main</em> in the box labeled &#8220;Class&#8221;. For some reason, Adobe dropped the &#8220;Document&#8221; bit.</p>
<hr />
<h2><span>Step 4:</span> (Optional) Reorganize your Folder Structure</h2>
<p>You don&#8217;t have to keep all your files in the same directory. Check out <a href="http://active.tutsplus.com/tutorials/screencasts/quick-tip-how-to-organize-your-flash-project-files/">this Quick Tip screencast</a> if you&#8217;d like to know how to move things around.</p>
<hr />
<h2><span>Step 5:</span> Write your Document Class</h2>
<p>Open your Main.as file and paste the following code:</p>
<pre name="code" class="javascript">
package
{
	import flash.display.MovieClip;
	public class Main extends MovieClip
	{
		public function Main()
		{

		}
	}
}
</pre>
<p>This is a basic empty document class. It&#8217;s the smallest amount of code we can write that will actually run. Let me break it down:</p>
<div class="tutorial_image"><image src="http://activetuts.s3.cdn.plus.org/tuts/071_QTdocClass/3.jpg" alt="The package keyword tells Flash that all of the code between its curly braces is part of a single group." /></div>
<p>The package keyword tells Flash that all of the code between its curly braces is part of a single group.</p>
<div class="tutorial_image"><image src="http://activetuts.s3.cdn.plus.org/tuts/071_QTdocClass/4.jpg" alt="The class keyword groups functions and variables together." /></div>
<p>Writing <em>class Main</em> also groups code together, but in a different way. Classes contain functions and variables; packages contain classes and import statements.</p>
<p><strong>Note:</strong> you have to give your class the same name as the AS file: <em>Main</em>.</p>
<p>What about <em>public</em>? Well, that just means that other classes in your code will be able to see this class.</p>
<div class="tutorial_image"><image src="http://activetuts.s3.cdn.plus.org/tuts/071_QTdocClass/5.jpg" alt="We want our class to extend the functionality of a regular MovieClip - hence, 'class Main extends MovieClip'." /></div>
<p>This class <em>Main</em> is going to power our FLA. By default, our FLA is a movie clip (it has a timeline).</p>
<p>We want <em>Main</em> to be able to do everything that a movie clip can do, plus more based on the code that we write. In other words, we want to <em>extend</em> the functionality of a regular <em>MovieClip</em>.</p>
<p>(Sometimes, we might not need to do any animation on the stage&#8217;s main timeline; in this case, we don&#8217;t need to extend MovieClip, and we can just extend Sprite instead. MovieClip itself extends Sprite, but adds extra features for animation, like the <em>nextFrame()</em> function. So if you&#8217;re not sure whether you should extend MovieClip or Sprite, go for MovieClip &#8212; it&#8217;s safer!)</p>
<div class="tutorial_image"><image src="http://activetuts.s3.cdn.plus.org/tuts/071_QTdocClass/6.jpg" alt="The 'import' line tells Flash where to find the actual MovieClip so that we can extend it." /></div>
<p>MovieClip is itself a class.</p>
<p>Flash doesn&#8217;t automatically keep track of where all its class files are stored; in order for our <em>extends MovieClip</em> code to work, we need to tell Flash where to find the MovieClip class. That&#8217;s what the <em>import</em> line does.</p>
<p><em>Import statements always go inside the package and outside the class, at the top.</em></p>
<div class="tutorial_image"><image src="http://activetuts.s3.cdn.plus.org/tuts/071_QTdocClass/7.jpg" alt="Every class contains a function with the same name as the class. The code inside it is run when an object of this type of class is created - in our case, when the SWF is loaded." /></div>
<p>Every class contains a function with the same name as the class. It&#8217;s called the <em>constructor</em> function.</p>
<p>All the code inside this function is run when an object of this type of class is created &#8211; in our case, code between these curly braces will be run when the SWF is loaded.</p>
<p>Don&#8217;t worry if you feel you don&#8217;t quite grasp all of this yet. Once you start actually using classes and writing your own, it&#8217;ll all snap into place.</p>
<hr />
<h2><span>Step 6:</span> Make it <em>do</em> Something</h2>
<p>As I said in Step 5, the constructor function contains the very first code to be run when your SWF is loaded. So let&#8217;s put something in there to make sure everything&#8217;s working:</p>
<pre name="code" class="javascript">
package
{
	import flash.display.MovieClip;
	public class Main extends MovieClip
	{
		public function Main()
		{
			trace( "Yep, it's working" );
		}
	}
}
</pre>
<p>Line 8 is the only new one there. Test your SWF in the usual way (<em>Control > Test Movie</em>). If all&#8217;s well, you should see &#8220;Yep, it&#8217;s working&#8221; pop up in the Output panel. If not&#8230;</p>
<ul>
<li>Have you saved the change you made to Main.as?</li>
<li>Is your FLA&#8217;s Document Class set to <em>Main</em>?</li>
<li>Are you definitely testing the Example.fla movie?</li>
</ul>
<p>If none of these questions help, please post a comment.</p>
<hr />
<h2><span>Step 7:</span> Try Something a Little More Complex</h2>
<p>Try replacing your Main.as code with this:</p>
<pre name="code" class="javascript">
package
{
	import flash.display.MovieClip;
	public class Main extends MovieClip
	{
		public function Main()
		{
			var greeting:String = "Hello";
			trace( greeting );
		}
	}
}
</pre>
<p>Simple, right? We&#8217;ve just created a new String variable inside the constructor function. Now let&#8217;s add a new function:</p>
<pre name="code" class="javascript">
package
{
	import flash.display.MovieClip;
	public class Main extends MovieClip
	{
		public function Main()
		{
			var greeting:String = "Hello";
			changeGreetingToFrench();
			trace( greeting );
		}

		public function changeGreetingToFrench():void
		{
			greeting = "Bonjour";
		}
	}
}
</pre>
<p>There are a few things to note here.</p>
<p>Firstly, the new function goes inside the class, and <em>after</em> the constructor &#8211; by convention, the constructor is the first function in the class. </p>
<p>Secondly, the new function is <em>public</em>; when coding inside a class (and not on the timeline) it&#8217;s good practice to put &#8220;public&#8221; (or &#8220;private&#8221; or &#8220;protected&#8221;, but I&#8217;ll leave those for another post) at the start of the line that defines the function. It&#8217;s just a way of letting other classes know whether or not they can access it.</p>
<p>Thirdly, the new function&#8217;s definition ends with <em>:void</em>. This just means it doesn&#8217;t return a value. Constructor functions don&#8217;t need the <em>:void</em> because they <em>can&#8217;t</em> return a value.</p>
<p>If you test this movie, you&#8217;ll get an error message:</p>
<p><strong>Main.as, Line 15: 		1120: Access of undefined property greeting.</strong></p>
<p>When you create a variable inside a function, it can&#8217;t be accessed by other functions. If you want every function in the class to be able to access the variable, you need to declare it inside the class but <em>outside</em> all of the functions:</p>
<pre name="code" class="javascript">
package
{
	import flash.display.MovieClip;
	public class Main extends MovieClip
	{
		public var greeting:String = "Hello";

		public function Main()
		{
			changeGreetingToFrench();
			trace( greeting );
		}

		public function changeGreetingToFrench():void
		{
			greeting = "Bonjour";
		}
	}
}
</pre>
<p>Just as with functions, if you declare a variable outside of a function, you need to start it with &#8220;public&#8221; (or &#8220;private&#8221; or &#8220;protected&#8221;). Unlike functions, variables should be defined <em>above</em> the constructor.</p>
<p>Test your movie now and you should finally get a nice greeting in French. How useful!</p>
<hr />
<h2>Wrapping Up</h2>
<p>So, this is not exactly an exciting result, but hopefully you now feel able to follow tutorials that don&#8217;t code on the timeline.</p>
<p>I really want to make sure everyone understands how to use a document class, so please, if any of this was unclear, post a note in the comments. Once we&#8217;ve sorted out the confusion, I&#8217;ll edit the Quick Tip to make it easier for the next person to understand. Thanks <img src='http://active.tutsplus.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=HWTL7BaqBgs:qSaE_kiEnjI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=HWTL7BaqBgs:qSaE_kiEnjI:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=HWTL7BaqBgs:qSaE_kiEnjI:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=HWTL7BaqBgs:qSaE_kiEnjI:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=HWTL7BaqBgs:qSaE_kiEnjI:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=HWTL7BaqBgs:qSaE_kiEnjI:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=HWTL7BaqBgs:qSaE_kiEnjI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=HWTL7BaqBgs:qSaE_kiEnjI:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=HWTL7BaqBgs:qSaE_kiEnjI:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=HWTL7BaqBgs:qSaE_kiEnjI:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/HWTL7BaqBgs" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/tutorials/actionscript/quick-tip-how-to-use-a-document-class-in-flash/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/tutorials/actionscript/quick-tip-how-to-use-a-document-class-in-flash/</feedburner:origLink></item>
		<item>
		<title>How to Prepare Your Flash Documents for TV Broadcast</title>
		<link>http://feedproxy.google.com/~r/Flashtuts/~3/e7UjG024Oyc/</link>
		<comments>http://active.tutsplus.com/freebies/applications/how-to-prepare-your-flash-documents-for-tv-broadcast/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 12:00:17 +0000</pubDate>
		<dc:creator>Tom Green</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Videos]]></category>

		<guid isPermaLink="false">http://active.tutsplus.com/?p=3258</guid>
		<description><![CDATA[<img src="http://activetuts.s3.cdn.plus.org/tuts/074_flashForBroadcast/Preview/preview.jpg" alt="How to Prepare your Flash Documents for TV Broadcast">]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://active.tutsplus.com/tutorials/video/exporting-code-driven-flash-as-a-quicktime-movie/">my previous article</a> I showed you how to export a code-driven animation for video playback. The problem with writing these things is that everything is wonderful because I get to focus on a single task &#8211; but everyone then thinks, &#8220;Cool, I can do that&#8221; and then discovers they have walked into a minefield because preparing Flash for broadcast requires a lot of work behind the scenes.</p>
<p>In this article, I am going to walk you through some of the more important things you need to know and do when preparing Flash projects for broadcast.</p>
<p><span id="more-3258"></span></p>
<h2>A Little Background</h2>
<p>For many of you, it may come as a bit of a surprise to discover that almost from its first release about 15 years ago, Flash animations were quietly moving from computer screens to TV screens. Animations were exported from Flash to QuickTime or AVI videos and subsequently prepared for broadcast on Avid workstations and showing up on the Saturday morning cartoon shows. </p>
<p>This was a painful process because everything that had to be done on the main timeline and ActionScript, nested movieclips and so on simply weren&#8217;t able to be used. </p>
<p>There was also a Flash constraint that continues to this day: You are &#8220;limited&#8221; to 16,000 frames and any one frame can have a &#8220;maximum&#8221; of 16,000 layers. On the surface that may seem to be more than enough room but do the math: at 30 frames per second a 16,000-frame timeline represents 9 minutes of playback. Apart from the fact that trying to get this monster to export is similar to pushing a watermelon through a worm, the odds are almost 100% that you will bump up against the 2GB limit for AVI files. This explains why many Flash animators, preparing content for broadcast, preserve their sanity by breaking their projects into 20 &#8211; 30 section chunks.</p>
<p>With the introduction of HD video in Flash Player 9.0.115 and the ability to create and play HD video using the H.264 codec and the .mp4 format Flash became untethered. The same video can be just as easily played in a browser as it can on a Sony Playstation or the HD screen in your living room. On top of all of that, SmartPhone manufacturers have come to the realization that their products are mobile devices which are being used for more than simply reaching out and &#8220;touching someone&#8221;. Though it is still early days in this arena, video is going to play a huge role in the rise of the smartphone. The day is not far off where, thanks to Flash Player 10, Flash animators will be producing content, in Flash, that shows up, simultaneously, on 52-inch HD screens, computer monitors, gaming systems and SmartPhone screens. In this article I am only going to deal with preparing Flash animations for TV.</p>
<h2>Setting up Your Flash Document</h2>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/074_flashForBroadcast/Article/1.jpg" width="600" height="339" /></div>
<p>Before you start it is a really good idea to know which aspect ratio you will be developing for.</p>
<p>The NTSC standard (National Television Standards Commission) which is used throughout North America and most of South America has a 4:3 aspect ratio which means that for every four pixels of width there are 3 pixels of height. Flash stage sizes of 640 by 480, 800 by 600 or even 320 by 240 are examples of 4:3 aspect ratios.
 </p>
<p>If you are going widescreen, the aspect ratio changes to 16:9. </p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/074_flashForBroadcast/Article/2.jpg" width="600" height="308" /></div>
<p>Even though you have picked the appropriate stage size don&#8217;t think things stop there. We are dealing with screen-based media here and when you move from your computer screen to the TV screen the shape of the pixels change from square (computer) to rectangular (TV). If you don&#8217;t compensate for this, distortions will be introduced into your work. To overcome this, a common stage size that reflects the adjustment is 720 by 540. Flash documents created for use in a PAL setting should have a stage size of 720 by 576.</p>
<h2>Frame Rate is Critical</h2>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/074_flashForBroadcast/Article/3.jpg" width="554" height="406" /></div>
<p>Flash movies, as you know, can have varying frame rates. When Flash first appeared 12 fps was the standard. Today it is up to 24 fps, the default, though many developers and designers bump it to 30 fps or higher. Broadcast is rather rigid. The NTSC standard is 29.97 fps though 30 fps is commonly used.<br />
 If you live in Europe you most likely use the PAL (Phase Alternating Line) standard which was adopted in in the early 1960&#8217;s. It too, uses the 4:3 aspect ratio used by its NTSC cousin but there are differences you need to be aware of.</p>
<p>First off, the PAL frame rate is 25fps. This standard has better resolution than NTSC meaning its picture quality is also higher. Flash documents created for use in a PAL setting should have a frame rate of 25 fps.</p>
<h2>Quicktime Isn&#8217;t Your Only Export Option</h2>
<p>Though I showed you how to export a Flash movie as a QuickTime movie, PNG sequences are the way to go when frame accuracy is critical. With this technique your Flash movie, for want of a better analogy, is treated as a Flip Book and each frame of your Flash movie is rendered out as a numbered PNG document. </p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/074_flashForBroadcast/Article/4.jpg" width="555" height="401" /></div>
<p>In this example I have applied one of the Motion Presets (Window > Motion Presets) to a movieclip on the Flash stage. The animation results in a 75-frame timeline. I selected File > Export > Export Movie and chose PNG Sequence from the Format pop down menu. The key here is to create a folder to hold the resulting png files. I am expecting a minimum of 75 png images but this number can grow to hundreds and even thousands depending on the number of frames in the Flash movie.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/074_flashForBroadcast/Article/5.jpg" width="495" height="290" /></div>
<p>Clicking the Save button opens the Export PNG dialog box. The settings chosen are self-explanatory. Clicking the OK button starts the process.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/074_flashForBroadcast/Article/6.jpg" width="600" height="439" /></div>
<p>There are now 75 png images in the folder and you will note they are sequentially numbered. It is extremely important that you don&#8217;t change any file name or number.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/074_flashForBroadcast/Article/7.jpg" width="600" height="428" /></div>
<p>I opened After Effects CS4 and selected File > Import. When the Import File dialog box opened, I navigated to the folder containing the PNG images and selected the first file in the sequence. After Effects recognizes this selection as being the first image of a PNG Sequence and selecting &#8220;Force alphabetical order&#8221; makes sure the images come into After Effects in order. The neat thing about this is when I click Open, the sequence arrives in the After Effects Project panel as a single document, not 75 individual images. From there a Video or Motion Graphics artist can further manipulate the files before outputting for broadcast.</p>
<h2>Making a <em>Safe</em> Flash Stage</h2>
<p>If there is one thing that hacks me off about watching television it&#8217;s that, on occasion, the titles or the motion will be clipped off around the edges of the screen. This is due to the fact that TVs are not computer screens and in almost all cases will actually show a smaller version of the stage size. This why video producers and Motion Graphics artists will use overlays that show them both the Title Safe and the Action Safe areas of the screen.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/074_flashForBroadcast/Article/8.jpg" width="600" height="415" /></div>
<p>These can be easily created in Flash and, if saved as a template, can be reused or you can use Guide Layers for single use purposes. The neat thing about Guide Layers is they aren&#8217;t exported.</p>
<p>In the above image I am using a template of a 720 by 540 stage. I used the Rectangle tool to create a box with a stroke and no fill that matched the stage dimensions, tucking the box up against the 0,0 point of the stage. Having the box containing the stage dimensions is an invaluable visual aid when you have content, like the above photo, that bleeds onto the pasteboard and covers the stage.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/074_flashForBroadcast/Article/9.jpg" width="369" height="141" /></div>
<p>To create the Action Safe area I copied the box, selected Edit > Paste In Place and then, using the Scale and Rotate menu found in Modify > Transform > Scale and Rotate, reduced the size of the box to 90 percent of its original size. All of the important motion in your Flash movie should take place within this area.</p>
<p>The next step was to create the Title Safe Area. Again I selected Edit > Paste In Place and this time, in the Scale and Rotate dialog box I reduced the box to 80%. The Tile safe area ensures that the all important titles are clearly legible and aren&#8217;t cropped. This is why this area lies 20% in from the absolute edge of the stage.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/074_flashForBroadcast/Article/10.jpg" width="600" height="447" /></div>
<p>I then converted the layer containing the boxes to a Guide layer by right-clicking (Command-clicking if using a Mac) on the layer name and selecting Guide from the Context menu.</p>
<h2>TV Color Isn&#8217;t Web Color</h2>
<p>The last thing I want to get into is the issue of color. In <a href="http://active.tutsplus.com/tutorials/video/exporting-code-driven-flash-as-a-quicktime-movie/">my previous tutorial</a> one of the commenters, Shaun, mentioned &#8220;Just have to watch the bright colors&#8211;seem to bleed sometimes.&#8221; Some of you may have read that and wondered, &#8220;Huh?&#8221;</p>
<p>The fact is that your TV displays less color than your computer monitor. Your monitor can display all of the RGB colors from 0 to 255. When it comes to TV your Flash palette needs to be reduced to a range from 16 and 235. Black, [0,0,0], actually gets shifted to [16,16,16] meaning the colors between 0 and 16 are clipped. Same thing for white, [255,255,255]; it gets downshifted to [235,235,235]. The color that really tends to bleed is red, you might want to reduce it from [255,0,0] to [200,16,16] and add the swatch to your color palette. </p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/074_flashForBroadcast/Article/11.jpg" width="92" height="107" /></div>
<p>If creating custom colors is tedious you might want to head out to the web and pick up Warren Fuller&#8217;s <a href="http://www.animonger.com/ntsc.html">FlashNTSC swatch palette</a>. </p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/074_flashForBroadcast/Article/12.jpg" width="385" height="304" /></div>
<p>Installing it isn&#8217;t difficult. Open the Flash Swatches panel and, from the panel pop down menu select Replace colors. When the Import Swatch Color dialog box opens navigate to the folder where you saved the .clr file, select the file and click Open.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/074_flashForBroadcast/Article/13.jpg" width="210" height="304" /></div>
<p>When the dialog box closes, the NTSC Swatches will appear in the Swatch panel.</p>
<div class="tutorial_image"><img src="http://activetuts.s3.cdn.plus.org/tuts/074_flashForBroadcast/Article/14.jpg" width="385" height="304" /></div>
<p>To return to the default set of Flash swatches click the Swatch panel&#8217;s pop down menu and select Load Default Colors.</p>
<h2>Conclusion</h2>
<p>In this article I dealt with preparing Flash files for broadcast display on a TV. I started by explaining how the Flash stage size must have a particular aspect ratio and gave you the stage sizes for NTSC and PAL broadcasts that accommodate the shift from the square pixels of a computer monitor to the rectangular pixels on a TV.</p>
<p>I also discussed the importance of frame rate and showed you another method of export to broadcast &#8211; PNG Sequence &#8211; which is more frame accurate than the usual QuickTime export out of Flash.</p>
<p>From there I moved into how to identify the Action safe and Title safe areas of a screen and explained how to create these areas through the use of a Guide layer. I finished up by briefly reviewing a couple of color issues, how to deal with them and where you can pick up a free NTSC swatch file.</p>
<p>I hope, if you have reached this point in the article, that you understand there is a lot more to the process than simply firing up Flash&#8217;s QuickTime Exporter. That is the last step in the process.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Flashtuts?a=e7UjG024Oyc:Sey9UJn7iC4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=e7UjG024Oyc:Sey9UJn7iC4:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=e7UjG024Oyc:Sey9UJn7iC4:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=e7UjG024Oyc:Sey9UJn7iC4:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=e7UjG024Oyc:Sey9UJn7iC4:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=e7UjG024Oyc:Sey9UJn7iC4:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/Flashtuts?d=qj6IDK7rITs" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=e7UjG024Oyc:Sey9UJn7iC4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=e7UjG024Oyc:Sey9UJn7iC4:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Flashtuts?a=e7UjG024Oyc:Sey9UJn7iC4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/Flashtuts?i=e7UjG024Oyc:Sey9UJn7iC4:F7zBnMyn0Lo" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/Flashtuts/~4/e7UjG024Oyc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://active.tutsplus.com/freebies/applications/how-to-prepare-your-flash-documents-for-tv-broadcast/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		<feedburner:origLink>http://active.tutsplus.com/freebies/applications/how-to-prepare-your-flash-documents-for-tv-broadcast/</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic Page Served (once) in 0.750 seconds -->
