<?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>Theme Heven &#187; Flash AS</title>
	<atom:link href="http://www.themeheven.com/category/tutorial/flash-as/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.themeheven.com</link>
	<description>WordPress, Ajax, Jquery, Web 2.0, PHP, Tutorials, Tips, Tricks</description>
	<lastBuildDate>Wed, 13 Jan 2010 09:37:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Create a MovieClip Rotating around the Center Continiously</title>
		<link>http://www.themeheven.com/2009/08/how-to-create-a-movieclip-rotating-around-the-center-continiously/</link>
		<comments>http://www.themeheven.com/2009/08/how-to-create-a-movieclip-rotating-around-the-center-continiously/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 09:30:37 +0000</pubDate>
		<dc:creator>themeheven</dc:creator>
				<category><![CDATA[Flash AS]]></category>
		<category><![CDATA[Rotate Circle]]></category>

		<guid isPermaLink="false">http://www.themeheven.com/?p=256</guid>
		<description><![CDATA[This  article explain you how to create an object which rotate around the center continiously. In this tutorial you will learn more about the center and math, sine/cos/degrees/radians. Here I am going to explain you with the action script:
First Create an object of any shape which you want to rotate around the circle. And [...]]]></description>
			<content:encoded><![CDATA[<p>This  article explain you how to create an object which rotate around the center continiously. In this tutorial you will learn more about the center and math, sine/cos/degrees/radians. Here I am going to explain you with the action script:</p>
<p>First Create an object of any shape which you want to rotate around the circle. And give a instance name for the object. In this example I have used a circle shape having circ instance name &amp; I will describe you using the same instance name in this tutorial.</p>
<p>Here I want to start right now. First I will divide the stage from X &amp; Y by 2 show that I can find the center position of the stage.</p>
<p>circ.centerX = Stage.width / 2;</p>
<p>circ.centerY = Stage.height / 2;</p>
<p>Now set the starting point on the circle, in degrees.</p>
<p>circ.angle = 0;</p>
<p>Define the radius of the circle.</p>
<p>circ.radius = 100;</p>
<p>Here I declare the  amount of change in the angle (You know angle change will be in degree) for each iteration of the animation. Here I have used 20 degree for angle change. This will effect the rotation speed. If you need to increase speed you should increase angleChange and decrease for low speed.</p>
<p>circ.angleChange = 10;</p>
<p>Now write a  function to convert degrees to radians. This function accepts degrees and returns radians.</p>
<p>function degreetoradian(degree) {</p>
<p>return degree * (Math.PI / 180);</p>
<p>}</p>
<p>Ok We got the radians.</p>
<p>Now I start AS to rotate the circle.</p>
<p>function animateCircle() {</p>
<p>Here I store the radian conversion of the degree</p>
<p>var radian = degreetoradian(this.angle);</p>
<p>Now set the x and y cordinate for this movieClip, based on the clip-specific. And variables storing the circle center and radius, determining x and y coordinates using cosine and sine, respectively.</p>
<p>this._x = this.centerX + this.radius * Math.cos(radian);</p>
<p>this._y = this.centerY + this.radius * Math.sin(radian);</p>
<p>Here I add the angle change to the master angle for this clip with each  iteration, so we know how to determine the next x,y point.</p>
<p>this.angle += this.angleChange;</p>
<p>And now modulus to determine the correct angle for any angle which is greater  than 360-degrees.</p>
<p>this.angle+= 3;</p>
<p>}</p>
<p>You can give required value for angle change.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="300" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="quality" value="high" /><param name="src" value="http://www.jagadishwor.com.np//wp-content/uploads/2009/08/cirRot.swf" /><embed type="application/x-shockwave-flash" width="300" height="350" src="http://www.jagadishwor.com.np//wp-content/uploads/2009/08/cirRot.swf" quality="high"></embed></object></p>
<p>And in the final assign a funcion to be called on every EnterFrame event for this clip to play movie continiously.</p>
<p>circ.onEnterFrame = animateCircle;</p>
<p>The Action Script Code:</p>
<pre>//Define the stage for orbit and finding the center.

  circ.centerX = Stage.width / 2;

  circ.centerY = Stage.height / 2;

  //Define the starting anlge point on the circle, in degrees.

  circ.angle = 0;

  //Set the radius of the circle

  circ.radius = 110;

  //Set the angle change amount value.

  circ.angleChange = 10;

  //function to convert degrees to radians

  function degreetoradian(degree) {

return degree * (Math.PI / 180);

}

//Create function to animate circle

function animateCircle() {

//use a local variable to store the radian conversion of the degree

// value more familiar to most of us. See notes on Flash angles.

var radian = degreetoradian(this.angle);

//set the x and y cordinate for this slip, based on the clip-specific

// variables storing the circle center and radius. See notes for

// determining x and y coordinates using cosine and sine, respectively.

this._x = this.centerX + this.radius * Math.cos(radian);

this._y = this.centerY + this.radius * Math.sin(radian);

//add the angle change to the master angle for this clip with each 

// iteration, so we know how to determine the next x,y point.

this.angle += this.angleChange;

//use modulus to determine the correct angle for any angle greater

// than 360-degrees. See notes for an explanation of modulus.

this.angle+= 3;

}

//Now animate circle on onEnterFrame

circ.onEnterFrame = animateCircle</pre>
<p><a href="http://www.jagadishwor.com.np//wp-content/uploads/2009/08/cirRot.rar">Download Zip</a><br />
<h3>Most Commented Posts</h3>
<ul class="related_post">
<li><a href="http://www.themeheven.com/2009/03/display-wordpress-content-outside-of-your-blog/" title="Display Wordpress content outside of your blog">Display Wordpress content outside of your blog</a></li>
<li><a href="http://www.themeheven.com/2009/03/top-10-magazine-wordpress-themes-from-premiumthemes/" title="Top 10 Magazine WordPress Themes from Premiumthemes">Top 10 Magazine WordPress Themes from Premiumthemes</a></li>
<li><a href="http://www.themeheven.com/2009/04/wordpress-meta-tags-plugin/" title="WordPress Meta-Tags Plugin">WordPress Meta-Tags Plugin</a></li>
<li><a href="http://www.themeheven.com/2009/06/simple-jquery-image-slide-show-with-semi-transparent-caption/" title="Simple JQuery Image Slide Show with Semi-Transparent Caption">Simple JQuery Image Slide Show with Semi-Transparent Caption</a></li>
<li><a href="http://www.themeheven.com/2009/06/web-2-0-and-seo/" title="Web 2.0 and SEO">Web 2.0 and SEO</a></li>
<li><a href="http://www.themeheven.com/2009/03/photoshop-tutorial-sites/" title="Photoshop Tutorial Sites">Photoshop Tutorial Sites</a></li>
<li><a href="http://www.themeheven.com/2009/04/how-to-embed-google-ad-in-your-post/" title="How to: Embed Google Ad in your post">How to: Embed Google Ad in your post</a></li>
<li><a href="http://www.themeheven.com/2009/04/wordpress-tips-and-tricks/" title="Wordpress Tips and Tricks">Wordpress Tips and Tricks</a></li>
<li><a href="http://www.themeheven.com/2009/04/digital-photography-tutorial-and-tips/" title="Digital Photography Tutorial and Tips">Digital Photography Tutorial and Tips</a></li>
<li><a href="http://www.themeheven.com/2009/05/useful-wordpress-tricks-to-make-your-theme-even-better/" title="Useful Wordpress Tricks to Make Your Theme Even Better">Useful Wordpress Tricks to Make Your Theme Even Better</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.themeheven.com/2009/08/how-to-create-a-movieclip-rotating-around-the-center-continiously/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Duplicate Movie Clip</title>
		<link>http://www.themeheven.com/2009/08/flash-duplicate-movie-clip/</link>
		<comments>http://www.themeheven.com/2009/08/flash-duplicate-movie-clip/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 08:53:21 +0000</pubDate>
		<dc:creator>themeheven</dc:creator>
				<category><![CDATA[Flash AS]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Duplicate Movie Clip]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.themeheven.com/?p=229</guid>
		<description><![CDATA[In this Tutorial I will show you how you can duplicate your instances of a movie clip using a simple action script.
1. Create a movie clip of your choice. (If you want to show animation use motion gudie path for Motion Twin).
2. Place movie clip in the stage and give a instance name here I [...]]]></description>
			<content:encoded><![CDATA[<p>In this Tutorial I will show you how you can duplicate your instances of a movie clip using a simple action script.</p>
<p>1. Create a movie clip of your choice. (If you want to show animation use motion gudie path for Motion Twin).</p>
<p>2. Place movie clip in the stage and give a instance name here I use soccer_1</p>
<p>3. Create button for your movie clip duplication process.</p>
<p>4. Write Duplicate Code like below in your Actions Panel on your button&#8217;s release action:</p>
<p>on (release) {<br />
_root.Soccer_1.duplicateMovieClip (&#8221;Soccer_&#8221;+&#8221;x&#8221;, x );<br />
x++;<br />
}</p>
<p>5. Play your movie for test.<br />
<h3>See Also Following Topics:</h3>
<ul class="related_post">
<li><a href="http://www.themeheven.com/2009/07/drawing-shape-using-action-script/" title="Drawing Shape Using Action Script">Drawing Shape Using Action Script</a></li>
<li><a href="http://www.themeheven.com/2009/07/drawing-a-circle-using-action-script-code/" title="Drawing a Circle Using Action Script Code">Drawing a Circle Using Action Script Code</a></li>
<li><a href="http://www.themeheven.com/2009/07/flash-cs3-tutorial-arrays-2/" title="Flash CS3 Tutorial &#8211; Arrays">Flash CS3 Tutorial &#8211; Arrays</a></li>
<li><a href="http://www.themeheven.com/2009/07/flash-cs3-tutorial-arrays/" title="Flash CS3 Tutorial &#8211; Arrays">Flash CS3 Tutorial &#8211; Arrays</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.themeheven.com/2009/08/flash-duplicate-movie-clip/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drawing Shape Using Action Script</title>
		<link>http://www.themeheven.com/2009/07/drawing-shape-using-action-script/</link>
		<comments>http://www.themeheven.com/2009/07/drawing-shape-using-action-script/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 13:07:11 +0000</pubDate>
		<dc:creator>themeheven</dc:creator>
				<category><![CDATA[Flash AS]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Action Script]]></category>
		<category><![CDATA[Draw Shape]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.themeheven.com/?p=223</guid>
		<description><![CDATA[1. Draw Animating Circle
var cnt:Number = -90; // from which degree
  var radius:Number = 100;
  this.createEmptyMovieClip("circle",this.getNextHighestDepth());
  circle._x = 200;
  circle._y = 200;
  circle.lineStyle(1,0xFF0000,100);
  xx = 100*Math.cos(-90*Math.PI/180);
  yy = 100*Math.sin(-90*Math.PI/180);
  circle.moveTo(xx,yy);
intervalId = setInterval(this, "executeCallback", 5);

// function to darw a circele.
  function executeCallback() {
  xx = 100*Math.cos(cnt*Math.PI/180);
 [...]]]></description>
			<content:encoded><![CDATA[<p>1. Draw Animating Circle</p>
<pre><code>var cnt:Number = -90; // from which degree
  var radius:Number = 100;
  this.createEmptyMovieClip("circle",this.getNextHighestDepth());
  circle._x = 200;
  circle._y = 200;
  circle.lineStyle(1,0xFF0000,100);
  xx = 100*Math.cos(-90*Math.PI/180);
  yy = 100*Math.sin(-90*Math.PI/180);
  circle.moveTo(xx,yy);
intervalId = setInterval(this, "executeCallback", 5);

// function to darw a circele.
  function executeCallback() {
  xx = 100*Math.cos(cnt*Math.PI/180);
  yy = 100*Math.sin(cnt*Math.PI/180);
  circle.lineTo(xx,yy);
  cnt++;
  if (cnt&gt;=270) {
  fillcolor();
  circle.endFill();
  clearInterval(intervalId);
  }
  }

// To fill the color to circle
  function fillcolor() {
  circle.beginFill(0x00ff00,50);
  for (var i = -90; i&lt;=270; i++) {
  xx = 100*Math.cos(i*Math.PI/180);
  yy = 100*Math.sin(i*Math.PI/180);
  circle.lineTo(xx,yy);
  }
  }</code></pre>
<p>2. Drawing Rectangle and Square</p>
<pre><code>this.createEmptyMovieClip("rectangle_mc", 1);
  with(rectangle_mc){
  lineStyle(6, 0x003399, 100);
  moveTo(0, 0);
  lineTo(200, 0);
  lineTo(200, 200);
  lineTo(0, 200);
  lineTo(0, 0);
  _x=80;
  _y=80;
} </code></pre>
<p>3. Draw Arc</p>
<pre><code>
//
function drawArc(centerX, centerY, radius, startAngle, arcAngle, steps){
//
// Rotate the point of 0 rotation 1/4 turn counter-clockwise.
startAngle -= .25;
//
var twoPI = 2 * Math.PI;
var angleStep = arcAngle/steps;
var xx = centerX + Math.cos(startAngle * twoPI) * radius;
var yy = centerY + Math.sin(startAngle * twoPI) * radius;
moveTo(xx, yy);
for(var i=1; i&lt;=steps; i++){
var angle = startAngle + i * angleStep;
xx = centerX + Math.cos(angle * twoPI) * radius;
yy = centerY + Math.sin(angle * twoPI) * radius;
lineTo(xx, yy);
}
}
lineStyle(0, 0xFF0000);
drawArc(250, 250, 200, 45/360, -90/360, 20);
//</code></pre>
<p>4. Draw Triangle</p>
<pre><code>_root.lineStyle(3, 0x0000FF, 100); _root.moveTo(50, 200);
  _root.lineTo(150, 50);
  _root.lineTo(250, 200);
_root.lineTo(50, 200); </code></pre>
<p>5. Draw Pentagon</p>
<pre><code>createEmptyMovieClip("pentagon_mc", 1);
  pentagon_mc.beginFill(0x999999, 85);
  pentagon_mc.moveTo(0, 0);
  pentagon_mc.lineTo(0, -60);
  pentagon_mc.lineTo(-60, 0);
  pentagon_mc.lineTo(-60, 60);
  pentagon_mc.lineTo(60, 60);
  pentagon_mc.lineTo(60, 0);
  pentagon_mc.lineTo(0, -60);
pentagon_mc.endFill();  </code></pre>
<p>6. Draw Dimond</p>
<pre><code>createEmptyMovieClip("diamond_mc", 1);
  diamond_mc.beginFill(0x000000, 100);
  diamond_mc._x=300;
  diamond_mc._y=100;
  diamond_mc.lineTo(0, -90);
  diamond_mc.lineTo(-90, 0);
  diamond_mc.lineTo(0, 90);
  diamond_mc.lineTo(90, 0);
  diamond_mc.lineTo(0, -90);
diamond_mc.endFill();  </code></pre>
<p>7. Draw Oval Shape</p>
<pre><code>// Change "radius" to "xRadius" and add "yRadius" argument.
  function drawOval(centerX, centerY, xRadius, yRadius, sides){
//
// Change "radius" to "xRadius".
this.moveTo(centerX + xRadius, centerY);
//
for(var i=0; i&lt;=sides; i++){
var pointRatio = i/sides;
var radians = pointRatio * 2 * Math.PI;
var xSteps = Math.cos(radians);
var ySteps = Math.sin(radians);
//
// Change "radius" to "xRadius".
var pointX = centerX + xSteps * xRadius;
//
// Change "radius" to "yRadius".
var pointY = centerY + ySteps * yRadius;
//
this.lineTo(pointX, pointY);
}
}
//
lineStyle(0);
//
// X, Y, W, H, steps.
drawOval(250, 200, 200, 150, 100);
// </code></pre>
<h3>See Also Following Topics:</h3>
<ul class="related_post">
<li><a href="http://www.themeheven.com/2009/07/drawing-a-circle-using-action-script-code/" title="Drawing a Circle Using Action Script Code">Drawing a Circle Using Action Script Code</a></li>
<li><a href="http://www.themeheven.com/2009/08/flash-duplicate-movie-clip/" title="Flash Duplicate Movie Clip">Flash Duplicate Movie Clip</a></li>
<li><a href="http://www.themeheven.com/2009/07/flash-cs3-tutorial-arrays-2/" title="Flash CS3 Tutorial &#8211; Arrays">Flash CS3 Tutorial &#8211; Arrays</a></li>
<li><a href="http://www.themeheven.com/2009/07/flash-cs3-tutorial-arrays/" title="Flash CS3 Tutorial &#8211; Arrays">Flash CS3 Tutorial &#8211; Arrays</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.themeheven.com/2009/07/drawing-shape-using-action-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drawing a Circle Using Action Script Code</title>
		<link>http://www.themeheven.com/2009/07/drawing-a-circle-using-action-script-code/</link>
		<comments>http://www.themeheven.com/2009/07/drawing-a-circle-using-action-script-code/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 12:01:16 +0000</pubDate>
		<dc:creator>themeheven</dc:creator>
				<category><![CDATA[Flash AS]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Action Script]]></category>
		<category><![CDATA[Draw Circle]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.themeheven.com/?p=220</guid>
		<description><![CDATA[Create Empty Movie Clip mycirlce
this.createEmptyMovieClip(&#8221;mycircle&#8221;, 3);
Set the Stage Position for x coordinate and y coordinate
You can change the movie position as your required
mycircle._x = 200;
mycircle._y = 200;
Create Circle code here
mycircle.createEmptyMovieClip(&#8221;circle&#8221;, 1);
mycircle.circle.lineStyle(5, 0&#215;003399, 300);
mycircle.circle.moveTo(200, 0);
Define Radius of your circle
circleRadius = 200;
for (a=0; a&#60;360; a++) {
radAngle = a*Math.PI/180;
xCoord = Math.cos(radAngle)*circleRadius;
yCoord = Math.sin(radAngle)*circleRadius;
Move Line to x, y coordinate [...]]]></description>
			<content:encoded><![CDATA[<p>Create Empty Movie Clip mycirlce</p>
<p>this.createEmptyMovieClip(&#8221;mycircle&#8221;, 3);</p>
<p>Set the Stage Position for x coordinate and y coordinate<br />
You can change the movie position as your required</p>
<p>mycircle._x = 200;</p>
<p>mycircle._y = 200;</p>
<p>Create Circle code here</p>
<p>mycircle.createEmptyMovieClip(&#8221;circle&#8221;, 1);</p>
<p>mycircle.circle.lineStyle(5, 0&#215;003399, 300);</p>
<p>mycircle.circle.moveTo(200, 0);</p>
<p>Define Radius of your circle</p>
<p>circleRadius = 200;</p>
<p>for (a=0; a&lt;360; a++) {</p>
<p>radAngle = a*Math.PI/180;</p>
<p>xCoord = Math.cos(radAngle)*circleRadius;</p>
<p>yCoord = Math.sin(radAngle)*circleRadius;</p>
<p>Move Line to x, y coordinate show that circle will be print</p>
<p>mycircle.circle.lineTo(xCoord, yCoord);</p>
<p>}</p>
<p>Copy and Paste Action Script</p>
<p>this.createEmptyMovieClip(&#8221;mycircle&#8221;, 3);</p>
<p>mycircle._x = 200;</p>
<p>mycircle._y = 200;</p>
<p>mycircle.createEmptyMovieClip(&#8221;circle&#8221;, 1);</p>
<p>mycircle.circle.lineStyle(5, 0&#215;003399, 300);</p>
<p>mycircle.circle.moveTo(200, 0);</p>
<p>circleRadius = 200;</p>
<p>for (a=0; a&lt;360; a++) {</p>
<p>radAngle = a*Math.PI/180;</p>
<p>xCoord = Math.cos(radAngle)*circleRadius;</p>
<p>yCoord = Math.sin(radAngle)*circleRadius;</p>
<p>mycircle.circle.lineTo(xCoord, yCoord);</p>
<p>}</p>
<p>A simple circle code:</p>
<p>MovieClip.prototype.DrawCircle = function (x,y,r) {</p>
<p>var c1=r*(Math.SQRT2-1);</p>
<p>var c2=r*Math.SQRT2/2;</p>
<p>this.moveTo(x+r,y);</p>
<p>this.curveTo(x+r,y+c1,x+c2,y+c2);</p>
<p>this.curveTo(x+c1,y+r,x,y+r);</p>
<p>this.curveTo(x-c1,y+r,x-c2,y+c2);</p>
<p>this.curveTo(x-r,y+c1,x-r,y);</p>
<p>this.curveTo(x-r,y-c1,x-c2,y-c2);</p>
<p>this.curveTo(x-c1,y-r,x,y-r);</p>
<p>this.curveTo(x+c1,y-r,x+c2,y-c2);</p>
<p>this.curveTo(x+r,y-c1,x+r,y);</p>
<p>};</p>
<p>_root.createEmptyMovieClip(&#8221;circle&#8221;, 1);</p>
<p>_root.circle.lineStyle(5,0&#215;000000);</p>
<p>_root.circle.DrawCircle(150, 150, 200);</p>
<p>Again Another Method</p>
<p>//</p>
<p>function magicTrigFunctionX (pointRatio){</p>
<p>return Math.cos(pointRatio*2*Math.PI);</p>
<p>}</p>
<p>function magicTrigFunctionY (pointRatio){</p>
<p>return Math.sin(pointRatio*2*Math.PI);</p>
<p>}</p>
<p>//</p>
<p>function drawCircle(centerX, centerY, radius, sides){</p>
<p>// Move the pen to the first point on the circle.</p>
<p>this.moveTo(centerX + radius, centerY);</p>
<p>//</p>
<p>for(var i=0; i&lt;=sides; i++){</p>
<p>var pointRatio = i/sides;</p>
<p>var xSteps = magicTrigFunctionX(pointRatio);</p>
<p>var ySteps = magicTrigFunctionY(pointRatio);</p>
<p>var pointX = centerX + xSteps * radius;</p>
<p>var pointY = centerY + ySteps * radius;</p>
<p>this.lineTo(pointX, pointY);</p>
<p>}</p>
<p>}</p>
<p>//</p>
<p>lineStyle(0);</p>
<p>//</p>
<p>drawCircle(250, 250, 200, 100);</p>
<p>//<br />
<h3>See Also Following Topics:</h3>
<ul class="related_post">
<li><a href="http://www.themeheven.com/2009/07/drawing-shape-using-action-script/" title="Drawing Shape Using Action Script">Drawing Shape Using Action Script</a></li>
<li><a href="http://www.themeheven.com/2009/08/flash-duplicate-movie-clip/" title="Flash Duplicate Movie Clip">Flash Duplicate Movie Clip</a></li>
<li><a href="http://www.themeheven.com/2009/07/flash-cs3-tutorial-arrays-2/" title="Flash CS3 Tutorial &#8211; Arrays">Flash CS3 Tutorial &#8211; Arrays</a></li>
<li><a href="http://www.themeheven.com/2009/07/flash-cs3-tutorial-arrays/" title="Flash CS3 Tutorial &#8211; Arrays">Flash CS3 Tutorial &#8211; Arrays</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.themeheven.com/2009/07/drawing-a-circle-using-action-script-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash CS3 Tutorial &#8211; Arrays</title>
		<link>http://www.themeheven.com/2009/07/flash-cs3-tutorial-arrays-2/</link>
		<comments>http://www.themeheven.com/2009/07/flash-cs3-tutorial-arrays-2/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 02:43:28 +0000</pubDate>
		<dc:creator>themeheven</dc:creator>
				<category><![CDATA[Flash AS]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.themeheven.com/?p=206</guid>
		<description><![CDATA[An array is basically a container for holding data, similar to the way a variable hold data. The difference is that an array can hold multiple pieces of data. The location of each piece of data is referred to as its index and will always fall in a specific sequence. These indexes are numbers sequentially [...]]]></description>
			<content:encoded><![CDATA[<p>An array is basically a container for holding data, similar to the way a variable hold data. The difference is that an array can hold multiple pieces of data. The location of each piece of data is referred to as its index and will always fall in a specific sequence. These indexes are numbers sequentially and begin at zero. Since Flash numbers each piece of data within the array it is easy for the programmer to access a specific piece of data at any given time. In ActionScript you are not forced to contain one type of data in an array. This means that an array may contain a number in index 0, a name in index 1, and a movie clip in index 2. Creating an array is rather simple an only requires two steps. The first is to declare the array, second is to populate the array with data.</p>
<p>Flash Array</p>
<p>Animation with Arrays</p>
<p>To Create an array select the first key frame on the actions layer in the time line. Copy the sample code. This code is pretty straight forward. You are creating a variable called colorsArray, data typing it as an array and setting it equal to a new array and that is it for creating the array. To add data to the array copy and past the code from the next example. With this code your are simply calling the name of the array, then in between the braces you are telling flash what index of the array to use. Lastly you are telling flash to put something in the specified index.</p>
<pre><code>
var colorsArray:Array = new Array();
var colorsArray:Array = new Array();
</code></pre>
<p>A loop will be used to access the data contained within the array, but first create another array by coping the example code. This is the section that makes this an advanced Flash CS3 Tutorial. The first line is the Array that this Flash CS3 Tutorial is all about. Next, is the for loop that you should already understand. Inside the loop is where the fun begins. The for loop is actually creating circles with a color from the first array and adding them to the cirArray so they can be used later. First, a variable num is created and set to be a random number between 0 an 4, (see math tutorials) if you need a better understanding. Next, the code is creating a new Sprite (object) and the next three lines are using graphics properties to create a circle (see controlling graphics tutorial) inside the Sprite or cir variable.</p>
<pre><code>
var cirArray:Array = new Array();
for (var i:int = 0; i &lt; 15; i++){
var num = Math.floor(Math.random() * 5)
var cir:Sprite = new Sprite();
cir.graphics.lineStyle(1);
cir.graphics.beginFill(colorsArray[num]);
cir.graphics.drawCircle(0,0,30);
cir.x = Math.random() * 500
cir.y = Math.random() * 300
cir.alpha =.5
addChildAt(cir, i)

cir.name="cir"+i 

  cirArray[i] = this.getChildByName("cir"+i) 

  };
</code></pre>
<p>If you look at the line cir.graphics.beginFill(colorsArray[num]) you will see a reference to the array you first created holding the color values. This line of ActionScript is simply using the random number (num) to decide which index of the array to pull the color information from. You should understand the two lines that are setting the cir.x and cir.y to a random location, then the cir&#8217;s alpha is set to .5 making it semi transparent, and finally the circle is added to the stage with the addChildAt. The last two lines of this code are particularly important to the array. cir.name=&#8221;cir&#8221;+i names the current instance of cir as cir + i and the last line is a method of the DisplayObjectContiner class that returns the object with the specified name, thus placing the newly created and named instance of the cir inside a separate index of the cirArray. Sounds a little complicated but basically it is the same as manually adding an object to each index of the array as you did in the first array.</p>
<pre><code>
start_btn.addEventListener(MouseEvent.CLICK, startMotion);
function startMotion(event:MouseEvent):void{
stage.addEventListener(Event.ENTER_FRAME, motion);
stop_btn.visible = true
start_btn.visible = false
};

stop_btn.addEventListener(MouseEvent.CLICK, stopMotion); 

  function stopMotion(event:MouseEvent):void{ 

  stage.removeEventListener(Event.ENTER_FRAME, motion); 

  stop_btn.visible = false

start_btn.visible = true 

  };
</code></pre>
<p>At this point in the Flash CS3 Tutorial ActionScript has created two arrays and added data to each of them, now to interact with the data. Copy the example code to the actions panel below the arrays. In the source file you should have noticed two buttons, stop and start. This section of code is simple the event listeners to make the buttons work.</p>
<pre><code>function motion(event:Event):void{
for (var i:int = 0; i &lt; 15; i++){
if (cirArray[i].x &gt; 520){
cirArray[i].x = -20
cirArray[i].y = Math.random()* 300
} else
cirArray[i].x +=15
}
};</code></pre>
<p>Once again add the example code to the actions panel. The first line of code is a simple function that is being called by the start button. Next, is the for loop that moves through the array. You could change the number 15 to be the length of the array by replacing it with cirArray.lenght and it would automatically detect the length of the array. Next, is an if statement checks to see if the object contained with the specific index of the array is on the stage. If the object is on the stage it moves the object 15 pixels and if it is not on the stage is moves it to the other side of the stage and randomly changes the y position. This simple if statement is what makes the 15 simple circles seem to be an endless amount.</p>
<p>Press Control-Enter and test the movie, if all goes well you have a Flash CS3 Animation created with ActionScript Arrays</p>
<p>Download Flash CS3 Tutorial, Source Files</p>
<p>Flash CS3 Tutorials, Copyright FrenchSquared 2008</p>
<p>Adobe Flash CS4 Tutorials, The Information You Need is designed around the idea that knowledge helps everyone. If an individual so desires he/she should not need to spend $100k on a college education. The knowledge needs to be available to that said individual. Adobe Flash CS4 Tutorials, The Information You Need is an attempt to bring some knowledge to the masses.</p>
<p>Article Source: <a href="http://EzineArticles.com/?expert=Gordon_French" target="_blank">http://EzineArticles.com/?expert=Gordon_French</a><br />
<h3>See Also Following Topics:</h3>
<ul class="related_post">
<li><a href="http://www.themeheven.com/2009/08/flash-duplicate-movie-clip/" title="Flash Duplicate Movie Clip">Flash Duplicate Movie Clip</a></li>
<li><a href="http://www.themeheven.com/2009/07/drawing-shape-using-action-script/" title="Drawing Shape Using Action Script">Drawing Shape Using Action Script</a></li>
<li><a href="http://www.themeheven.com/2009/07/drawing-a-circle-using-action-script-code/" title="Drawing a Circle Using Action Script Code">Drawing a Circle Using Action Script Code</a></li>
<li><a href="http://www.themeheven.com/2009/07/flash-cs3-tutorial-arrays/" title="Flash CS3 Tutorial &#8211; Arrays">Flash CS3 Tutorial &#8211; Arrays</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.themeheven.com/2009/07/flash-cs3-tutorial-arrays-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flash CS3 Tutorial &#8211; Arrays</title>
		<link>http://www.themeheven.com/2009/07/flash-cs3-tutorial-arrays/</link>
		<comments>http://www.themeheven.com/2009/07/flash-cs3-tutorial-arrays/#comments</comments>
		<pubDate>Sun, 12 Jul 2009 07:33:21 +0000</pubDate>
		<dc:creator>themeheven</dc:creator>
				<category><![CDATA[Flash AS]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Array]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.themeheven.com/?p=207</guid>
		<description><![CDATA[An array is basically a container for holding data, similar to the way a variable hold data. The difference is that an array can hold multiple pieces of data. The location of each piece of data is referred to as its index and will always fall in a specific sequence. These indexes are numbers sequentially [...]]]></description>
			<content:encoded><![CDATA[<p>An array is basically a container for holding data, similar to the way a variable hold data. The difference is that an array can hold multiple pieces of data. The location of each piece of data is referred to as its index and will always fall in a specific sequence. These indexes are numbers sequentially and begin at zero. Since Flash numbers each piece of data within the array it is easy for the programmer to access a specific piece of data at any given time. In ActionScript you are not forced to contain one type of data in an array. This means that an array may contain a number in index 0, a name in index 1, and a movie clip in index 2. Creating an array is rather simple an only requires two steps. The first is to declare the array, second is to populate the array with data.</p>
<p><strong>Flash Array</strong></p>
<p><span style="color: #808000;"><strong>Animation with Arrays</strong></span></p>
<p>To Create an array select the first key frame on the actions layer in the time line. Copy the sample code. This code is pretty straight forward. You are creating a variable called colorsArray, data typing it as an array and setting it equal to a new array and that is it for creating the array. To add data to the array copy and past the code from the next example. With this code your are simply calling the name of the array, then in between the braces you are telling flash what index of the array to use. Lastly you are telling flash to put something in the specified index.</p>
<pre><code>
var colorsArray:Array = new Array();
var colorsArray:Array = new Array();
</code></pre>
<p>A loop will be used to access the data contained within the array, but first create another array by coping the example code. This is the section that makes this an advanced Flash CS3 Tutorial. The first line is the Array that this Flash CS3 Tutorial is all about. Next, is the for loop that you should already understand. Inside the loop is where the fun begins. The for loop is actually creating circles with a color from the first array and adding them to the cirArray so they can be used later. First, a variable num is created and set to be a random number between 0 an 4, (see math tutorials) if you need a better understanding. Next, the code is creating a new Sprite (object) and the next three lines are using graphics properties to create a circle (see controlling graphics tutorial) inside the Sprite or cir variable.</p>
<pre><code>
var cirArray:Array = new Array();
for (var i:int = 0; i &lt; 15; i++){
var num = Math.floor(Math.random() * 5)
var cir:Sprite = new Sprite();
cir.graphics.lineStyle(1);
cir.graphics.beginFill(colorsArray[num]);
cir.graphics.drawCircle(0,0,30);
cir.x = Math.random() * 500
cir.y = Math.random() * 300
cir.alpha =.5
addChildAt(cir, i)

cir.name="cir"+i 

  cirArray[i] = this.getChildByName("cir"+i) 

  };

</code></pre>
<p>If you look at the line cir.graphics.beginFill(colorsArray[num]) you will see a reference to the array you first created holding the color values. This line of ActionScript is simply using the random number (num) to decide which index of the array to pull the color information from. You should understand the two lines that are setting the cir.x and cir.y to a random location, then the cir&#8217;s alpha is set to .5 making it semi transparent, and finally the circle is added to the stage with the addChildAt. The last two lines of this code are particularly important to the array. cir.name=&#8221;cir&#8221;+i names the current instance of cir as cir + i and the last line is a method of the DisplayObjectContiner class that returns the object with the specified name, thus placing the newly created and named instance of the cir inside a separate index of the cirArray. Sounds a little complicated but basically it is the same as manually adding an object to each index of the array as you did in the first array.</p>
<pre><code>
start_btn.addEventListener(MouseEvent.CLICK, startMotion);
function startMotion(event:MouseEvent):void{
stage.addEventListener(Event.ENTER_FRAME, motion);
stop_btn.visible = true
start_btn.visible = false
};

stop_btn.addEventListener(MouseEvent.CLICK, stopMotion); 

  function stopMotion(event:MouseEvent):void{ 

  stage.removeEventListener(Event.ENTER_FRAME, motion); 

  stop_btn.visible = false

start_btn.visible = true 

  };
</code></pre>
<p>At this point in the Flash CS3 Tutorial ActionScript has created two arrays and added data to each of them, now to interact with the data. Copy the example code to the actions panel below the arrays. In the source file you should have noticed two buttons, stop and start. This section of code is simple the event listeners to make the buttons work.</p>
<pre><code>function motion(event:Event):void{
for (var i:int = 0; i &lt; 15; i++){
if (cirArray[i].x &gt; 520){
cirArray[i].x = -20
cirArray[i].y = Math.random()* 300
} else
cirArray[i].x +=15
}
};</code></pre>
<p>Once again add the example code to the actions panel. The first line of code is a simple function that is being called by the start button. Next, is the for loop that moves through the array. You could change the number 15 to be the length of the array by replacing it with cirArray.lenght and it would automatically detect the length of the array. Next, is an if statement checks to see if the object contained with the specific index of the array is on the stage. If the object is on the stage it moves the object 15 pixels and if it is not on the stage is moves it to the other side of the stage and randomly changes the y position. This simple if statement is what makes the 15 simple circles seem to be an endless amount.</p>
<p>Press Control-Enter and test the movie, if all goes well you have a Flash CS3 Animation created with ActionScript Arrays</p>
<p>Download Flash CS3 Tutorial, Source Files</p>
<p>Flash CS3 Tutorials, Copyright FrenchSquared 2008</p>
<p>Adobe Flash CS4 Tutorials, The Information You Need is designed around the idea that knowledge helps everyone. If an individual so desires he/she should not need to spend $100k on a college education. The knowledge needs to be available to that said individual. Adobe Flash CS4 Tutorials, The Information You Need is an attempt to bring some knowledge to the masses.</p>
<p>Article Source: <a href="http://EzineArticles.com/?expert=Gordon_French" target="_blank">http://EzineArticles.com/?expert=Gordon_French</a><br />
<h3>See Also Following Topics:</h3>
<ul class="related_post">
<li><a href="http://www.themeheven.com/2009/08/flash-duplicate-movie-clip/" title="Flash Duplicate Movie Clip">Flash Duplicate Movie Clip</a></li>
<li><a href="http://www.themeheven.com/2009/07/drawing-shape-using-action-script/" title="Drawing Shape Using Action Script">Drawing Shape Using Action Script</a></li>
<li><a href="http://www.themeheven.com/2009/07/drawing-a-circle-using-action-script-code/" title="Drawing a Circle Using Action Script Code">Drawing a Circle Using Action Script Code</a></li>
<li><a href="http://www.themeheven.com/2009/07/flash-cs3-tutorial-arrays-2/" title="Flash CS3 Tutorial &#8211; Arrays">Flash CS3 Tutorial &#8211; Arrays</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.themeheven.com/2009/07/flash-cs3-tutorial-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->
