<?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>mikestickney.com &#187; ActionsScript Tutorial</title>
	<atom:link href="http://mikestickney.com/wordpress/tag/actionsscript-tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://mikestickney.com/wordpress</link>
	<description></description>
	<lastBuildDate>Tue, 24 Aug 2010 01:25:08 +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>Flash Tutorial: Character Movement with Arrow Keys</title>
		<link>http://mikestickney.com/wordpress/flash-tutorial-character-movement-with-arrow-keys/</link>
		<comments>http://mikestickney.com/wordpress/flash-tutorial-character-movement-with-arrow-keys/#comments</comments>
		<pubDate>Sat, 12 Apr 2008 02:14:48 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[ActionScript tutorials]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Tutorial]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[ActionsScript Tutorial]]></category>
		<category><![CDATA[arrow keys]]></category>
		<category><![CDATA[character movement]]></category>
		<category><![CDATA[design tutorial]]></category>
		<category><![CDATA[flash design; Movie Clip]]></category>
		<category><![CDATA[flash development]]></category>

		<guid isPermaLink="false">http://mikestickney.com/wordpress/flash-tutorial-character-movement-with-arrow-keys/</guid>
		<description><![CDATA[Level: This is a basic ActionsScript tutorial. As this is not an animation tutorial, a basic knowledge of the Flash user environment is assumed
Version: I will be using Flash CS3 and AS2 (athough tut is compatible with earlier versions of Flash) and instructions are for the Mac. Windows users would use the PC counterparts for [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Level: </strong>This is a basic ActionsScript tutorial. As this is not an animation tutorial, a basic knowledge of the Flash user environment is assumed</p>
<p><strong>Version:</strong> I will be using Flash CS3 and AS2 (athough tut is compatible with earlier versions of Flash) and instructions are for the Mac. Windows users would use the PC counterparts for specific instructions on Flash Menu/Shortcut instuctions.</p>
<p><strong>Description:</strong> In this Flash tutorial, I will show you how to move a game character using the arrow keys, and have the character face in the direction that he is moving.</p>
<p><strong>Demo:</strong><br />

<object type="application/x-shockwave-flash" width="400" height="300">
<param name="movie" value="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/charMove_tut1.swf" />
<embed src="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/charMove_tut1.swf" type="application/x-shockwave-flash" width="400" height="300" >
</object>
</p>
<p><strong>Let&#8217;s get started!</strong></p>
<p>Select &#8220;File &gt; New&#8221; (command-&#8221;N&#8221;) and select Flash File (ActionScript 2.0) to open a new Flash document file.</p>
<p><span id="more-28"></span>Save the file, and give it the appropriate name. I will call this &#8220;charMove_tut1&#8243;. Feel free to make the document dimensions (&#8220;Modify &gt; Document or &#8220;command-J&#8221;) whatever you like, but I chose to use a size of 400 x 300 pixels.</p>
<p>The first thing we want to do is create a game character with 4 seperate states: left profile, right profile, front profile and back profile. Because this is not an illustration / animation tutorial, I will not be going through how to illustrate your character. Feel free to illustrate your own character, and convert each profile into it&#8217;s own symbol. For those beginners who do not want to illustrate their own character at this time, feel free to download the below .swf files (or jump to the source at the bottom of this page):</p>
<p>Front Profile: <a href="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/ninja_front.swf" >Download</a> (right click on link and select &#8220;Save Link As&#8221;) 
<object type="application/x-shockwave-flash" width="50" height="95">
<param name="movie" value="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/ninja_front.swf" />
<embed src="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/ninja_front.swf" type="application/x-shockwave-flash" width="50" height="95" >
</object>
</p>
<p>Left Profile: <a href="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/ninja_left.swf" >Download</a> 
<object type="application/x-shockwave-flash" width="50" height="95">
<param name="movie" value="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/ninja_left.swf" />
<embed src="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/ninja_left.swf" type="application/x-shockwave-flash" width="50" height="95" >
</object>
</p>
<p>Right Profile: <a href="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/ninja_right.swf" >Download</a><br />

<object type="application/x-shockwave-flash" width="50" height="95">
<param name="movie" value="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/ninja_right.swf" />
<embed src="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/ninja_right.swf" type="application/x-shockwave-flash" width="50" height="95" >
</object>
</p>
<p>Back Profile: <a href="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/ninja_back.swf" >Download</a><br />

<object type="application/x-shockwave-flash" width="50" height="95">
<param name="movie" value="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/ninja_back.swf" />
<embed src="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/ninja_back.swf" type="application/x-shockwave-flash" width="50" height="95" >
</object>
</p>
<p align="center">&#8212;- ads by google &#8212;-<br />
<script type="text/javascript"><!--
google_ad_client = "pub-7252304256657784";
google_ad_slot = "4730110072";
google_ad_width = 234;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
<p>To import these files, open your Flash file, select &#8220;File &gt; Import &gt; Import to Library&#8221;, browse to where you saved the above files, select the files and click the &#8220;Import to Library&#8221; button. You should now see the 4 profiles as symbols in your Flash document Library (Window &gt; Library (cmd-L)).</p>
<p>Once you have your character profiles ready (either by using mine or creating your own), we will need to place them in a movie clip symbol in order to control the movement. On frame 1 of our main movie timeline, select &#8220;Insert &gt; New Symbol&#8221; (cmd-F8). This will bring up the &#8220;Create New Symbol&#8221; dialog box (Fig. 1). In the &#8220;Name&#8221; field, give your symbol an appropriate name (I chose &#8220;mc_character&#8221;, select the &#8220;Movie Clip&#8221; radial, and hit OK. This will automatically put you in the symbol editing mode for your new symbol. In your new symbol, create 2 new layers. Name the top layer &#8220;actions&#8221;, the second layer &#8220;labels&#8221; and the bottom layer &#8220;character&#8221;.</p>
<p><img src="http://www.spitshine-design.com/images/tutorials/tut9_fig1.gif" alt="" /></p>
<p>Extend your timeline to 20 frames. Select keyframe 5 for all 3 layers (you can shift click or click and drag), and insert a new keyframe (Insert &gt; Timeline &gt; Keyframe or F6). Do the same thing at frame 10 and 15. Click on keyframe 1 of our &#8220;labels&#8221; layer, and in the Properties window (Window &gt; Properties &gt; Properties or cmd-F3), give this frame a label of &#8220;right&#8221; (Fig. 2).</p>
<p><img src="http://www.spitshine-design.com/images/tutorials/tut9_fig2.gif" alt="" width="350" height="85" /></p>
<p>On frame 5, do the same thing, giving it a lable of &#8220;left&#8221;, frame 10 label &#8220;up&#8221;, frame 20 label &#8220;down&#8221;. Your timeline should now look similar to Fig. 3.</p>
<p><img src="http://www.spitshine-design.com/images/tutorials/tut9_fig3.gif" alt="" width="386" height="220" /></p>
<p>Note: Technically, we can make this movie clip only 4 frames, with frames 1-4 labeled the same as above. However, For the purposes of this tutorial, I felt it better to extend the frames in order to better illustrate the frame labels.</p>
<p>On frame 1 of your &#8220;character&#8221; layer, drag your right profile symbol to the stage and align it to the center. Tip: You can center align your symbols to the stage by using the Align palette (Window &gt; Align or cmd-K (Fig. 4). Be sure the &#8220;To Stage&#8221; button is selected (it will be a darker shade of grey when selected) to align your sybols to the stage, deselecting this button allows you to align multiple symbols to each other.</p>
<p><img src="http://www.spitshine-design.com/images/tutorials/tut9_fig4.gif" alt="" width="219" height="170" /></p>
<p>On frame 5 of your &#8220;character&#8221; layer, drag your left profile symbol to the stage and align it to the center. In case you haven&#8217;t figured it out, do the same thing at frame 10 with the back profile symbol and frame 15 with the front profile symbol.</p>
<p>The last step is to add the ActionScript to our movie clip symbol. On the &#8220;actions&#8221; layer, click on frame 1, and add the following code to the Action panel (WIndow &gt; Actions or alt-F9):</p>
<blockquote><p><span style="color: #000080;">stop();</span></p></blockquote>
<p>This simply stops our movie from playing through, since we only want it to change based on what key is pressed. Do the same thing at frame 5, 10, and 15 of our &#8220;actions&#8221; layer.</p>
<p>Our movie clip is now complete, so it&#8217;s time to add the ActionScript that will control our movement and the profile of our character.</p>
<p>Return to your main timeline. Drag your &#8220;mc_character&#8221; symbol from the library onto your stage. WIth your character selected, add the following code to the Actions panel:</p>
<blockquote><p><span style="color: #000080;">onClipEvent(enterFrame){</span><br />
<span style="color: #000080;">if(Key.isDown(Key.RIGHT)){</span><br />
<span style="color: #000080;">this._x += 5;</span><br />
<span style="color: #000080;">this.gotoAndStop(&#8220;right&#8221;);</span><br />
<span style="color: #000080;">}</span></p>
<p><span style="color: #000080;">if(Key.isDown(Key.LEFT)){</span><br />
<span style="color: #000080;">this._x -= 5;</span><br />
<span style="color: #000080;">this.gotoAndStop(&#8220;left&#8221;);</span><br />
<span style="color: #000080;">}</span></p>
<p><span style="color: #000080;">if(Key.isDown(Key.UP)){</span><br />
<span style="color: #000080;">this._y -= 5;</span><br />
<span style="color: #000080;">this.gotoAndStop(&#8220;up&#8221;);</span><br />
<span style="color: #000080;">}</span></p>
<p><span style="color: #000080;">if(Key.isDown(Key.DOWN)){</span><br />
<span style="color: #000080;">this._y += 5;</span><br />
<span style="color: #000080;">this.gotoAndStop(&#8220;down&#8221;);</span><br />
<span style="color: #000080;">}</span></p>
<p><span style="color: #000080;">}</span></p></blockquote>
<p><strong>UPDATE</strong>: I’ve been finding several readers having trouble with doing a straight copy/paste of this code from the Web. I believe the issue lies in the quotation marks (”). When copying from the Web, it sometimes uses “smartquotes”. If you are getting an error on test regarding the quote marks, first step is to be sure you are using regular quotes (type them in instead of copy/paste from the Web site). If you are still having problems, feel free to drop me a comment and I will try my best to help resolve your issues. &#8211; Mike</p>
<p>That&#8217;s it! Go ahead and test your movie. What you shoud see is when you click on the arrow keys, your character not only moves in that direction, but faces that direction as well (up being backwards, down being forwards).</p>
<p>Now, let me try and explain the code:</p>
<blockquote><p><span style="color: #000080;">onClipEvent(enterFrame){</span></p></blockquote>
<p>On ClipEvent refers to the movie clip which this code is added to, the &#8220;enterFrame&#8221; is saying everytime our movie enters this frame of our main timeline, peform the actions between the curly brackets.</p>
<blockquote><p><span style="color: #000080;">if(Key.isDown(Key.RIGHT)){</span></p></blockquote>
<p>when the right arrow key is pressed, perform the actions within the curly brackets.</p>
<blockquote><p><span style="color: #000080;">this._x += 5;</span></p></blockquote>
<p><span style="color: #000080;">this.</span> refers to the movie clip that this code is attached to. <span style="color: #000080;">_x</span> refers to the x position of this movie clip. If the right arrow is pressed, move the moviclip 5 pixels to the right (Tip: for faster movement, increase this number, for slower movement, decrease this number).</p>
<blockquote><p><span style="color: #000080;">this.gotoAndStop(&#8220;right&#8221;);</span><br />
<span style="color: #000080;">}</span></p></blockquote>
<p>Go to our frame labeled &#8220;right&#8221; in our movie clip symbol and stop on that frame. (Tip: Frame labels are case sensitive).</p>
<blockquote><p><span style="color: #000080;">if(Key.isDown(Key.LEFT)){</span><br />
<span style="color: #000080;">this._x -= 5;</span><br />
<span style="color: #000080;">this.gotoAndStop(&#8220;left&#8221;);</span><br />
<span style="color: #000080;">}</span></p></blockquote>
<p>This code is doing the same as above, but saying if the left arrow is pressed, move the clip 5 pixels to the left and go to our frame labeled &#8220;left&#8221;.</p>
<blockquote><p><span style="color: #000080;">if(Key.isDown(Key.UP)){</span><br />
<span style="color: #000080;">this._y -= 5;</span><br />
<span style="color: #000080;">this.gotoAndStop(&#8220;up&#8221;);</span><br />
<span style="color: #000080;">}</span></p></blockquote>
<p>This is doing the same as above, but saying if the up arrow is pressed, move the clip 5 pixels up (<span style="color: #000080;">_y</span> represents the y position of your clip) and go to our frame labeled &#8220;up&#8221;.</p>
<blockquote><p><span style="color: #000080;">if(Key.isDown(Key.DOWN)){</span><br />
<span style="color: #000080;">this._y += 5;</span><br />
<span style="color: #000080;">this.gotoAndStop(&#8220;down&#8221;);</span><br />
<span style="color: #000080;">} </span><br />
<span style="color: #000080;">}</span></p></blockquote>
<p>This is doing the same as above, but saying if the down arrow is pressed, move the clip 5 pixels down and to go our frame labeled &#8220;down&#8221;.</p>
<p>Thanks for reading, and I hope you found this tutorial useful. Source files are below, with commented code. As always, comments or questions are welcome. Check back soon for more expaned tutorials based on the idea of character movement.</p>
<p><strong>Source Files (Flash 8): </strong><a title="Flash Tutorial: Character Movement with Arrow Keys" href="http://mikestickney.com/wordpress/wp-content/uploads/2008/04/charMove_tut1.fla" >Flash Tutorial: Character Movement with Arrow Keys</a><strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://mikestickney.com/wordpress/flash-tutorial-character-movement-with-arrow-keys/feed/</wfw:commentRss>
		<slash:comments>90</slash:comments>
		</item>
		<item>
		<title>Flash Tutorial: Play a movie clip a set number of times and then stop</title>
		<link>http://mikestickney.com/wordpress/flash-tutorial-play-a-movie-clip-a-set-number-of-times-and-then-stop/</link>
		<comments>http://mikestickney.com/wordpress/flash-tutorial-play-a-movie-clip-a-set-number-of-times-and-then-stop/#comments</comments>
		<pubDate>Sat, 15 Mar 2008 18:57:51 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[ActionScript tutorials]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Tutorial]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[ActionsScript Tutorial]]></category>
		<category><![CDATA[design tutorial]]></category>
		<category><![CDATA[flash design; Movie Clip]]></category>
		<category><![CDATA[flash development]]></category>

		<guid isPermaLink="false">http://mikestickney.com/wordpress/flash-tutorial-play-a-movie-clip-a-set-number-of-times-and-then-stop/</guid>
		<description><![CDATA[Flash Tutorial: Stop a movie clip after playing 3 times
Level: This is an intermediate lesson, that focuses on the ActionScript involved. It is assumed the user has basic Flash knowledge that includes creating symbols, creating motion tweens and creating frame lables.
Version: I will be using Flash CS3 and AS2 (athough tut is compatible with earlier [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Flash Tutorial:</strong> Stop a movie clip after playing 3 times</p>
<p><strong>Level:</strong> This is an intermediate lesson, that focuses on the ActionScript involved. It is assumed the user has basic Flash knowledge that includes creating symbols, creating motion tweens and creating frame lables.</p>
<p><strong>Version: </strong>I will be using Flash CS3 and AS2 (athough tut is compatible with earlier versions of Flash) and instructions are for the Mac. Windows users would use the PC counterparts for specific instructions on Flash Menu/Shortcut instuctions.</p>
<p><strong>Description:</strong> In this Flash tutorial, I will demonstrate and explain the ActionScript involved to play a movie clip a certain number of times, and then stop playing. This tutorial focuse on the AS, so some basic Flash animation knowledge is assumed.</p>
<p><strong>Demo: </strong>
<object type="application/x-shockwave-flash" width="400" height="200">
<param name="movie" value="http://mikestickney.com/wordpress/wp-content/uploads/2008/03/playClip3Times.swf" />
<embed src="http://mikestickney.com/wordpress/wp-content/uploads/2008/03/playClip3Times.swf" type="application/x-shockwave-flash" width="400" height="200" >
</object>
</p>
<p><strong>Let&#8217;s get started!</strong></p>
<p>Select &#8220;File &gt; New&#8221; (command-&#8221;N&#8221;) and select Flash File (ActionScript 2.0) to open a new Flash document file. Save the file, and give it the appropriate name.<span id="more-21"></span>I will call this &#8220;clipDemo_tut1.fla&#8221;. Feel free to make the document dimensions whatever you like (&#8220;Modify &gt; Document or &#8220;command-J&#8221;), but I chose to use a size of 400 x 200 pixels. Create 3 layers and label the top one &#8220;actions&#8221; the second one &#8220;counter&#8221; and the bottom one &#8220;ball&#8221;.</p>
<p>The first thing we need to do is create a simple animation. For this tutorial, I simply created a circle that will move horizontally across the stage. I will assume the reader of this tutorial has some knowledge of creating a movie clip in Flash, so I will just walk through this quickly without much detailed instuction.</p>
<p align="center"><script type="text/javascript"><!--
google_ad_client = "pub-7252304256657784";
google_ad_slot = "4730110072";
google_ad_width = 234;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
<p>First, on the &#8220;ball&#8221; layer, draw a circle on the stage, and position against the left side. Select the cirlce and choose &#8220;Modify &gt; Convert to Symbol&#8221; (F8), give the symbol a name (I will use &#8220;mc_ball&#8221;) and choose the Movie Clip radial. Double click on the new symbol (either on the stage or in the Library), to bring you into editing mode. Click on the circle again to select it, and again choose &#8220;Modify &gt; Convert to Symbol&#8221; (F8), give your symbol a new name (I will use &#8220;img_ball&#8221;), and this time select the &#8220;Graphic&#8221; radial. Going back to your movie clip, add some frames to your timeline, however many you want, it doesn&#8217;t matter, I will make mine 35 frames long. Add a new keyframe to the layer with your circle. On the last frame of your movie, move the circle off to the right side of your stage. Select any frame between 1 and 35 and select &#8220;Insert &gt; Timeline &gt; Create Motion Tween&#8221;. You should now have a simple animation of the ball sliding across your stage.</p>
<p>
<object type="application/x-shockwave-flash" width="400" height="200">
<param name="movie" value="http://mikestickney.com/wordpress/wp-content/uploads/2008/03/stage1.swf" />
<embed src="http://mikestickney.com/wordpress/wp-content/uploads/2008/03/stage1.swf" type="application/x-shockwave-flash" width="400" height="200" >
</object>
</p>
<p>This is the animation we will use for this demonstration. Now it&#8217;s time to focus in on the purpose of this article, which is the ActionScript involved to make this movieclip play a certain number of times (3), and then stop.</p>
<p>In our &#8220;mc_ball&#8221; movie clip, add 2 layers to the timeline label the top one &#8220;actions&#8221; and the second one &#8220;labels&#8221;, and add a keyframe to the last frame of each layer. On frame 1 of the &#8220;labels&#8221; layer, in your property window, give this a frame label of &#8220;begin&#8221;, and on the last frame, give it a label of &#8220;end&#8221;. On the last frame of he &#8220;actions&#8221; layer, insert the following code in the actions panel (Windows &gt; Actions or alt-F9):</p>
<blockquote><p><font color="#000080">_root.counter += 1;</font></p>
<p><font color="#000080">if (_root.counter &gt;= 3) {<br />
_root.mc_ball.stop();<br />
}</font></p>
<p><font color="#000080">else {<br />
_root.mc_ball.gotoAndPlay(&#8220;begin&#8221;);<br />
}</font></p></blockquote>
<p>Don&#8217;t worry, I will explain the code later. For now, let&#8217;s continue with the tutorial.</p>
<p>Return to the main timeline (scene 1). Click on the cirlce movie clip on the stage and in the properties window, give this an instance name of &#8220;mc_ball&#8221;.</p>
<p>Still in our main timeline, on frame 1 of the &#8220;actions&#8221; layer, add the following code:</p>
<blockquote><p><font color="#000080">var counter = 0</font></p>
<p><font color="#000080">stop();</font></p></blockquote>
<p>Technically, we are now done with our movie. Go ahead and test it out&#8230; you should see the circle travel across the stage 3 times, and then stop (stop being a blank stage). However, let&#8217;s add some additional ActionScript to better demonstrate what the code is doing. The following instructions are optional and are used simply to better illustrate what is happening.</p>
<p>First thing we want to do is tell us how many times the movie clip played, so for that I will add a simple counter in the lower corner. In scene 1, on the &#8220;counter&#8221; layer that we created earlier, let&#8217;s just put a text box in the lower corner and type the word &#8220;counter&#8221;. Next to this text, with the &#8220;text tool&#8221;, draw a small text box, and in the properties manual, set the text type to &#8220;Dynamic&#8221; and in the &#8220;Var&#8221; field, type &#8220;counter&#8221;. Let&#8217;s also give it an instance name of &#8220;counter&#8221; (Fig. 1).</p>
<p><img src="http://www.spitshine-design.com/images/tutorials/tut4_fig1.gif" alt="Tutorial 4: Figure 1" height="85" width="400" /></p>
<p>Now, if we test our movie again, you should see a display of the number of times the animation has played in the bottom corner of the stage. The last thing we want to do is place a &#8220;replay&#8221; button on the so we can see the demonstration again.</p>
<p align="center"><script type="text/javascript"><!--
google_ad_client = "pub-7252304256657784";
google_ad_slot = "4730110072";
google_ad_width = 234;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
<p>Let&#8217;s add a new layer to our timeline and call it &#8220;Replay&#8221;. Below the &#8220;counter&#8221; text on the stage, let&#8217;s draw a text box and type the words &#8220;Demonstrate Again&#8221;. Note: be sure to change the &#8220;Text type&#8221; in our properties window back to &#8220;static&#8221;. Click on the text, select &#8220;Modify &gt; Convert to Symbol&#8221; (F8), and give this a name of &#8220;mc_reset&#8221; and be sure to select the &#8220;movie clip&#8221; radial. With our new symbol selected, let&#8217;s give this an instance name of &#8220;mc_reset&#8221;, and add the following code to the Actions Panel:</p>
<blockquote><p><font color="#000080">on (release) {<br />
_root.counter -= 3;<br />
_root.mc_ball.gotoAndPlay(&#8220;begin&#8221;);<br />
this.gotoAndPlay(&#8220;begin&#8221;);<br />
}</font></p></blockquote>
<p>Now, double click on the mc_reset symbol to bring us into the symbol editing mode and add 2 new layers, one named &#8220;actions&#8221; and one named &#8220;labels&#8221;. Let&#8217;s also add a new frame to all three layers. In the &#8220;actions&#8221; layer, add the following code to the Actions Panel on both frames:</p>
<blockquote><p><font color="#000080">stop();</font></p></blockquote>
<p>Now, in the &#8220;labels&#8221; layer, let&#8217;s label frame 1 &#8220;begin&#8221; and frame 2 end&#8221;. Lastly, let&#8217;s delete the content from frame 1 of our text layer so that we only see the &#8220;demonstrate again&#8221; on the seconcd frame.</p>
<p>Still with me? Don&#8217;t worry, we are almost done&#8230;</p>
<p>Go to your &#8220;mc_ball&#8221; symbol, and on the last frame in the &#8220;actions&#8221; layer in the Actions Panel, add the code in blue below to the existing code (the code in green is what was added previously:</p>
<blockquote>
<blockquote></blockquote>
<p><font color="#008000">_root.counter += 1;</font></p>
<p><font color="#000080"><font color="#008000">if (_root.counter &gt;= 3) {<br />
_root.mc_ball.stop();</font><br />
_root.mc_reset.gotoAndStop(&#8220;end&#8221;);</font><font color="#000080"><br />
<font color="#008000">  }</font></font></p>
<p><font color="#008000">else {<br />
_root.mc_ball.gotoAndPlay(&#8220;begin&#8221;);<br />
}</font></p>
<blockquote></blockquote>
</blockquote>
<p>Return to the main stage and test your movie. What you should now see is the counter increase by one each time the circle crosses the stage, and when it hits 3, it should stop, and the &#8220;demonstrate again&#8221; text should appear. When you click on this text, the counter should return to zero and the ball should travel across the screen again.</p>
<p>And that&#8217;s all, we are now done! What? You want to know what this code does? Ok&#8230; let me try to explain it:</p>
<p>Actions Scene 1, Frame 1:</p>
<blockquote><p><font color="#000080">var counter = 0</font></p></blockquote>
<p>This adds a varialbe called &#8220;counter&#8221; with a value of &#8220;0&#8243;.</p>
<p>Actions mc_ball, Final Frame:</p>
<blockquote><p><font color="#000080">_root.counter += 1;</font></p></blockquote>
<p>this says to add 1 to our variable called counter which we declared in scene 1</p>
<blockquote><p><font color="#000080">if (_root.counter &gt;= 3) {<br />
_root.mc_ball.stop();<br />
_root.mc_reset.gotoAndStop(&#8220;end&#8221;)<br />
}</font></p></blockquote>
<p>If the counter variable is greater than or equal to 3 (the number of times we want our clip to play), perform the actions between the curly brackets. The actions between the curly brackes are telling the &#8220;mc_ball&#8221; movie clip to stop playing, and it&#8217;s also telling the &#8220;mc_reset&#8221; clip (our Demonstrate Again button&#8230;) to go to the frame labeled &#8220;end&#8221;.</p>
<blockquote><p><font color="#000080">else {<br />
_root.mc_ball.gotoAndPlay(&#8220;begin&#8221;);<br />
}</font></p></blockquote>
<p>If the counter variable is NOT greater than or equall to zero (the requirements we asked for in the &#8220;if&#8221; statement above), perform the actions between the curly brackets. The actions between the curly brackets are telling our &#8220;mc_ball&#8221; movie clip to go back to the begining and play again.</p>
<p>Hopefully that helps explain things, and I&#8217;ve tried to comment the source file for everyone to make sure it&#8217;s clear. As always, I hope you found this tutorial helpful, and if you have any questions or comments please leave them below!</p>
<p>Source Files (Flash 8): <a href="http://mikestickney.com/wordpress/wp-content/uploads/2008/03/playClip3Times.fla"  title="Flash Button Tutorial: Source File">Flash Button Tutorial: Source File</a></p>
]]></content:encoded>
			<wfw:commentRss>http://mikestickney.com/wordpress/flash-tutorial-play-a-movie-clip-a-set-number-of-times-and-then-stop/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
