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

<channel>
	<title>Flash, Flex and ActionScript tutorials - flashadvanced &#187; centered movie clip</title>
	<atom:link href="http://flashadvanced.com/tag/centered-movie-clip/feed/" rel="self" type="application/rss+xml" />
	<link>http://flashadvanced.com</link>
	<description>Become an advanced actionscript developer</description>
	<lastBuildDate>Sun, 30 Jan 2011 21:10:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ActionScript 3 full browser background</title>
		<link>http://flashadvanced.com/actionscript-3-full-browser-background/</link>
		<comments>http://flashadvanced.com/actionscript-3-full-browser-background/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 12:21:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ActionScript 3.0 Basics]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[centered movie clip]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[full browser]]></category>
		<category><![CDATA[pattern]]></category>
		<category><![CDATA[tiled background]]></category>

		<guid isPermaLink="false">http://flashadvanced.com/?p=261</guid>
		<description><![CDATA[Today I will show you one of the must know techniques in Flash. We will be using ActionScript 3 to fill the whole browser window with a background pattern. Also, I will show you how to center your content on the stage. So, what we want to do is when we resize the browser, the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flashadvanced.com/?p=261"><br />
<img src="http://flashadvanced.com/wp-content/upload/tilebg/tile.jpg" alt="" /><br />
</a></p>
<p>Today I will show you one of the <strong>must know techniques</strong> in Flash. We will be using ActionScript 3 to <strong>fill the whole browser window</strong> with a background pattern. Also, I will show you how to center your content on the stage. So, what we want to do is when we resize the browser, the content is centered and the background pattern is not scaled. Let&#8217;s get started!</p>
<p><span id="more-261"></span></p>
<p><span style="color: #ff0000;">1.</span> First of all, choose a background pattern from this website: <a href="http://www.squidfingers.com/patterns/" target="_blank">www.squidfingers.com</a>. Download the .zip file. Unzip the file and open a new Flash CS3 document. Save it as tile.fla. Import the pattern GIF by clicking File -&gt; Import -&gt; Import to Library.</p>
<p><span style="color: #ff0000;">2.</span> Go to the Library panel, select the background pattern and linkage it to a class named myBitmapImage:</p>
<p><img src="http://flashadvanced.com/wp-content/upload/tilebg/linkage.jpg" alt="" /></p>
<p><span style="color: #ff0000;">3.</span> Create a Movie Clip that you want to center. Set the registration point to center and give it an instance name &#8220;cont&#8221;.</p>
<p><span style="color: #ff0000;">4.</span> We are ready for ActionScript. Create new layer called &#8220;actions&#8221; and open the Actions panel.</p>
<pre><code>
//centering the content by default
cont.x = stage.stageWidth / 2;
cont.y = stage.stageHeight / 2;

//new pattern instance
var bg:myBitmapImage = new myBitmapImage(0,0);
//bitmap data
var tile:BitmapData = new BitmapData(100, 100, false, 0);
//rectangle which represents the stage
var rectPattern:Sprite;

function initStage():void
{
	//setting the scaling and the alignment of the stage
   stage.scaleMode = StageScaleMode.NO_SCALE;
   stage.align = StageAlign.TOP_LEFT;
   //we call the onStageResize function on a resize event
   stage.addEventListener(Event.RESIZE, onStageResize);

   //function for filling the background
   fillBG();
}
function fillBG():void
{
   //first we have to draw our bitmap image from library
   tile.draw(bg, new Matrix());
   //matrix that is used for beginBitmapFill function
   var matrix:Matrix = new Matrix();
   rectPattern = new Sprite();
   rectPattern.graphics.lineStyle();
   //beginBitmapFill method, fisrst we have to put bitmap data and second is matrix with value 0
   rectPattern.graphics.beginBitmapFill(tile, matrix);
   rectPattern.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
    //displaying rectangle rectDrawing
   addChild(rectPattern);
   //setting the child index to zero so the background is always behind the other objects on stage
   setChildIndex(rectPattern, 0);
}

function onStageResize(e:Event):void
{
   //repeat fill background function to fill resized stage
   fillBG();
   //always aligned at center of the stage
   cont.x = stage.stageWidth / 2;
   cont.y = stage.stageHeight / 2;
}

//init the stage
initStage();
</code></pre>
<p><span style="color: #ff0000;">5.</span> One of the last things to do is to set the publish settings. Go to File -&gt; Publish Settings and choose HTML. Under &#8220;Dimensions&#8221; choose &#8220;Percent&#8221;:</p>
<p><img src="http://flashadvanced.com/wp-content/upload/tilebg/publish.jpg" alt="" /></p>
<p><span style="color: #ff0000;">6.</span> The last thing to do is to publish the movie into a <strong>HTML</strong> page. So, once again go to File -&gt; Publish Preview -&gt; HTML. Your movie is already published in the directory where you saved your movie. Open the HTML file with a text editor and paste these lines of css code just before the  opening tag:</p>
<pre><code>
<!-- body{margin: 0px; padding: 0px} --></code>&lt;style&gt;
body{margin: 0px; padding: 0px}
&lt;/style&gt;</pre>
<p>We are ready. Everything fits perfect now. Enjoy!</p>
<p style="text-align: left; margin: 40px 40px 40px 0;"><a href="http://www.flashadvanced.com/wp-content/upload/tilebg/tile.html" target="_blank"><img src="http://flashadvanced.com/wp-content/upload/other/demo.jpg" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://flashadvanced.com/actionscript-3-full-browser-background/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

