<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>

<channel>
	<title>Hot Atomics</title>
	<atom:link href="http://www.hotatomics.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.hotatomics.com</link>
	<description>Design and Development</description>
	<pubDate>Tue, 10 Jun 2008 14:37:29 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5</generator>
	<language>en</language>
			<item>
		<title>Full Screen Flash (AS 2.0)</title>
		<link>http://www.hotatomics.com/flash-actionscript/full-screen-flash-as-20</link>
		<comments>http://www.hotatomics.com/flash-actionscript/full-screen-flash-as-20#comments</comments>
		<pubDate>Fri, 04 Apr 2008 22:59:34 +0000</pubDate>
		<dc:creator>Paul</dc:creator>
		
		<category><![CDATA[Flash/Actionscript]]></category>

		<category><![CDATA[ActionScript 2.0]]></category>

		<category><![CDATA[ActionScript Class]]></category>

		<category><![CDATA[Flash Tutorial]]></category>

		<category><![CDATA[Full Screen Flash]]></category>

		<category><![CDATA[LayoutManager.as]]></category>

		<guid isPermaLink="false">http://www.hotatomics.com/?p=10</guid>
		<description><![CDATA[In my years of Flash development I have always struggled with its capabilites in publishing output - mainly its scale and dimension properties and how to achieve proportional dimensions in different sized browser windows. If my site was to be completely developed in Flash, how could I display it properly to all users. In a [...]]]></description>
			<content:encoded><![CDATA[<p>In my years of Flash development I have always struggled with its capabilites in publishing output - mainly its scale and dimension properties and how to achieve proportional dimensions in different sized browser windows. If my site was to be completely developed in Flash, how could I display it properly to all users. In a nutshell, I wanted mainly to find a way of creating a &#8220;layout&#8221; for my published swf - for example, centering my content within a browser window no matter what size (height, width or both). But this can be done with css you say - well, yes and no. If you do a web search you will find there are a few ways to create a style sheet that can center your published swf, or any content for that matter, horizontally and vertically. But, if your Flash file has a background that you want to span your entire window, like a gradient say, this would not be possible as you would be limited to your css file&#8217;s placement dictation and would most likely result in showing  the HTML background as a border.</p>
<p>With that being said, I decided to look into creating a class that could define different objects within my swf and their layout and scale proportionate to browser window dimensions. Now, recently I have just begun to develop external Flash class files, mainly out of a desire for code re-usability. In your Flash window choose File->New->Actionscript File.</p>
<p>Copy and Paste the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript"><span style="color: #000000; font-weight: bold;">class</span> LayoutManager <span style="color: #66cc66;">&#123;</span>
	<span style="color: #808080; font-style: italic;">// Declare some variables to work with</span>
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> mc:<span style="color: #0066CC;">MovieClip</span>;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">leftMargin</span>:<span style="color: #0066CC;">Number</span>;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> topMargin:<span style="color: #0066CC;">Number</span>;
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> alignType:<span style="color: #0066CC;">String</span>;
	<span style="color: #808080; font-style: italic;">// Our Constructor and the arguments passed to it from our swf file</span>
	<span style="color: #000000; font-weight: bold;">function</span> LayoutManager<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">target</span>:<span style="color: #0066CC;">MovieClip</span>, aType:<span style="color: #0066CC;">String</span>, lmargin:<span style="color: #0066CC;">Number</span>, tmargin:<span style="color: #0066CC;">Number</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// Set scale mode to no scale</span>
		<span style="color: #0066CC;">Stage</span>.<span style="color: #0066CC;">scaleMode</span> = <span style="color: #ff0000;">&quot;noScale&quot;</span>;
		<span style="color: #808080; font-style: italic;">// Align the stage to the top left</span>
		<span style="color: #0066CC;">Stage</span>.<span style="color: #0066CC;">align</span> = <span style="color: #ff0000;">&quot;TL&quot;</span>;
		<span style="color: #808080; font-style: italic;">// Optional - disabe right-click flash menu</span>
		<span style="color: #0066CC;">Stage</span>.<span style="color: #0066CC;">showMenu</span> = <span style="color: #000000; font-weight: bold;">false</span>;
		<span style="color: #808080; font-style: italic;">// Add a listener to detect in this case when the stage/window resizes</span>
		<span style="color: #0066CC;">Stage</span>.<span style="color: #0066CC;">addListener</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">this</span><span style="color: #66cc66;">&#41;</span>;
		mc = <span style="color: #0066CC;">target</span>;
		<span style="color: #0066CC;">leftMargin</span> = lmargin;
		topMargin = tmargin;
		alignType = aType;
		<span style="color: #0066CC;">onResize</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">// Make our clip resize to browser size</span>
	<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">onResize</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">Void</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> l = alignType.<span style="color: #0066CC;">length</span>;
		<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>--l&gt;<span style="color: #cc66cc;">-1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">var</span> _alignType = alignType.<span style="color: #0066CC;">charAt</span><span style="color: #66cc66;">&#40;</span>l<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #b1b100;">switch</span> <span style="color: #66cc66;">&#40;</span>_alignType<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
					<span style="color: #808080; font-style: italic;">// Case 'c' (upper or lowercase) - center horizontally</span>
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'C'</span> :
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'c'</span> :
					<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>mc._width&gt;Stage.<span style="color: #006600;">width</span>-<span style="color: #0066CC;">leftMargin</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
						mc.<span style="color: #0066CC;">_x</span> = <span style="color: #0066CC;">leftMargin</span>;
					<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
						mc.<span style="color: #0066CC;">_x</span> = <span style="color: #0066CC;">Stage</span>.<span style="color: #0066CC;">width</span>/<span style="color: #cc66cc;">2</span>-mc.<span style="color: #0066CC;">_width</span>/<span style="color: #cc66cc;">2</span>;
					<span style="color: #66cc66;">&#125;</span>
					<span style="color: #b1b100;">break</span>;
					<span style="color: #808080; font-style: italic;">// Case 'm' (upper or lowercase) - center vertically</span>
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'M'</span> :
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'m'</span> :
					<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>mc._height&gt;Stage.<span style="color: #006600;">height</span>-topMargin<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
						mc.<span style="color: #0066CC;">_y</span> = topMargin;
					<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
&nbsp;
						mc.<span style="color: #0066CC;">_y</span> = <span style="color: #0066CC;">Stage</span>.<span style="color: #0066CC;">height</span>/<span style="color: #cc66cc;">2</span>-mc.<span style="color: #0066CC;">_height</span>/<span style="color: #cc66cc;">2</span>;
					<span style="color: #66cc66;">&#125;</span>
					<span style="color: #b1b100;">break</span>;
					<span style="color: #808080; font-style: italic;">// Case 'l' (upper or lowercase) - align left</span>
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'L'</span> :
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'l'</span> :
					mc.<span style="color: #0066CC;">_x</span> = <span style="color: #cc66cc;">0</span>+<span style="color: #0066CC;">leftMargin</span>;
					<span style="color: #b1b100;">break</span>;
					<span style="color: #808080; font-style: italic;">// Case 't' (upper or lowercase) - align top</span>
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'T'</span> :
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'t'</span> :
					mc.<span style="color: #0066CC;">_y</span> = <span style="color: #cc66cc;">0</span>+topMargin;
					<span style="color: #b1b100;">break</span>;
					<span style="color: #808080; font-style: italic;">// Case 'b' (upper or lowercase) - align bottom</span>
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'B'</span> :
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'b'</span> :
					mc.<span style="color: #0066CC;">_y</span> = <span style="color: #0066CC;">Stage</span>.<span style="color: #006600;">height</span>-mc._height-<span style="color: #0066CC;">leftMargin</span>;
					<span style="color: #b1b100;">break</span>;
					<span style="color: #808080; font-style: italic;">// Case 'r' (upper or lowercase) - align right</span>
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'R'</span> :
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'r'</span> :
					mc.<span style="color: #0066CC;">_x</span> = <span style="color: #0066CC;">Stage</span>.<span style="color: #006600;">width</span>-mc._width-topMargin;
					<span style="color: #b1b100;">break</span>;
					<span style="color: #808080; font-style: italic;">// Case 'f' (upper or lowercase) - fullscreen scale accordingly</span>
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'F'</span> :
				<span style="color: #b1b100;">case</span> <span style="color: #ff0000;">'f'</span> :
					mc.<span style="color: #0066CC;">_width</span> = <span style="color: #0066CC;">Stage</span>.<span style="color: #006600;">width</span>-<span style="color: #0066CC;">leftMargin</span>;
					mc.<span style="color: #0066CC;">_height</span> = <span style="color: #0066CC;">Stage</span>.<span style="color: #006600;">height</span>-topMargin;
					<span style="color: #b1b100;">break</span>;
&nbsp;
			<span style="color: #66cc66;">&#125;</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Create a folder - whatever you want to name it - for this example I&#8217;ve created a folder on my desktop called &#8220;flash-layout&#8221;. Save the file into your newly created folder and name it &#8220;LayoutManager.as&#8221;.</p>
<p>Next, create a new Flash movie by choosing File->New->Flash File (ActionScript 2.0). Select the Rectangle Tool and draw a rectangle on the stage - let&#8217;s give it a width of 200 pixels and a height of 200 pixels. Now select that rectangle and choose Modify->Convert To Symbol. Give it an instance name of &#8220;square_mc&#8221;, Type:Movie clip, and set the Registration point to be the top left. Click OK.
</p>
<p><img src="http://www.hotatomics.com/wordpress/wp-content/uploads/posts/full-screen-flash/image-1.jpg" alt="Image 1" /></p>
<p>With the &#8220;square_mc&#8221; clip still selected, in the properties inspector, give the movie clip an instance name of &#8220;square_mc&#8221;. Also, center align your &#8220;square_mc&#8221; by choosing Modify->Align->Horizontal Center and then do the same for Vertical Center. Next, create a new layer and call it &#8220;actions&#8221;. You can lock up the default &#8220;Layer 1&#8243; layer that our movie clip resides in. With the &#8220;actions&#8221; layer selected, select &#8220;Actions-Frame&#8221; from the property inspector. This will open up the ActionScript panel.</p>
<p>Copy and Paste the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript"><span style="color: #808080; font-style: italic;">// Reference our external movie clip classes for </span>
<span style="color: #808080; font-style: italic;">// controlling fullscreen and fixed positioning</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> centerMiddle:LayoutManager = <span style="color: #000000; font-weight: bold;">new</span> LayoutManager<span style="color: #66cc66;">&#40;</span>square_mc, <span style="color: #ff0000;">&quot;cm&quot;</span>,<span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Here we are creating a variable, called centerMiddle, calling our LayoutManager class, and declaring a &#8220;new&#8221; instance of LayoutManager. We are also passing along the necessary arguments for the new LayoutManager and assigning them to our &#8220;target&#8221; movie clip, &#8220;square_mc&#8221;, and giving it the parameters &#8220;cm&#8221; - center and middle (horizontal/vertical). The last two parameters are left and top margins, which here we have set to zero.</p>
<p>Save your movie in the flash-layout folder that we previously created and name it &#8220;flash-layout.fla&#8221;. It is important that you save to the same folder where your ActionScript class resides. There are other methods regarding classes and class paths, but for this tutorial we&#8217;ll stick to this method. After saving, test your movie - Ctrl-Enter for Windows users or Cmd-Enter for Mac users. You should be able to resize your window to any size and your movie clip will always remain centered vertically and horizontally.</p>
<p>Lastly, my Flash movies&#8217; document size for this particular tutorial is 550&#215;400 pixels. Create a new layer and drag it below the other layers in your layer window - making it the bottom layer in the layer list. With the Rectangle Tool selected, create a rectangle in this layer an give it a width of 550 and height of 400. Give it a gradient fill of your liking - whatever you choose. With this rectangle selected convert to symbol->movie clip->top left registration like we did earlier but this time name it &#8220;bg_mc&#8221;. Center align it through the same means of what we did earlier and give it an instance name &#8220;bg_mc&#8221;. Lock this layer and enter our actions panel within our actions layer where our code we pasted earlier resides.</p>
<p>Copy and Paste this after our exisitng code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript"><span style="color: #000000; font-weight: bold;">var</span> fullScreen:LayoutManager = <span style="color: #000000; font-weight: bold;">new</span> LayoutManager<span style="color: #66cc66;">&#40;</span>bg_mc, <span style="color: #ff0000;">&quot;f&quot;</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Here we used the same means of using our LayoutManager class, only difference is this time our &#8220;target&#8221; movie clip is &#8220;bg_mc&#8221;, we are passing a parameter &#8220;f&#8221; - full screen (100% window size) - and the margins remain at 0.</p>
<p>Save and test your movie again. This time our centered &#8220;square_mc&#8221; clip still remains centered and at its fixed size, however our gradient clip &#8220;bg_mc&#8221; is full screen.</p>
<p><a href="http://www.hotatomics.com/wordpress/wp-content/uploads/posts/full-screen-flash/flash-layout.zip" title="Download Source" target="_blank">Download Source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.hotatomics.com/flash-actionscript/full-screen-flash-as-20/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
