<?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>pixology &#187; actionscript</title>
	<atom:link href="http://www.pixologyinteractive.com/tag/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pixologyinteractive.com</link>
	<description>//creativity from the ground up</description>
	<lastBuildDate>Wed, 23 Sep 2009 16:56:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Adding a Scrollbar to a Dynamicly Populated Menu List in ActionScript 2.0</title>
		<link>http://www.pixologyinteractive.com/2009/06/adding-a-scrollbar-to-a-dynamicly-populated-menu-list-in-actionscript-2/</link>
		<comments>http://www.pixologyinteractive.com/2009/06/adding-a-scrollbar-to-a-dynamicly-populated-menu-list-in-actionscript-2/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 18:05:20 +0000</pubDate>
		<dc:creator>Erin Pierce</dc:creator>
				<category><![CDATA[develop]]></category>
		<category><![CDATA[interact]]></category>
		<category><![CDATA[teaching]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[actionscript 2.0]]></category>
		<category><![CDATA[dynamic menu]]></category>

		<guid isPermaLink="false">http://www.erinpierce.com/?p=234</guid>
		<description><![CDATA[Hello people. Yesterday I made a break through. I had been struggling for a few days, attempting to think through how on earth I was going to add a custom scrollbar to TWO dynamically populated menu lists. Well, I solved it. First I found the code I needed and a sample file on kirupa.com (they [...]]]></description>
			<content:encoded><![CDATA[<p>Hello people. Yesterday I made a break through. I had been struggling for a few days, attempting to think through how on earth I was going to add a custom scrollbar to TWO dynamically populated menu lists. Well, I solved it. First I found the code I needed and a sample file on <a href="http://www.kirupa.com/developer/flash8/scrollbar.htm" target="_blank">kirupa.com</a> (they rock btw).</p>
<p>Before the scrolling, I had an XML document with categories and projects. My code loaded the XML, parsed it and duplicated my menu item (nav button) using the <span class="Unicode">duplicateMovieClip()</span> method. I had it nested in a <span class="Unicode">for</span> loop and so it did all of the naming and depth placement at once. When you clicked on a menu item, a second function was called to populate the second list, passing through the category number and using the same <span class="Unicode">duplicateMovieClip()</span> method.</p>
<p>After looking at the way <a href="http://www.kirupa.com/" target="_blank">kirupa.com</a> set up the scrollbar file I realized I needed to put both of my menu lists into container movie clips. That way I would be able to get the <span class="Unicode">_y</span> and <span class="Unicode">_height</span> properties of the grouped nav buttons. I&#8217;ve been working a lot with AS 3.0 and needed a refresher in AS 2 on how to nest duplicated items inside a movie clip. I Googled and found <a href="http://www.actionscript.org/forums/showthread.php3?t=61711" target="_blank">this article on actionscript.org</a> reminding me you must use the <span class="Unicode">attachMovie()</span> method.</p>
<p>First I put both nav buttons into their own movie clips and call them: listOneHolder and listTwoHolder. Then I changed both <span class="Unicode">duplicateMovieClip()</span> methods to <span class="Unicode">attachMovie()</span>. Now the code looked like this:</p>
<blockquote><p><span class="Unicode">function loadXML(loaded)</span><br />
<span class="Unicode">{</span><br />
<span class="Unicode"> if (loaded)</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> xml = this.firstChild;</span><br />
<span class="Unicode"> totalSections = xml.childNodes.length;</span><br />
<span class="Unicode"> for (i = 0; i &lt; totalSections; i++)</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> //duplicateMovieClip(myNav, &#8216;myNav&#8217;+i, i + 10); //OLD duplicate nav buttons</span><br />
<span class="Unicode"> _root.listOneHolder.attachMovie(&#8216;myNav&#8217;, &#8216;myNav&#8217; + i, i + 10); //new attach movies</span></p>
<p><span class="Unicode"> setProperty(_root.listOneHolder['myNav'+i], _x, navX); //set the x property</span><br />
<span class="Unicode"> setProperty(_root.listOneHolder['myNav'+i], _y, navY); //set the y property</span></p>
<p><span class="Unicode"> _root.listOneHolder['myNav'+i].navTxt.htmlText = xml.childNodes[i].attributes.name; // set the text value</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode">}</span></p></blockquote>
<p>note: in addition to having my two menu item movie clips on the stage (myNav and btn), i made sure to right click on them in the library, select &#8220;Linkage&#8230;&#8221; and clicked &#8220;Export for ActionScript&#8221;.</p>
<p>after that i was able to start tackling the actual scrollbar issue. i figured out that i could use the code from <a href="http://www.kirupa.com/developer/flash8/scrollbar.htm" target="_blank">kirupa.com</a> (as seen below) and modify it to accommodate for my two lists.</p>
<blockquote><p><span class="Unicode">// KIRUPA //</span><br />
<span class="Unicode">function scrolling () {</span><br />
<span class="Unicode"> var scrollHeight:Number = theScrollbar.scrollTrack._height;</span><br />
<span class="Unicode"> var contentHeight:Number = contentMain._height;</span><br />
<span class="Unicode"> var scrollFaceHeight:Number = theScrollbar.scrollFace._height;</span><br />
<span class="Unicode"> var maskHeight:Number = maskedView._height;</span><br />
<span class="Unicode"> var initPosition:Number = theScrollbar.scrollFace._y=theScrollbar.scrollTrack._y;</span><br />
<span class="Unicode"> var initContentPos:Number = contentMain._y;</span><br />
<span class="Unicode"> var finalContentPos:Number = maskHeight-contentHeight+initContentPos;</span><br />
<span class="Unicode"> var left:Number = theScrollbar.scrollTrack._x;</span><br />
<span class="Unicode"> var top:Number = theScrollbar.scrollTrack._y;</span><br />
<span class="Unicode"> var right:Number = theScrollbar.scrollTrack._x;</span><br />
<span class="Unicode"> var bottom:Number = theScrollbar.scrollTrack._height-scrollFaceHeight+theScrollbar.scrollTrack._y;</span><br />
<span class="Unicode"> var dy:Number = 0;</span><br />
<span class="Unicode"> var speed:Number = 10;</span><br />
<span class="Unicode"> var moveVal:Number = (contentHeight-maskHeight)/(scrollHeight-scrollFaceHeight);</span><br />
<span class="Unicode"> </span><br />
<span class="Unicode"> theScrollbar.scrollFace.onPress = function() {</span><br />
<span class="Unicode"> var currPos:Number = this._y;</span><br />
<span class="Unicode"> startDrag(this, false, left, top, right, bottom);</span><br />
<span class="Unicode"> this.onMouseMove = function() {</span><br />
<span class="Unicode"> dy = Math.abs(initPosition-this._y);</span><br />
<span class="Unicode"> contentMain._y = Math.round(dy*-1*moveVal+initContentPos);</span><br />
<span class="Unicode"> };</span><br />
<span class="Unicode"> };</span><br />
<span class="Unicode"> theScrollbar.scrollFace.onMouseUp = function() {</span><br />
<span class="Unicode"> stopDrag();</span><br />
<span class="Unicode"> delete this.onMouseMove;</span><br />
<span class="Unicode"> };</span><br />
<span class="Unicode"> theScrollbar.btnUp.onPress = function() {</span><br />
<span class="Unicode"> this.onEnterFrame = function() {</span><br />
<span class="Unicode"> if (contentMain._y+speed</span><br />
<span class="Unicode"> if (theScrollbar.scrollFace._y&lt;=top) {</span><br />
<span class="Unicode"> theScrollbar.scrollFace._y = top;</span><br />
<span class="Unicode"> } else {</span><br />
<span class="Unicode"> theScrollbar.scrollFace._y -= speed/moveVal;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> contentMain._y += speed;</span><br />
<span class="Unicode"> } else {</span><br />
<span class="Unicode"> theScrollbar.scrollFace._y = top;</span><br />
<span class="Unicode"> contentMain._y = maskedView._y;</span><br />
<span class="Unicode"> delete this.onEnterFrame;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> };</span><br />
<span class="Unicode"> };</span><br />
<span class="Unicode"> theScrollbar.btnUp.onDragOut = function() {</span><br />
<span class="Unicode"> delete this.onEnterFrame;</span><br />
<span class="Unicode"> };</span><br />
<span class="Unicode"> theScrollbar.btnUp.onRelease = function() {</span><br />
<span class="Unicode"> delete this.onEnterFrame;</span><br />
<span class="Unicode"> };</span><br />
<span class="Unicode"> theScrollbar.btnDown.onPress = function() {</span><br />
<span class="Unicode"> this.onEnterFrame = function() {</span><br />
<span class="Unicode"> if (contentMain._y-speed&gt;finalContentPos) {</span><br />
<span class="Unicode"> if (theScrollbar.scrollFace._y&gt;=bottom) {</span><br />
<span class="Unicode"> theScrollbar.scrollFace._y = bottom;</span><br />
<span class="Unicode"> } else {</span><br />
<span class="Unicode"> theScrollbar.scrollFace._y += speed/moveVal;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> contentMain._y -= speed;</span><br />
<span class="Unicode"> } else {</span><br />
<span class="Unicode"> theScrollbar.scrollFace._y = bottom;</span><br />
<span class="Unicode"> contentMain._y = finalContentPos;</span><br />
<span class="Unicode"> delete this.onEnterFrame;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> };</span><br />
<span class="Unicode"> };</span><br />
<span class="Unicode"> theScrollbar.btnDown.onRelease = function() {</span><br />
<span class="Unicode"> delete this.onEnterFrame;</span><br />
<span class="Unicode"> };</span><br />
<span class="Unicode"> theScrollbar.btnDown.onDragOut = function() {</span><br />
<span class="Unicode"> delete this.onEnterFrame;</span><br />
<span class="Unicode"> };</span><br />
<span class="Unicode"> </span><br />
<span class="Unicode"> if (contentHeight</span><br />
<span class="Unicode"> theScrollbar.scrollFace._visible = false;</span><br />
<span class="Unicode"> theScrollbar.btnUp.enabled = false;</span><br />
<span class="Unicode"> theScrollbar.btnDown.enabled = false;</span><br />
<span class="Unicode"> } else {</span><br />
<span class="Unicode"> theScrollbar.scrollFace._visible = true;</span><br />
<span class="Unicode"> theScrollbar.btnUp.enabled = true;</span><br />
<span class="Unicode"> theScrollbar.btnDown.enabled = true;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode">};</span></p></blockquote>
<p>In order to accommodate for my two lists I needed to modify the function to have a few parameters passed through &#8230; those were the scrollbar instance (i put two on my stage, one for each list), the mask instance (again, two on each stage, one for each list), and the list. So my new function looked like this:</p>
<blockquote><p><span class="Unicode">function goScrolling (_mc, mask_mc, listHolder_mc)</span><br />
<span class="Unicode">{</span><br />
<span class="Unicode"> var scrollHeight:Number = _mc.scrollTrack._height;</span><br />
<span class="Unicode"> var contentHeight:Number = listHolder_mc._height;</span><br />
<span class="Unicode"> var scrollFaceHeight:Number = _mc.scrollFace._height;</span><br />
<span class="Unicode"> var maskHeight:Number = mask_mc._height;</span><br />
<span class="Unicode"> var initPosition:Number = _mc.scrollFace._y = _mc.scrollTrack._y;</span><br />
<span class="Unicode"> var initContentPos:Number = listHolder_mc._y;</span><br />
<span class="Unicode"> var finalContentPos:Number = maskHeight &#8211; contentHeight + initContentPos;</span><br />
<span class="Unicode"> var left:Number = _mc.scrollTrack._x;</span><br />
<span class="Unicode"> var top:Number = _mc.scrollTrack._y;</span><br />
<span class="Unicode"> var right:Number = _mc.scrollTrack._x;</span><br />
<span class="Unicode"> var bottom:Number = _mc.scrollTrack._height &#8211; scrollFaceHeight + _mc.scrollTrack._y;</span><br />
<span class="Unicode"> var dy:Number = 0;</span><br />
<span class="Unicode"> var speed:Number = 10;</span><br />
<span class="Unicode"> var moveVal:Number = (contentHeight &#8211; maskHeight) / (scrollHeight-scrollFaceHeight);</span><br />
<span class="Unicode"> </span><br />
<span class="Unicode"> _mc.scrollFace.onPress = function()</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> var currPos:Number = this._y;</span><br />
<span class="Unicode"> startDrag(this, false, left, top, right, bottom);</span><br />
<span class="Unicode"> this.onMouseMove = function() </span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> dy = Math.abs(initPosition &#8211; this._y);</span><br />
<span class="Unicode"> listHolder_mc._y = Math.round(((dy * -1) * moveVal) + initContentPos);</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> _mc.scrollFace.onMouseUp = function()</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> stopDrag();</span><br />
<span class="Unicode"> delete this.onMouseMove;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> _mc.btnUp.onPress = function()</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> this.onEnterFrame = function()</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> if (listHolder_mc._y + speed &lt; mask_mc._y)</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> if (_mc.scrollFace._y &lt;= top)</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> _mc.scrollFace._y = top;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> else</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> _mc.scrollFace._y -= speed / moveVal;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> listHolder_mc._y += speed;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> else</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> _mc.scrollFace._y = top;</span><br />
<span class="Unicode"> listHolder_mc._y = mask_mc._y;</span><br />
<span class="Unicode"> delete this.onEnterFrame;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> _mc.btnUp.onDragOut = function()</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> delete this.onEnterFrame;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> _mc.btnUp.onRelease = function()</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> delete this.onEnterFrame;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> _mc.btnDown.onPress = function()</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> this.onEnterFrame = function()</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> if ((listHolder_mc._y &#8211; speed) &gt; finalContentPos)</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> if (_mc.scrollFace._y &gt;= bottom)</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> _mc.scrollFace._y = bottom;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> else</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> _mc.scrollFace._y += speed / moveVal;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> listHolder_mc._y -= speed;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> else</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> _mc.scrollFace._y = bottom;</span><br />
<span class="Unicode"> listHolder_mc._y = finalContentPos;</span><br />
<span class="Unicode"> delete this.onEnterFrame;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> _mc.btnDown.onRelease = function()</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> delete this.onEnterFrame;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> _mc.btnDown.onDragOut = function()</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> delete this.onEnterFrame;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> </span><br />
<span class="Unicode"> if (contentHeight &lt; maskHeight)</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> _mc._visible = false;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode"> else</span><br />
<span class="Unicode"> {</span><br />
<span class="Unicode"> _mc._visible = true;</span><br />
<span class="Unicode"> }</span><br />
<span class="Unicode">}</span></p></blockquote>
<p>Once I had that modified, I needed to figure out when to call the function. First I called it right away. The first menu populates and at the end of my XML loader function I call the scrolling function to check to see if either list needs a scrollbar. Then, once one of the categories is selected (from list one), I needed to call the scrolling function again, checking to see if list two needs a scrollbar.</p>
<p>So, the first time I call it, inside my XML loader function, I am passing through the scrollbar for list one, the mask for list one and list one mc:</p>
<blockquote><p><span class="Unicode">goScrolling(_root.theScrollbar1, _root.maskedView1, _root.listOneHolder);</span></p></blockquote>
<p>The second time I call the function, inside my XML loader function, inside the onRelease function for my main menu (list one) nav i pass through the second list, mask and scrollbar:</p>
<blockquote><p><span class="Unicode">_root.listOneHolder['myNav'+i].onRelease = function ()</span><br />
<span class="Unicode">{</span><br />
<span class="Unicode"> goScrolling(_root.theScrollbar2, _root.maskedView2, _root.listTwoHolder);</span><br />
<span class="Unicode">}</span></p></blockquote>
<p>I then had two functioning scrollbars! However, I have run into two problems &#8230; one of which I have solved, the other won&#8217;t take long but I have not yet done. I clicked on one of the main menu items. List two was long enough to have a scrollbar and I then scrolled to the bottom and selected one of the projects (or secondary menu items). When I went to another category, I realized list two did not reset itself. The <span class="Unicode">_y</span> property was still at the same value, as if I had used the scrollbar. SO. I added to the end of the scrolling function a short bit of logic:</p>
<blockquote><p><span class="Unicode">// the number 55 represents the starting _y value</span><br />
<span class="Unicode">if (initContentPos &lt; 55)</span><br />
<span class="Unicode">{</span><br />
<span class="Unicode"> listHolder_mc._y = 55;</span><br />
<span class="Unicode">}</span></p></blockquote>
<p>Here&#8217;s a <a href="http://www.erinpierce.com/clients/ae" target="_blank">link to the project</a> as it is today. The second issue I found has to do with the mathematical calculation of height and/or how far down the scroll bar needs to go. The scroll current goes too far down, or rather, sets the <span class="Unicode">_y</span> property too low. So now I am off to fix that. I&#8217;ll post in the comments the solution when I have it.</p>
<p>Good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.pixologyinteractive.com/2009/06/adding-a-scrollbar-to-a-dynamicly-populated-menu-list-in-actionscript-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Building a simple website using ActionScript 3.0</title>
		<link>http://www.pixologyinteractive.com/2009/02/building-a-simple-website-using-actionscript-30/</link>
		<comments>http://www.pixologyinteractive.com/2009/02/building-a-simple-website-using-actionscript-30/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 16:34:58 +0000</pubDate>
		<dc:creator>Erin Pierce</dc:creator>
				<category><![CDATA[develop]]></category>
		<category><![CDATA[teaching]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[actionscript 3.0]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flash website]]></category>
		<category><![CDATA[flash website tutorial]]></category>
		<category><![CDATA[simple actionscript 3.0 tutorial]]></category>

		<guid isPermaLink="false">http://www.erinpierce.com/?p=105</guid>
		<description><![CDATA[This is a tutorial on how to make a four &#8220;page&#8221; website.
1. Open a new Flash file (AS 3.0).
2. First we&#8217;ll make our four buttons. Draw a rectangle on the stage. I set my x and y coordinates to be at 25.
figure 1

3. Turn the shape into a movie clip. Double click to select the [...]]]></description>
			<content:encoded><![CDATA[<p>This is a tutorial on how to make a four &#8220;page&#8221; website.</p>
<p>1. Open a new Flash file (AS 3.0).</p>
<p>2. First we&#8217;ll make our four buttons. Draw a rectangle on the stage. I set my x and y coordinates to be at 25.</p>
<p><strong>figure 1</strong><br />
<img class="alignnone size-full wp-image-65" title="rectangle" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-2.png" alt="rectangle" /></p>
<p>3. Turn the shape into a movie clip. Double click to select the shape, press F8 (or right click and Convert to Symbol), name it &#8220;navbg_mc&#8221;, and hit OK.</p>
<p><strong>figure 2</strong><br />
<img class="alignnone size-full wp-image-66" title="picture-4" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-4.png" alt="picture-4" /></p>
<p>4. Now we&#8217;ll create three more instances of this movie clip object. To align them we can select all, hit Command <span class="Unicode">(</span><span class="Unicode">⌘) + K to open our Align panel (or Window &gt; Align), then click &#8220;Align left edge&#8221; (figure 4: circled in red). You may need to reposition the x coordinate of the rectangles on the stage to 25. Next, click &#8220;Distribute vertical center&#8221; (figure 4: circled in blue). This will distribute all of the items evenly between the first (top) and last (bottom) item.</span></p>
<p><strong>figure 3</strong><br />
<img class="alignnone size-full wp-image-67" title="picture-3" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-3.png" alt="picture-3" /></p>
<p><strong>figure 4</strong><br />
<img class="alignnone size-full wp-image-68" title="picture-21" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-21.png" alt="picture-21" /></p>
<p>5. Title the layer &#8220;nav bkgnd&#8221; for navigation background.<br />
6. Add a new layer and title it &#8220;nav txt&#8221; for the navigation text and lock the nav bkgnd layer.</p>
<p><strong>figure 5</strong><br />
<img class="alignnone size-full wp-image-70" title="picture-41" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-41.png" alt="picture-41" /></p>
<p>7. Now add text for each of the navigational buttons. Be sure your text boxes are on whole pixels. This will be important when we publish our movie. The text may appear blurry if it sits on a partial pixel (i.e. if x was equal to 25.5).</p>
<p><strong>figure 6</strong><br />
<img class="alignnone size-full wp-image-72" title="picture-6" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-6.png" alt="picture-6" /></p>
<p>8. Unlock the nav bkgnd layer. We are now going to turn these into individual movie clips, but first, give each rectangle (instance of navbg_mc) an instance name of &#8220;navbg&#8221;.</p>
<p><strong>figure 7</strong><br />
<img class="alignnone size-full wp-image-75" title="picture-8" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-8.png" alt="picture-8" /></p>
<p>9. Now that we have done that we can select each rectangle and the text corresponding and create our movie clips. Select the home text and the rectangle underneath. Convert it into a Movie Clip Symbol (F8 or right click, Convert to Symbol). Name it nav_home_mc. Repeat this for each item, naming them appropriately (nav_about_mc, nav_services_mc, nav_contact_mc).</p>
<p><strong>figure 8</strong><br />
<img class="alignnone size-full wp-image-76" title="picture-10" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-10.png" alt="picture-10" /></p>
<p>10. We can now delete the layer we are no longer using and rename the one with all of our buttons: nav buttons.<br />
11. Out on frame 25, add a frame (F5 or right click &gt; Insert Frame).</p>
<p><strong>figure 9</strong><br />
<img class="alignnone size-full wp-image-78" title="picture-11" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-11.png" alt="picture-11" /></p>
<p>12. For each nav item, give it an instance name. Start with the home nav button and name it: home_btn<br />
Do the same for every button (about_btn, services_btn, contact_btn).</p>
<p><strong>figure 10</strong><br />
<img class="alignnone size-full wp-image-94" title="picture-71" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-71.png" alt="picture-71" width="308" height="260" /></p>
<p>13. Lock the nav buttons layer then create a new layer and title it: home content.<br />
14. Add two more layers. Title the top one &#8220;actions&#8221; and the middle one &#8220;labels&#8221;. These will be used for our ActionScript and our timeline markers for each section.</p>
<p><strong>figure 11</strong><br />
<img class="alignnone size-full wp-image-79" title="picture-12" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-12.png" alt="picture-12" /></p>
<p>15. On frames 8, 17 and 25 insert blank keyframes on the actions and labels layers.</p>
<p><strong>figure 12</strong><br />
<img class="alignnone size-full wp-image-80" title="picture-22" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-22.png" alt="picture-22" /></p>
<p>16. Lock the actions layer.<br />
17. We now need to label our sections. First, on frame 1, we will name this section &#8220;home&#8221;. Click on the first frame on the labels layer. Then, down in the properties panel you&#8217;ll find a place to define the Frame Label.</p>
<p><strong>figure 13</strong><br />
<img class="alignnone size-full wp-image-82" title="picture-31" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-31.png" alt="picture-31" /></p>
<p>18. Give it a label of &#8220;home&#8221;. Then go to frame 8 and label it &#8220;about&#8221;; frame 17 label &#8220;services&#8221;; frame 25 label &#8220;contact&#8221;.</p>
<p><strong>figure 14</strong><br />
<img class="alignnone size-full wp-image-83" title="picture-42" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-42.png" alt="picture-42" /></p>
<p>19. So because we will need Flash to stop at each of these sections, we need to add a stop action (<code>stop();)</code> for each. Press Control + F9 or go to Window &gt; Actions to pull up your ActionScript panel. In the actions layer on each of the blank keyframes type into your ActionScript Panel the stop action.</p>
<p><strong>figure 15</strong><br />
<img class="alignnone size-full wp-image-86" title="picture-13" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-13.png" alt="picture-13" /></p>
<p>20. Now we need some elements for each section. Lock all the layers and create a new layer in between layers nav buttons and labels and title it: home content.<br />
21. On the home content layer, add a title and body content.</p>
<p><strong>figure 16</strong><br />
<img class="alignnone size-full wp-image-87" title="picture-23" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-23.png" alt="picture-23" /></p>
<p>22. Select both text items, create a new movie clip symbol (F8 or right click, Convert to Symbol). Name the movie clip: home_content<br />
23. Insert a blank keyframe on the 2nd frame.</p>
<p><strong>figure 17</strong><br />
<img class="alignnone size-full wp-image-88" title="picture-32" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-32.png" alt="picture-32" /></p>
<p>24. In your library panel, find the movie clip you just created and duplicate the symbol, renaming it to: about_content<br />
25. Double click on the about_content movie clip. Change the title to ABOUT.<br />
26. Go back to the main timeline by clicking on Scene 1.</p>
<p><strong>figure 18</strong><br />
<img class="alignnone size-full wp-image-90" title="picture-44" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-44.png" alt="picture-44" /></p>
<p>27. We now need to create another layer and name it: about content<br />
28. Insert a blank keyframe on the same frame as our &#8220;about&#8221; label (frame 8).<br />
29. Drag the new about_content movie clip onto the stage.<br />
30. Insert a blank keyframe on frame 9.</p>
<p><strong>figure 19</strong><br />
<img class="alignnone size-full wp-image-91" title="picture-5" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-5.png" alt="picture-5" /></p>
<p>31. Repeat steps 24 through 30 for both of the remaining sections.</p>
<p><strong>figure 20</strong><br />
<img class="alignnone size-full wp-image-92" title="picture-61" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-61.png" alt="picture-61" /></p>
<p>32. Now for the good stuff! Click on the first frame on our actions layer. We now need to tell Flash what we want to happen when the user clicks on one of our buttons.<br />
33. Since we are going to use our movie clips as buttons, we need to tell each of these instances to be buttons. (change each)</p>
<p><strong>figure 21</strong><br />
<img class="alignnone size-full wp-image-96" title="picture-14" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-14.png" alt="picture-14" width="423" height="345" /></p>
<p>34. In the Actions panel, type:</p>
<p><code>import flash.display.MovieClip;</code></p>
<p>This will allow us to give actions to the movie clips on our stage. You really don&#8217;t need to know anything more than it is necessary to have at the top of your code.</p>
<p>35. Now to create the function that will navigate us to the proper sections when we click one of the buttons. Type this into your Actions panel (on that same frame, frame 1 of the main timeline).</p>
<p><code>function clickHome (event:MouseEvent):void {</code><br />
<code> trace("home button clicked");<br />
</code><code>};</code></p>
<p>36. Now that we have a function that will tell us when the home button is clicked, we need to link it to the actual click event. In order to do that we need to add above our function a line of code. This line of code will add an event listener to the home button and call our clickHome() function when it is clicked.</p>
<p><code>home_btn.addEventListener(MouseEvent.CLICK, clickHome);</code></p>
<p><code>function clickHome (event:MouseEvent):void {</code><br />
<code> trace("home button clicked");</code><br />
<code>};</code></p>
<p>37. Let&#8217;s test the movie and click the home button.</p>
<p><strong>figure 22</strong><br />
<img class="alignnone size-full wp-image-101" title="picture-45" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-45.png" alt="picture-45" width="512" height="343" /></p>
<p>38. It worked!</p>
<p>39. Okay so now we need to be able to do this for every one of the buttons. So we need to create a function for each section and add the call on the CLICK event:</p>
<p><code>about_btn.addEventListener(MouseEvent.CLICK, clickAbout);</code></p>
<p><code>function clickAbout (event:MouseEvent):void {</code><br />
<code> trace("about button clicked");</code><br />
<code>};</code></p>
<p><strong>figure 23</strong><br />
<img class="alignnone size-full wp-image-102" title="picture-62" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-62.png" alt="picture-62" /></p>
<p>40. Test your movie again. Notice now you get results every time you click one of the buttons?</p>
<p>41. From here we need to tell it what to do when we click on a button. Currently it just gives us a <code>trace();</code> to let us know it is working. But what we need is to tell it to go to the specific sections, which is where <code>gotoAndStop();</code> comes in! In between the curly brackets (&#8220;{&#8221; and &#8220;}&#8221;) in our clickAbout() function type:</p>
<p><code>gotoAndStop('about');</code></p>
<p>The function should now look like this:</p>
<p><code>function clickAbout (event:MouseEvent):void {</code><br />
<code> trace("about button clicked");</code><br />
<code> gotoAndStop('about');</code><br />
<code>};</code></p>
<p>If you remember, we labeled our sections on the timeline using the Frame Label in our Properties panel. These are now coming in handy. For each of our functions we need to tell it to go to the specific sections.</p>
<p><strong>figure 24</strong><br />
<img class="alignnone size-full wp-image-103" title="picture-72" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-72.png" alt="picture-72" /></p>
<p>42. Test your movie. You have just completed creating a simple Flash website!</p>
<p><a href="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/website.zip">Download finished files</a></p>
<p><strong>Addendum:<br />
</strong>Change your button instance names to match that of the labels for each section: take off the &#8220;_btn&#8221;. The code below will use the instance names of each button in order to find the corresponding frame label and navigate there.</p>
<p><code>stop();</code></p>
<p><code>import flash.display.MovieClip;</code></p>
<p><code>home.addEventListener(MouseEvent.CLICK, gotoMySection);</code><br />
<code>about.addEventListener(MouseEvent.CLICK, gotoMySection);</code><br />
<code>services.addEventListener(MouseEvent.CLICK, gotoMySection);</code><br />
<code>contact.addEventListener(MouseEvent.CLICK, gotoMySection);</code></p>
<p><code>// this function takes user to specified section or frame label</code><br />
<code>function gotoMySection (event:MouseEvent):void {</code></p>
<p><code>gotoAndStop(event.target.name);</code></p>
<p><code> trace(event.target.name + " was clicked");</code></p>
<p><code>};</code></p>
<p><a href="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/website_addendum.zip">Download these files w/ updated code</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pixologyinteractive.com/2009/02/building-a-simple-website-using-actionscript-30/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ActionScript Basics: Terms Defined</title>
		<link>http://www.pixologyinteractive.com/2009/02/actionscript-basics-terms-defined/</link>
		<comments>http://www.pixologyinteractive.com/2009/02/actionscript-basics-terms-defined/#comments</comments>
		<pubDate>Tue, 10 Feb 2009 16:26:47 +0000</pubDate>
		<dc:creator>Erin Pierce</dc:creator>
				<category><![CDATA[develop]]></category>
		<category><![CDATA[teaching]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[actionscript 3.0]]></category>
		<category><![CDATA[adobe flash]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[simple actionscript 3.0 tutorial]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.erinpierce.com/?p=101</guid>
		<description><![CDATA[Terms, defined
There are some terms, some of which we have covered, that will be useful to have a general and basic understanding of.

Instances &#38; Instance Names
When we create symbols, existing in the Library and drag them onto the stage, we create an instance of that symbol. If we will be referencing an instance in our [...]]]></description>
			<content:encoded><![CDATA[<h3>Terms, defined</h3>
<p>There are some terms, some of which we have covered, that will be useful to have a general and basic understanding of.</p>
<ol>
<li><strong>Instances &amp; Instance Names</strong><br />
When we create symbols, existing in the Library and drag them onto the stage, we create an <em>instance</em> of that symbol. If we will be referencing an instance in our ActionScript, we must name that instance. You name your instances in the Properties Panel.<br />
<img class="alignnone size-full wp-image-35" title="picture-1" src="http://www.erinpierce.com/teaching/4210/wp-content/uploads/2009/02/picture-1.png" alt="picture-1" width="489" height="499" /></li>
<li><strong>Statements</strong><br />
A statement is like a sentence only rather than the expression ending with a period it ends with a semi-colon (&quot;;&quot;). Example:<br />
<code>var theDog;</code></li>
<li><strong>Variables &amp; Data Types</strong><br />
Variables are containers; they are vessels used to store various bits of information. There are many types of data. Here are a few:</p>
<p><strong>Number</strong><br />
These can be positive, negative, integer or decimal (floating point) numbers.</p>
<p><code>var myAge:Number = 52;</code></p>
<p><code>//comments are indicated by using two slashes ... these are good to use. they will help you remember what a line of code means</code></p>
<p><code>/*<br />
if you will be writing extra, you<br />
can use a slash + a star and that will<br />
give you the ability to comment a longer<br />
description or block of code<br />
<br />*/</code></p>
<p><strong>Boolean (true/false)</strong><br />
<code>var myStatement:Boolean = false;</code></p>
<p><strong>String</strong><br />
<code>var myName:String = &quot;Bob Saget&quot;; // set value of the myName variable equal to Bob Saget</code></p>
<blockquote><p>NOTE: The way in which data is stored is very important. For example, these are not equal:</p>
<p><code><br />
var myAge:Number = 52;<br />
var myAge:String = &quot;52&quot;;<br />
</code></p></blockquote>
</li>
<li><strong>Functions</strong><br />
Functions allow for reusing a block of code.</p>
<p><code>function myFirstFunction() {</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trace(&quot;hello&quot;);</code><br />
<code>};</code><br />
<code>myFirstFunction();</code></p>
<p>Many functions are built into Flash. <code>trace();</code> <code>stop();</code> and <code>gotoAndPlay();</code> are three of the most common.</li>
<li><strong>If Statements</strong>
<p>An if statement is a conditional statement&#8230;if you&#8217;ve ever taken a logic class, these are similar type statements&#8230;<br />
First, write out what you&#8217;d like to check:</p>
<p><code>// if the x property of the dog movie clip is equal to 50, then trace &quot;x equals 50&quot;</p>
<p></code><br />
<code>if (dog_mc.x == 50) {</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trace(&quot;x equals 50&quot;);</code><br />
<code>}</code></p>
<p>You can also have it do something else if the condition is not true using if / else statement.</p>
<p><code>// if the x property of the dog movie clip is equal to 50, then trace &quot;x equals 50&quot;, otherwise, trace &quot;x does not equal 50&quot;</p>
<p></code><br />
<code>if (dog_mc.x == 50) {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trace(&quot;x equals 50&quot;);<br />
} else {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trace(&quot;x does not equal 50&quot;);<br />
}</code></li>
<li><b>Operators</b><br />
The double equal sign (==) in our if statement is called an Operator. Operators tell the statement how to compare the two variables. Here are some other operators and their descriptions:</p>
<table cellpadding=&quot;3&quot;>
<tr bgcolor=&quot;#EEEEEE&quot;>
<td width=&quot;114&quot;><strong>Operator</strong></td>
<td width=&quot;244&quot;><strong>Description</strong></td>
</tr>
<tr>
<td>==</td>
<td>equals</td>
</tr>
<tr bgcolor=&quot;#EEEEEE&quot;>
<td>!=</td>
<td>does not equal</td>
</tr>
<tr>
<td>></td>
<td>greater than</td>
</tr>
<tr bgcolor=&quot;#EEEEEE&quot;>
<td>>=</td>
<td>greater than or equal to</td>
</tr>
<tr>
<td>< </td>
</td>
<td>less than</td>
</tr>
<tr bgcolor=&quot;#EEEEEE&quot;>
<td>< =</td>
</td>
<td>less than or equal to</td>
</tr>
<tr>
<td>&amp;&amp;</td>
<td>and*</td>
</tr>
<tr bgcolor=&quot;#EEEEEE&quot;>
<td>||</td>
<td>or*</td>
</tr>
</table>
<p>*Here are examples of how you would use the &amp;&amp; and || operators:</p>
<p><strong>AND Operator: &amp;&amp;</strong><br />
<code>// if the x property of dog mc is equal to 50 AND the y property is equal to 50, trace &quot;x and y equal 50&quot;</code></p>
<p><code>if ( (dog_mc.x == 50) &#038;&#038; (dog_mc.y == 50) ) {</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trace(&quot;x and y equal 50&quot;);</code><br />
<code>}</code></p>
<p><strong>OR Operator: ||</strong><br />
<code>// if the x property of dog mc is equal to 50 OR the x property is equal to 100, trace &quot;x equals 50 or 100&quot;</code></p>
<p><code>if ( (dog_mc.x == 50) || (dog_mc.x == 100) ) {</code><br />
<code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trace(&quot;x equals 50 or 100&quot;);</code><br />
<code>}</code>
</li>
<li><b>Loops</b><br />
Loops are used to execute a specific set of items a specific amount of times. There are several types of loops, the most common of which is the For loop. </p>
<p><code>for ( var i:Number = 1; i < = 10; i++ ) {</code><br />
</code><code>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trace(i);</code><br />
<code>}</code></p>
<p>The first item in the for loop is establishing the counter. We have to declare the variable (<code>var i</code>), the variable type (<code>:Number</code>) and give it a value (<code> = 1;)</code>. This will be the beginning or starting value of the counter.</p>
<p>Next we need to establish the condition. How many times does the for loop need to run? So we state the the variable <code>i</code> is less than or equal to 10.</p>
<p>The final piece in the for loop is the action. This tells the loop whether to increase (<code>i++</code>) or decrease (<code>i--</code>). Most often you will only need to increase.</p>
<p>Try changing the initial counter number, the final number or the action&#8230;see what happens!
</li>
</ol>
<h3>Resources</h3>
<p><a href="http://www.flashperfection.com/tutorials/Variables-Data-Types-Classes-Properties-And-Methods-In-AS3-19996.html" target="_blank">Variables &amp; Data Types</a><br />
<a href="http://www.flashperfection.com/tutorials/Using-Functions-in-ActionScript-3.0-91749.html" target="_blank">Functions</a><br />
<a href="http://www.flashperfection.com/tutorials/Using-Loops-in-AS3-26532.html" target="_blank">For Loops</a><br />
<a href="http://www.gotoandlearn.com/" target="_blank">General tutorials</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.pixologyinteractive.com/2009/02/actionscript-basics-terms-defined/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
