<?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>tripleaxis.com &#187; Flash Tutorials</title>
	<atom:link href="http://blog.tripleaxis.com/index.php/archives/category/development/flash/7/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.tripleaxis.com</link>
	<description></description>
	<lastBuildDate>Sat, 29 May 2010 22:00:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Help! My Preloader Starts at 50%</title>
		<link>http://blog.tripleaxis.com/index.php/archives/94</link>
		<comments>http://blog.tripleaxis.com/index.php/archives/94#comments</comments>
		<pubDate>Tue, 19 Jul 2005 23:30:26 +0000</pubDate>
		<dc:creator>Kim</dc:creator>
				<category><![CDATA[Flash Tutorials]]></category>

		<guid isPermaLink="false">http://www.tripleaxis.com/blog/?p=94</guid>
		<description><![CDATA[
			
				
			
		
I recently spoke to someone who&#8217;d experienced this problem &#8211; and they were at a complete loss as to why it was happening.
That isn&#8217;t to say they were crap or a complete n00b or anything, just that good old MM keeps sneaking stuff past us developers and, with no obvious clues and little documentation on [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.tripleaxis.com%2Findex.php%2Farchives%2F94"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.tripleaxis.com%2Findex.php%2Farchives%2F94&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>I recently spoke to someone who&#8217;d experienced this problem &#8211; and they were at a complete loss as to why it was happening.<br />
That isn&#8217;t to say they were crap or a complete n00b or anything, just that good old MM keeps sneaking stuff past us developers and, with no obvious clues and little documentation on this problem, it can sometimes take a little digging to get to the solution.</p>
<p>In this case, it was down to the MM components that had been used in the movie. By default, these happy fellas sit in your library, automatically set to export themselves on the first frame. At other times, you may actually need to set an library item to export if, for example, you need to use an <strong>attachmovie</strong> command to add it to the movie at runtime.<br />
In either case, you can bring up the <strong>linkage</strong> properties dialogue by right-clicking the symbol in the library and set it to <strong>NOT</strong> export on the first frame.<br />
<span id="more-94"></span><br />
Exporting on the first frame means that the item will be available for actionscript use <em><strong>on</strong></em> the first frame and therefore will have to be downloaded <strong><em>before</em></strong> the first frame, leaving that lovely blank white rectangle you see on many sites before the preloader kicks in.<br />
There&#8217;s never a good enough reason to use the first frame for anything other than a preloader, so, instead of making people wait for your movie in front of a blank, white screen, you use an &#8216;asset introducer&#8217; frame. </p>
<p>An &#8216;asset introducer&#8217; frame (for want of a better term) is a frame in your movie after the preloader, but before the main movie starts, that contains all the library items that you plan to use in your movie. The frame is never seen by the end user as you tell your preloader to skip over it using a gotoAndPlay command, but because the items are present on the stage, flash feels obliged to load them.<br />
(You can use an extra scene to accomplish the same thing, but I&#8217;d never willingly advise anyone to use scenes in flash movies&#8230; ever!)</p>
<p>This frame can contain graphics, buttons and movieclips, but can also hold MM Components, sounds and video holders. With nothing being exported before frame 1, flash only needs to download minimal information before it can display that all important first frame and your preloader will start from 0% <img src='http://blog.tripleaxis.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tripleaxis.com/index.php/archives/94/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Advanced Bar Preloader Tutorial</title>
		<link>http://blog.tripleaxis.com/index.php/archives/90</link>
		<comments>http://blog.tripleaxis.com/index.php/archives/90#comments</comments>
		<pubDate>Tue, 12 Jul 2005 22:26:35 +0000</pubDate>
		<dc:creator>Kim</dc:creator>
				<category><![CDATA[Flash Tutorials]]></category>

		<guid isPermaLink="false">http://www.tripleaxis.com/blog/?p=90</guid>
		<description><![CDATA[
			
				
			
		

In this tutorial, I will assume a basic level of Flash Actionscript knowledge and will be using the basic drawing API methods available since Flash MX. We will also use functions to create streamlined, reusable code.
Sections:
   1. A brief look at the Flash Drawing API.
   2. Organising our Movie.
   [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.tripleaxis.com%2Findex.php%2Farchives%2F90"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.tripleaxis.com%2Findex.php%2Farchives%2F90&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<link rel="stylesheet" href="http://www.tripleaxis.com/tutorials/flash/advBarPreloader/preloader.css" type="text/css" />
In this tutorial, I will assume a basic level of Flash Actionscript knowledge and will be using the basic drawing API methods available since Flash MX. We will also use functions to create streamlined, reusable code.<br />
Sections:</p>
<p>   1. <a href="#step1">A brief look at the Flash Drawing API.</a><br />
   2. <a href="#step2">Organising our Movie.</a><br />
   3. <a href="#step3">Creating the graphics with Actionscript.</a><br />
   4. <a href="#step4">Creating the percentage textfield with Actionscript.</a><br />
   5. <a href="#step5">Centering the preloader on the stage.</a><br />
   6. <a href="#step6">Writing the functions to collect data.</a><br />
   7. <a href="#step7">Putting it all together.</a></p>
<p><strong><a href="../codeViewer.php?get_file=1&#038;file=downloads/codePreloader.zip">Grab all the tutorial files here</a></strong><br />
<span id="more-90"></span></p>
<hr width="100%" id="step1" noshade color="#AAAAAA"/>
<p class="pre_title">What is the point?</p>
<p>The idea behind preloading is that to ensure that everything we need to run our movie correctly; graphics, sounds, animations, etc have all completely loaded. We do this by stopping the movie from playing at a very early point &#8211; frame 1 being the most logical place &#8211; whilst we find out two things:</p>
<p>1) how much of the movie there is in total to load.<br />
2) how much we have already loaded.</p>
<p>Once we have these two numbers, we can create a percentage and then effectively give a waiting user a good idea of how long they will have to wait before the show will begin!</p>
<p>Since Flash MX, it has been possible to create graphics through Actionscript code whilst the movie is running and we will use this to create a simple bar graphic to display how much of our movie is loaded.</p>
<hr width="100%" noshade color="#AAAAAA"/>
<p class="pre_title">Step 1: A brief look at the Flash Drawing API.</p>
<p>The Flash Drawing API gives us the power to create graphics in our movie without ever having to touch the Flash authoring environment. It provides extremely simple methods (functions), with which we can draw lines, shapes and fills whilst the movie is running. The methods we will be using in our preloader will be:</p>
<p><a target="_blank" href="http://livedocs.macromedia.com/flash/mx2004/main_7_2/00001524.html#wp3999538">moveTo</a> &#8211; Move to a new position to begin drawing.<br />
<a target="_blank" href="http://livedocs.macromedia.com/flash/mx2004/main_7_2/00001518.html#wp3999305">lineTo</a> &#8211; Draw a straight line from the current drawing position to the x,y coordinates specified.<br />
<a target="_blank" href="http://livedocs.macromedia.com/flash/mx2004/main_7_2/00001488.html#wp3998377">beginFill</a> &#8211; Specify the fill details of the shape we are about to draw.<br />
<a target="_blank" href="http://livedocs.macromedia.com/flash/mx2004/main_7_2/00001498.html#wp3998770">endFill</a> &#8211; Close current shape and fill it.</p>
<p class="pre_note">NOTE: Method names above are linked to Macromedia&#8217;s LiveDocs for full explanation.</p>
<hr width="100%" id="step2" noshade color="#AAAAAA"/>
<p class="pre_title">Step 2: Organising our Movie.</p>
<p>As the code we&#8217;re going to be writing here will be dedicated to our preloader we don&#8217;t want to get it confused with other pieces of code that may exist in our movie. To prevent this and make it easy for us to find our code within our movie, create a new layer on the main timeline and call it &#8216;PRELOADER&#8217;. We will use the first frame of this layer for all our code.</p>
<p class="pre_note">NOTE: It is a good option to create an external actionscript file (.as) and use the &#8216;<a target="_blank" href="http://livedocs.macromedia.com/flash/mx2004/main_7_2/00001368.html#wp3951584">#include</a>&#8216; compiler directive to add your code to the movie.</p>
<hr width="100%" id="step3" noshade color="#AAAAAA"/>
<p class="pre_title">Step 3: Creating the Graphics with Actionscript.</p>
<p>Right. Let&#8217;s get started.<br />
The first thing we will need if we are going to be able to draw is a MovieClip. As moveTo, lineTo, etc are all methods of the MovieClip Class (object), we will need an instance of a MovieClip in our movie in order to use them. This doesn&#8217;t mean that we have to go placing a clip on the stage like usual &#8211; all we need to do is to use the <a target="_blank" href="http://livedocs.macromedia.com/flash/mx2004/main_7_2/00001491.html#wp3998547">createEmptyMovieClip</a> method.<br />
When using createEmptyMovieClip we can capture a reference (a virtual link to the actual MovieClip) to the newly created MovieClip and store it in a variable for ease of use.</p>
<p class="pre_note">NOTE: For more information on MovieClips and references, check out Colin Moock&#8217;s <a target="_blank" href="http://www.oreilly.com/catalog/actscript/chapter/ch13.html">Actionscript: The Definitive Guide</a>.</p>
<p>Lets&#8217;s start by creating a container MovieClip, which will hold all of our graphics. We do this so that when it&#8217;s time to remove our preloader, we can do so by just removing the container. Select the 1st frame on our PRELOADER layer and add the following:</p>
<p class="pre_code">
<span class="pre_comment">// Create our container and store reference in a variable:</span><br />
var preloader_mc = createEmptyMovieClip( &#8220;preloader&#8221;, 10 );
</p>
<p>Our preloader&#8217;s graphics will be two basic rectangles: one filled and one hollow. First, let&#8217;s make our filled rectangle &#8211; 150 pixels wide and 15 pixels high. This will be the main bar of our preloader.</p>
<div class="pre_code">
<span class="pre_comment">//Create our drawing MovieClip inside our container:</span><br />
var filledBar_mc = preloader_mc.createEmptyMovieClip( &#8220;filledBar&#8221;, 20 );</p>
<p><span class="pre_comment">// Set the Style for the outline of our rectangle:</span><br />
<span class="pre_comment">// ( thickness, rgb color, alpha )</span><br />
filledBar_mc.lineStyle( 1,0&#215;999999,100 );</p>
<p><span class="pre_comment">// Move our drawing clip into position:</span><br />
filledBar_mc.moveTo( 0,0 );</p>
<p><span class="pre_comment">// Set our shape&#8217;s fill properties:</span><br />
filledBar_mc.beginFill( 0xCCCCCC );</p>
<p><span class="pre_comment">// Draw our rectangle ( 150px / 15px ):</span><br />
filledBar_mc.lineTo( 150,0 );<br />
filledBar_mc.lineTo( 150,15 );<br />
filledBar_mc.lineTo( 0,15 );<br />
filledBar_mc.lineTo( 0,0 );</p>
<p><span class="pre_comment">// Close shape and fill:</span><br />
filledBar_mc.endFill();
</div>
<p>Now for our hollow one.<br />
We want this clip to appear on top of our filled bar, so our depth will be 30.</p>
<div class="pre_code">
<span class="pre_comment">// Create our drawing MovieClip inside our container:</span><br />
var hollowBar_mc = preloader_mc.createEmptyMovieClip( &#8220;hollowBar&#8221;, 30 );</p>
<p><span class="pre_comment">// Set the Style for the outline of our rectangle:</span><br />
hollowBar_mc.lineStyle( 1,0&#215;666666,100 );</p>
<p><span class="pre_comment">// Move our drawing clip into position:</span><br />
hollowBar_mc.moveTo( 0,0 );</p>
<p><span class="pre_comment">// Draw our rectangle ( 150px / 15px ):</span><br />
hollowBar_mc.lineTo( 150,0 );<br />
hollowBar_mc.lineTo( 150,15 );<br />
hollowBar_mc.lineTo( 0,15 );<br />
hollowBar_mc.lineTo( 0,0 );
</div>
<p>We have now created our graphics. They&#8217;re not going to win any prizes for design, but they&#8217;re clear, functional and they took us seconds to make. I&#8217;ll leave the award-winning to you.</p>
<p>Next comes the percentage display. If you don&#8217;t want to show the user this information, you can skip this next part and go straight to <a target="_blank" href="#step5">centering the preloader</a>, but it is always a good idea to keep the user as informed as possible as to what exactly is happening and not providing enough feedback could mean the difference between a user staying or leaving your site!</p>
<hr width="100%" noshade height="1" color="#AAAAAA" id="step4"/>
<p class="pre_title">Step 4: Creating the percentage textfield with Actionscript.</p>
<p>Alongside dynamically creating MovieClips, we also have the ability in Actionscript to create textfields. In our preloader, we now need to display a percentage that shows the user how much of the movie has loaded and to do this we must create a textfield using the <a target="_blank" href="http://livedocs.macromedia.com/flash/mx2004/main_7_2/00001492.html#wp3998568">createTextField</a> method.<br />
When creating our textfield we need to specify a name, depth, position (x and y) and dimensions (width and height) and to do this we need to work out a few things beforehand.</p>
<ul>
<li><strong>Name.</strong> This is up to you &#8211; in this case, I&#8217;ll just call it &#8216;percentDisplay&#8217;, but the more obvious your naming of objects and variables in your code, the better.</li>
<li><strong>Depth.</strong> We need the percentage to appear above the rest of the graphics, so it&#8217;ll be 40.</li>
<li><strong>Position.</strong> The percentage will be centered on the hollowBar graphic, so we will use its position and dimensions to center the textfield.</li>
<li><strong>Dimensions.</strong> We only need a small area to display the percentage, so think about the largest possible string that we will have to display. In this case it will be &#8220;100%&#8221;,<br />
so as long as this fits, we will be fine.</li>
</ul>
<p class="pre_note">NOTE: With naming conventions, you won&#8217;t readily notice the difference on smaller projects, but in larger, more complex applications, keeping names self-explanatory and easy to understand will help you immensely when it comes to working on sections of code that you may not be familiar with or simply haven&#8217;t touched for a while.</p>
<div class="pre_code">
<span class="pre_comment">// Find our X position from hollowBar&#8217;s _x position and _width:</span><br />
var textFieldX = filledBar_mc._x + ( filledBar_mc._width/2 ) &#8211; 26;</p>
<p><span class="pre_comment">// Find our Y position from hollowBar&#8217;s _y position and _height:</span><br />
var textFieldY = filledBar_mc._y + ( filledBar_mc._height/2 ) &#8211; 8.5;</p>
<p><span class="pre_comment">// Create our textfield:</span><br />
preloader_mc.createTextField( &#8220;percentDisplay&#8221;,31,textFieldX,textFieldY,50,15 );</p>
<p><span class="pre_comment">// Take a reference to our new textfield for easy reference:</span><br />
var percentDisplay_txt = preloader_mc.percentDisplay;</p>
<p><span class="pre_comment">// Set Text to be unselectable:</span><br />
percentDisplay_txt.selectable = false;
</div>
<p>Now we have a textfield, we can apply style to the text (font,size,colour,etc) by using a TextFormat object. The TextFormat object gives us the ability to apply a style to a textfield or portion of text.</p>
<div class="pre_code">
<span class="pre_comment">// Create a new TextFormat Object:</span><br />
var myTextFormat = new TextFormat();</p>
<p><span class="pre_comment">// Set the Text alignment:</span><br />
myTextFormat.align = &#8220;center&#8221;;</p>
<p><span class="pre_comment">// Set the Text font:</span><br />
myTextFormat.font = &#8220;Verdana&#8221;;</p>
<p><span class="pre_comment">// Set Text size:</span><br />
myTextFormat.size = 10;</p>
<p><span class="pre_comment">// Set Text colour:</span><br />
myTextFormat.color = 0&#215;003300;</p>
<p><span class="pre_comment">// Apply the TextFormat to our textfield:</span><br />
percentDisplay_txt.setTextFormat( myTextFormat );
</div>
<hr width="100%" noshade height="1" color="#AAAAAA" id="step5"/>
<p class="pre_title">Step 5: Centering the Preloader on the stage.</p>
<p>Having graphics on the stage is fine, but let&#8217;s make it look a little cleaner and align our preloader to the center of our movie.<br />
We can do this by taking our movie&#8217;s current width and height, finding the center point, finding the center point of our preloader and matching the two together.</p>
<div class="pre_code">
<span class="pre_comment">// Store our Movie&#8217;s width and height in two variables:</span><br />
<span class="pre_comment">// Replace with your movie&#8217;s dimensions:</span><br />
var movieWidth = 400;<br />
var movieHeight = 300;</p>
<p><span class="pre_comment">// Find the preloader&#8217;s new X position using the Stage width:</span><br />
preloader_mc._x = Math.round( movieWidth/2 &#8211; preloader_mc._width/2 );</p>
<p><span class="pre_comment">// Find the preloader&#8217;s new Y position using the Stage height:</span><br />
preloader_mc._y = Math.round( movieHeight/2 &#8211; preloader_mc._height/2 );
</div>
<hr width="100%" noshade color="#AAAAAA" id="step6"/>
<p class="pre_title">Step 6: Writing the function to collect data.</p>
<p>OK. Now we have taken care of the graphical elements of our preloader, we need to start thinking about how it&#8217;s all going to work. We will need to montior the amount of data we&#8217;ve already loaded and update our graphics accordingly. As the code that will do this will have to execute over and over again, we can simplify our code by encapsulating the commands into a function. Using functions has the effect of cleaning up code considerable and, with proper naming conventions again, can make code a lot more readable to other users.</p>
<p>In this case we are going to take several lines of code that gather information and perform a calculation with that data and stick them all into a function called &#8216;getPercentageLoaded&#8217;. Not only are we cleaning up the code, but we are also letting others know exactly what our code does simply by encapsulating it in a well-named function.</p>
<p>The information we&#8217;re after here are will be provided by the methods: <a target="_blank" href="http://livedocs.macromedia.com/flash/mx2004/main_7_2/00001504.html#3998890">getBytesTotal</a> and <a target="_blank" href="http://livedocs.macromedia.com/flash/mx2004/main_7_2/00001503.html#wp3998867">getBytesLoaded</a>. They are simple to use and return the relevant amounts of data in bytes.</p>
<p class="pre_note">NOTE: Remember that if you ever want to obtain an accurate number of kilobytes from a bytes value, you must divide by 1024<br />
i.e. var kilobytes = bytes/1024;</p>
<div class="pre_code">
<span class="pre_comment">// Create our function:</span><br />
function getPercentageLoaded(){</p>
<p>&nbsp;&nbsp;<span class="pre_comment">// Get total bytes and loaded bytes of our movie:</span><br />
&nbsp;&nbsp;var total = this.getBytesTotal();<br />
&nbsp;&nbsp;var loaded = this.getBytesLoaded();</p>
<p>&nbsp;&nbsp;<span class="pre_comment"> // Create percentage and return result:</span><br />
&nbsp;&nbsp;var percentage = Math.ceil( loaded / total * 100 );<br />
&nbsp;&nbsp;return percentage;<br />
}
</div>
<p>You will notice above that the last statement in the function is &#8216;return percentage&#8217;. If you&#8217;re not familiar with functions, what this does is to pass the variable we have just created inside the function (percentage) back out to the code where the function was called. This will become clearer in the next section, where we put everything together, call the function and use it&#8217;s output.</p>
<hr width="100%" noshade color="#AAAAAA" id="step7"/>
<p class="pre_title">Step 7: Putting it all together.</p>
<p>All that&#8217;s left to do now is to write the actual logic of our process. We have our data gathering function and our graphics that are ready and waiting to be manipulated to give our user some valuable feedback and now we need to look at how our movie is actually going to play.</p>
<p>The first thing we want to do is to stop the movie, then we will use the <a target="_blank" href="http://livedocs.macromedia.com/flash/mx2004/main_7_2/00001530.html#wp3999715">onEnterFrame</a> event handler to control our preloader. The onEnterFrame event is fired each time the movie enters a new frame and by attaching an onEnterFrame function to any movieclip (including the main timeline), we know that the code inside our function will be executed once every frame. Here we will attach the function to our &#8216;preloader_mc&#8217; movieClip that we created earlier.</p>
<div class="pre_code">
<span class="pre_comment">// Stop playback:</span><br />
stop();</p>
<p><span class="pre_comment">// Create our event handler:</span><br />
preloader_mc.onEnterFrame = function(){</p>
<p>&nbsp;&nbsp;<span class="pre_comment">// Call our function and store result:</span><br />
&nbsp;&nbsp;var percent = _root.getPercentageLoaded();</p>
<p>&nbsp;&nbsp;<span class="pre_comment">// Set filledBar size as per our percentage:</span><br />
&nbsp;&nbsp;this.filledBar._xscale = percent;</p>
<p>&nbsp;&nbsp;<span class="pre_comment">// Display percentage text in our textfield:</span><br />
&nbsp;&nbsp;this.percentDisplay.text = percent + &#8220;%&#8221;;</p>
<p>&nbsp;&nbsp;<span class="pre_comment">// Check to see if our movie&#8217;s loaded or not:</span><br />
&nbsp;&nbsp;if( percent > 99 ){</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span class="pre_comment">// Hide preloader graphics:</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;this._visible = false;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span class="pre_comment">// Stop this onEnterFrame loop:</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;delete this.onEnterFrame;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span class="pre_comment">// Play the main timeline:</span><br />
&nbsp;&nbsp;&nbsp;&nbsp;_root.play();<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}
</div>
<p>&#8230;and there you have it. This is a movie preloader that you can use again and again. To add this to a movie, just paste it into the first frame of your movie.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tripleaxis.com/index.php/archives/90/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Simple Bar Preloader Tutorial</title>
		<link>http://blog.tripleaxis.com/index.php/archives/83</link>
		<comments>http://blog.tripleaxis.com/index.php/archives/83#comments</comments>
		<pubDate>Tue, 12 Jul 2005 21:10:26 +0000</pubDate>
		<dc:creator>Kim</dc:creator>
				<category><![CDATA[Flash Tutorials]]></category>

		<guid isPermaLink="false">http://www.tripleaxis.com/blog/?p=83</guid>
		<description><![CDATA[
			
				
			
		

In this tutorial, I will assume a basic level of Flash knowledge.
The idea behind this preloader is that we halt the progression of the movie and find out our filesize. We find then find out how much of that is loaded, use these numbers to create a percentage and then affect the scale of our [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.tripleaxis.com%2Findex.php%2Farchives%2F83"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.tripleaxis.com%2Findex.php%2Farchives%2F83&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<link rel="stylesheet" href="http://www.tripleaxis.com/tutorials/flash/simpleBarPreloader/preloader.css" type="text/css" />
In this tutorial, I will assume a basic level of Flash knowledge.</p>
<p>The idea behind this preloader is that we halt the progression of the movie and find out our filesize. We find then find out how much of that is loaded, use these numbers to create a percentage and then affect the scale of our bar to represent this. We will repeat this until a satisfactory percentage of the movie has been loaded and then we let the movie continue.</p>
<p><strong><a href="../codeViewer.php?get_file=1&#038;file=downloads/barPreloader.zip">Grab all the tutorial files here</a></strong><br />
<span id="more-83"></span></p>
<p class="pre_title">Step 1: Create the graphics / structure.</p>
<ol>
<li>Create an empty movieclip. This will be our preloader, so you can call it something appropriate&#8230; &#8230;maybe &#8216;preloader&#8217;.</li>
<li>Now we are working within our new movieclip, create a long, filled rectangle and set the outline stroke to hairline.<br />
( this is to ensure clean scaling of the line ).</li>
<li>Select the entire rectangle and bring up the &#8216;Align&#8217; panel, shown below and click the &#8216;to Stage&#8217; button.<br />
This will allow us to align our chosen objects to positions relative to the movieclip in which we are working.<br />
Click the &#8216;Align Left Edge&#8217; button, then the &#8216;Align Top Edge&#8217; button. This aligns our shape so that its top-left corner is flush up against the registration point (center marker) of our movieclip.<br />
<img style="padding:4px;border:1px solid #ddd;" src="http://www.tripleaxis.com/tutorials/flash/simpleBarPreloader/alignpanel.gif" alt="The Align Panel" /></li>
<li>Select the fill of the rectangle and select &#8216;Convert to Symbol&#8217; from the &#8216;Insert&#8217; menu.<br />
(You may press F8 instead for the same effect).<br />
Call the new symbol &#8216;fill&#8217; and set the behaviour to &#8216;Movie Clip&#8217;.<br />
Hit OK, bring up the instance panel and name the movieClip &#8216;fill&#8217;.</li>
<li>Repeat step 3, but for the &#8216;fill&#8217; movieclip. Note: you will have to work inside the fill movieClip in order to align it properly.<br />
Once aligned, you will have to re-align the movieclip itself so that it fits into the rectangle outline.<br />
You should now have a movieclip that contains the outline of a rectangle and another movlieclip, called &#8216;fill&#8217;.<br />
As both of these items are on the same layer at the moment, separate them out into their own layers.</li>
<li>Lastly, add a dynamic textfield into another layer above the other graphics and set its variable to &#8216;txt&#8217; as shown below.<br />
Place this textfield over the bar and adjust the text size to fit snugly.<br />
It is a good idea to enter the maximum possible amount of text into a dynamic text field<br />
( in this case &#8216;100%&#8217; ), in order to aid in sizing and positioning the textfield.<br />
  <img style="padding:4px;border:1px solid #ddd;" src="http://www.tripleaxis.com/tutorials/flash/simpleBarPreloader/textpanel.gif" alt="The Textfield Panel" /></p>
<p>Your movie should now look something like this.</p>
<p><img style="padding:4px;border:1px solid #ddd;" src="http://www.tripleaxis.com/tutorials/flash/simpleBarPreloader/screen1.gif" alt="Screenshot1" /></p>
<p class="pre_note">Note: to check if everything is properly aligned, marquee-select everything inside the main movieclip.<br />
You should only be able to see one pair of (registration point) cross hairs.<br />
If you see two, you need to repeat the alignment steps.</p>
</li>
</ol>
<p class="pre_title">Step 2: Add the code.</p>
<blockquote><p>Select the &#8216;fill&#8217; movieclip and add the following code in the Actions panel:<br />
( note: make sure it says &#8216;Object Actions&#8217; (Flash5) or &#8216;Actions &#8211; MovieClip&#8217; (FlashMX/2004) in the top of the Actions panel and not &#8216;Frame Actions&#8217;.<br />
We want to add the actions to the movieclip itself, not into a frame. )</p>
<p><img style="padding:4px;border:1px solid #ddd;" src="http://www.tripleaxis.com/tutorials/flash/simpleBarPreloader/code1_mx.gif" alt="The Code" />
</p></blockquote>
<p><strong>The code explained:</strong></p>
<ol>
<li>
<p class="pre_code">onClipEvent(load) {<br />
&nbsp;&nbsp;_root.stop();<br />
   }</p>
<p>This will simply halt the main timeline of your movie as soon as the frame containing this movieclip is entered.<br />
If that is the first frame of your entire movie, then everything will be halted until something re-starts it ( i.e. our Loader )</li>
<li>
<p class="pre_code">onClipEvent(enterFrame){</p>
<p>This is the most commonly used movieclip event handler. It enables us to execute the code within it every time flash plays a frame.<br />
This basically means that if we set the main movie&#8217;s framerate to 18fps, then we will be looping through our code 18 times every second.</li>
<li>
<p class="pre_code">&nbsp;&nbsp;var totalk    = _root.getBytesTotal();<br />
&nbsp;&nbsp;var loadedk = _root.getBytesLoadedl();</p>
<p>getBytesTotal and getBytesLoaded return the total filesize of our movie and how much of that is loaded (respectfully) in bytes (1K = 1024Kb)</li>
<li>
<p class="pre_code">&nbsp;&nbsp;var percent = Math.ceil((loadedk/totalk)*100);</p>
<p>We use Math.ceil on the final percentage to round the outcome of the calculation up to the nearest whole number.<br />
This gives us a friendlier figure to display in our textfield.</p>
<p class="pre_note">( Note: Sometimes the values for getBytesTotal and getBytesLoaded may differ slightly, so rounding to the next number up and checking for a percentage that is greater than 99% is advisable to allow for this discrepancy &#8211; any shortfall will be streamed as our movie starts playing)</p>
</li>
<li>
<p class="pre_code">&nbsp;&nbsp;if (percent&lt;99){</p>
<p>This is our conditional statement. If our percentage is less than 99 ( i.e. not loaded ), we want to continue looping, otherwise we want to start the movie.</li>
<li>
<p class="pre_code">&nbsp;&nbsp;&nbsp;&nbsp;_parent.txt = percent + &#8220;%&#8221;;</p>
<p>&#8220;_parent&#8221; simply means &#8220;one level up&#8221; ( up &#8211; if you think of the main timeline being at the top )<br />
In this case, _parent.txt refers to the variable that our textfield displays and copies the current value of our percent variable into it, with a nice little percent sign on the end.</li>
<li>
<p class="pre_code">&nbsp;&nbsp;&nbsp;&nbsp;_xscale = percent;</p>
<p>This is the code that changes the horizontal scale of the bar. As the _xscale property uses a percentage, affecting this property is perfect for creating preloaders. If you think of the graphic you created as being 100% of the horizontal scale, 10% or even 50% will be thinner, therefore a pretty accurate representation of the amount of data loaded can be displayed.</li>
<li>
<p class="pre_code">&nbsp;&nbsp;} else {<br />
&nbsp;&nbsp;&nbsp;&nbsp;_root.play();<br />
&nbsp;&nbsp;}<br />
}</p>
<p>This is our &#8216;loop out&#8217; action. If enough of the movie has loaded, simply start the main timeline playing.</li>
</ol>
<p>&#8230; and there you have it. This is a movie preloader that you can use again and again. To add this to a movie, just drop it into the first frame of your movie.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tripleaxis.com/index.php/archives/83/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using FlashVars</title>
		<link>http://blog.tripleaxis.com/index.php/archives/80</link>
		<comments>http://blog.tripleaxis.com/index.php/archives/80#comments</comments>
		<pubDate>Sat, 09 Jul 2005 22:52:07 +0000</pubDate>
		<dc:creator>Kim</dc:creator>
				<category><![CDATA[Flash Tutorials]]></category>

		<guid isPermaLink="false">http://www.tripleaxis.com/blog/?p=80</guid>
		<description><![CDATA[
			
				
			
		
Here&#8217;s a quick tutorial for you guys.. This is a great one for getting values into flash before the movie even starts playing and there&#8217;s no Javascript or server side code involved whatsoever!
A lot of people have heard about FlashVars and the idea of passing values into flash via HTML, but don&#8217;t know how to [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.tripleaxis.com%2Findex.php%2Farchives%2F80"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.tripleaxis.com%2Findex.php%2Farchives%2F80&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p>Here&#8217;s a quick tutorial for you guys.. This is a great one for getting values into flash <strong><em>before</em></strong> the movie even starts playing and there&#8217;s no Javascript or server side code involved whatsoever!<br />
A lot of people have heard about FlashVars and the idea of passing values into flash via HTML, but don&#8217;t know how to use it. Well there&#8217;s actually <em>two</em> ways of going about this.<br />
<span id="more-80"></span><br />
<strong>1. Appending to the Filename</strong><br />
The idea here is that we append our variables onto the end of the URL from where the HTML will load the flash file. This is the &#8220;src&#8221; parameter in our &lt;object&gt; and &lt;embed&gt; tags. Just a quick point here.. The reason why we have to use both the object and embed tags is that some browsers respect one tag and some respect the other. This is due to the fact that in some browsers (Mozilla/Netscape/etc), flash is a Plugin and in IE, flash is an ActiveX Control. The different types of format require the different tags.</p>
<p><strong><em>Note: Using this method means the swf will not be cached if the flashvars change. The SWF file will have to be re-downloaded by the user completely every time the flashvars are different.</em></strong></p>
<hr width="100%" />
Example:<br />
Here we want to pass the following variables and be able to access their values on frame 1 of our movie:<br />
<strong><br />
greeting: &#8220;Hello world&#8221;<br />
visitorID: 51<br />
</strong></p>
<div style="padding-right: 6px; padding-left: 6px; padding-bottom: 6px; overflow: auto; height: 190px; border: #ddd 1px solid"><img id="image167" src="http://www.tripleaxis.com/tutorials/flash/flashvars/FilenameFlashvars.gif" /></div>
<p>In the code above, the %20 represents a space character. When dealing with text in html and flash, it may contain characters, such as &#038;, = or quotes which can cause unexpected results, so it is always safest to <a href="http://www.barelyfitz.com/projects/encoder/" target="_blank">escape</a> or <a href="http://uk2.php.net/urlencode" target="_blank">urlencode</a> your variables beforehand.</p>
<p><strong>2. The FlashVars Parameter</strong></p>
<p>The other method of passing values directly into flash is by using the FlashVars parameter in our object and embed tags. As with the first example, the FlashVars must be added to both tags in order for it to work correctly in all browsers.</p>
<p>Example:<br />
We are passing the same variables as before.</p>
<div style="padding-right: 6px; padding-left: 6px; padding-bottom: 6px; overflow: auto; padding-top: 6px; height: 190px; border: #ddd 1px solid"><img id="image167" src="http://www.tripleaxis.com/tutorials/flash/flashvars/Flashvars.gif" /></div>
<p>Example SWF:<br />
<iframe style="width: 100%; height: 380px" src="http://www.tripleaxis.com/tutorials/flash/flashvars/flashvars.php" frameborder="0" width="100%" height="330" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tripleaxis.com/index.php/archives/80/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
