<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>ActionScript Instances</title>
		<link>http://gamedesign.wikidot.com/forum/t-19342/actionscript-instances</link>
		<description>Posts in the discussion thread &quot;ActionScript Instances&quot; - How to...</description>
				<copyright></copyright>
		<lastBuildDate>Tue, 12 May 2026 21:01:29 +0000</lastBuildDate>
		
					<item>
				<guid>http://gamedesign.wikidot.com/forum/t-19342#post-48369</guid>
				<title>Re: ActionScript Instances</title>
				<link>http://gamedesign.wikidot.com/forum/t-19342/actionscript-instances#post-48369</link>
				<description></description>
				<pubDate>Wed, 12 Sep 2007 06:43:05 +0000</pubDate>
				<wikidot:authorName>Linkage2</wikidot:authorName>				<wikidot:authorUserId>29081</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Yeah, that helps. I'm not surprised I was doing it wrong, I don't really have my head around the way AS wants to be treated just yet.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://gamedesign.wikidot.com/forum/t-19342#post-48338</guid>
				<title>Re: ActionScript Instances</title>
				<link>http://gamedesign.wikidot.com/forum/t-19342/actionscript-instances#post-48338</link>
				<description></description>
				<pubDate>Wed, 12 Sep 2007 02:26:30 +0000</pubDate>
				<wikidot:authorName>hartnell</wikidot:authorName>				<wikidot:authorUserId>10978</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Ok, let me try to understand this. Even though you have the movie clip as an asset, you have to &quot;attach&quot; it as an asset?</p> <p>&#8212;hartnell</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://gamedesign.wikidot.com/forum/t-19342#post-48299</guid>
				<title>Re: ActionScript Instances</title>
				<link>http://gamedesign.wikidot.com/forum/t-19342/actionscript-instances#post-48299</link>
				<description></description>
				<pubDate>Tue, 11 Sep 2007 23:10:08 +0000</pubDate>
				<wikidot:authorName>Woad</wikidot:authorName>				<wikidot:authorUserId>19640</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>No, that's a stupid way to do it i'm afraid to say.<br /> First you'll run into a depth problem very quickly, if you just use a for variable (like i or j) then when you try to make more it will take those depths and destroy any movieclip that was using it.<br /> Also, there's no need to do attach in the beggining and then duplicate the movie everytime, just attach everytime.<br /> Here's an example that will hopefully help you out.</p> <div class="code"> <pre><code>Shoot = function() { mc = _root.attachMovie(&quot;bullet&quot;,&quot;bullet&quot;+_root.getNextHighestDepth(),_root.getNextHighestDepth()); mc._x = player._x; mc._y = player._y; mc.dir = Math.atan2(_ymouse -mc._y,_xmouse - mc._x); mc.speed = 5; mc.onEnterFrame = function() { this._x += Math.cos(this.dir)*this.speed; this._y += Math.sin(this.dir)*this.speed; if(this._x &lt; 0 || this._x &gt; Stage.width || this._y &lt; 0 || this._y &gt; Stage.height) { this.removeMovieClip(); } //Collision if statements if(this.hitTest(_root.target)) //Make a target movieclip, give it an instance name of target and put it on the stage. { this.removeMovieClip(); } } } onMouseDown = function() { Shoot(); } player.onEnterFrame = function() { if(Key.isDown(Key.LEFT)) { this._x -= 3; } if(Key.isDown(Key.RIGHT)) { this._x += 3; } if(Key.isDown(Key.UP)) { this._y -= 3; } if(Key.isDown(Key.DOWN)) { this._y += 3; } }</code></pre></div> <p>You also need to place a player movieclip onto the stage with an instance name of player.</p> <p>Does that clear anything up?</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://gamedesign.wikidot.com/forum/t-19342#post-48088</guid>
				<title>Re: ActionScript Instances</title>
				<link>http://gamedesign.wikidot.com/forum/t-19342/actionscript-instances#post-48088</link>
				<description></description>
				<pubDate>Tue, 11 Sep 2007 07:45:01 +0000</pubDate>
				<wikidot:authorName>Linkage2</wikidot:authorName>				<wikidot:authorUserId>29081</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>That's actually something I'm trying to get my head around right now, but in the sense of finding a good way to lay out a level for a platform style and then being able to do collision detection with it.</p> <p>Well, I think before you get going with your code, you should first attach a Bullet Movie Clip, like so:</p> <div class="code"> <pre><code>this.attachMovie(&quot;bullet&quot;,&quot;bullet&quot;,1);</code></pre></div> <br /> The first parameter is the Linkage (hehe) name for the Movie Clip, I'm assuming you'd set it to something like bullet. The second parameter is the new name for the object, and the third is its depth- note that when you make a new object on the same depth as another object, it will overwrite any previous on that depth. <p>Then, whenever you need to spawn a bullet, just do this:</p> <div class="code"> <pre><code>bullet.duplicateMovieClip(&lt;new name&gt;, &lt;depth&gt;); &lt;new name&gt;._x = wherever you want it go, same for _y.</code></pre></div> <p>A good way to keep everything on different depths is to, assuming you're finding the bullet you want with a for loop + check for use, set its depth to the current value for your for variable (I usually use g for for loops).</p> <p>Duplicating clips and then checking collision for each of them is where I'm stuck. I don't know how to reference each one correctly.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://gamedesign.wikidot.com/forum/t-19342#post-48079</guid>
				<title>ActionScript Instances</title>
				<link>http://gamedesign.wikidot.com/forum/t-19342/actionscript-instances#post-48079</link>
				<description></description>
				<pubDate>Tue, 11 Sep 2007 06:48:39 +0000</pubDate>
				<wikidot:authorName>hartnell</wikidot:authorName>				<wikidot:authorUserId>10978</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>How do you create an instance of an object using ActionScript during runtime? How do you destroy it? Think <em>bullets</em>. :)</p> <p>&#8212;hartnell</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>