<?xml version="1.0" encoding="UTF-8"?>
<posts type="array">
  <post>
    <body>Sorry sky that didn't work out for me. It said attachChild didn't appear to be valid. 

Anyways I fixed it and here's how: The movieclip was made from another movieclip whereas the other two buttons that worked were made from graphics. So all I had to do was change it to a graphic inside the button movieclip and all fixed now. Thanks everyone for your input.</body>
    <body-html>&lt;p&gt;Sorry sky that didn&amp;#8217;t work out for me. It said attachChild didn&amp;#8217;t appear to be valid.&lt;/p&gt;
&lt;p&gt;Anyways I fixed it and here&amp;#8217;s how: The movieclip was made from another movieclip whereas the other two buttons that worked were made from graphics. So all I had to do was change it to a graphic inside the button movieclip and all fixed now. Thanks everyone for your input.&lt;/p&gt;</body-html>
    <created-at type="datetime">2009-11-07T20:03:55-08:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">1440492</id>
    <post-number type="integer">9</post-number>
    <topic-id type="integer">63876</topic-id>
    <updated-at type="datetime">2009-11-07T20:03:55-08:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>Something new is popping up and I don't get why. Two of my buttons work fine. I added a third and for some reason when I click on it it says it's a movieclip, not a ToggleButton. I looked everywhere I could think of. The code is called in exactly the same way as the others. The other buttons work. The movie clip is linked properly, the base class is the same as the other two. The instance name is called out correctly. I even tried renaming the clip in the library, renaming the instance. For some reason it just won't recognize.</body>
    <body-html>&lt;p&gt;Something new is popping up and I don&amp;#8217;t get why. Two of my buttons work fine. I added a third and for some reason when I click on it it says it&amp;#8217;s a movieclip, not a ToggleButton. I looked everywhere I could think of. The code is called in exactly the same way as the others. The other buttons work. The movie clip is linked properly, the base class is the same as the other two. The instance name is called out correctly. I even tried renaming the clip in the library, renaming the instance. For some reason it just won&amp;#8217;t recognize.&lt;/p&gt;</body-html>
    <created-at type="datetime">2009-11-07T19:30:45-08:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">1440347</id>
    <post-number type="integer">7</post-number>
    <topic-id type="integer">63876</topic-id>
    <updated-at type="datetime">2009-11-07T19:33:58-08:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>Edit: I did something silly.. Here is my real error

I'm putting my ToggleButton into a container that holds ToggleButtons and now I get an implicit coercion error. It says I am trying to convert a MovieClip to a ToggleButton.

Edit Again: I appear to have done something else silly... Works now. Thanks for helping me realize it was the base class all along.

For anyone who cares to know, the second silly thing I did was since I am using the graphic for the button elsewhere I decided to make a new instance in the library to act as a button only and not an item, Well I forgot to change the instance on the stage to the new MovieClip. so of course it was not a ToggleButton.</body>
    <body-html>&lt;p&gt;Edit: I did something silly.. Here is my real error&lt;/p&gt;
&lt;p&gt;I&amp;#8217;m putting my ToggleButton into a container that holds ToggleButtons and now I get an implicit coercion error. It says I am trying to convert a MovieClip to a ToggleButton.&lt;/p&gt;
&lt;p&gt;Edit Again: I appear to have done something else silly&amp;#8230; Works now. Thanks for helping me realize it was the base class all along.&lt;/p&gt;
&lt;p&gt;For anyone who cares to know, the second silly thing I did was since I am using the graphic for the button elsewhere I decided to make a new instance in the library to act as a button only and not an item, Well I forgot to change the instance on the stage to the new MovieClip. so of course it was not a ToggleButton.&lt;/p&gt;</body-html>
    <created-at type="datetime">2009-11-07T18:21:38-08:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">1440150</id>
    <post-number type="integer">5</post-number>
    <topic-id type="integer">63876</topic-id>
    <updated-at type="datetime">2009-11-07T18:33:18-08:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>1. I have three different pictures. I do not want to combine them into a movie clip with 3 different frames. I want 3 separate buttons who all perform the same actions when I click on them. The only thing different about them is the image. 

2. How can I make a ToggleButton and assign a picture to it? I don't need multiple classes because all the functions for ToggleButtons are the same, either on or off, so I don't want to create three separate classes for each button.

I can make a new ToggleButton and add it to the stage, but it doesn't do anything. When I make it there is no image (MovieClip) associated with it and I don't know how to add one. 

On the other hand, when I take an image (MovieClip) that is already on the stage and try to make it a ToggleButton, it appears to do nothing. No errors, no nothing.

Thanks for asking your questions. I hope I was able to clarify better.</body>
    <body-html>&lt;p&gt;1. I have three different pictures. I do not want to combine them into a movie clip with 3 different frames. I want 3 separate buttons who all perform the same actions when I click on them. The only thing different about them is the image.&lt;/p&gt;
&lt;p&gt;2. How can I make a ToggleButton and assign a picture to it? I don&amp;#8217;t need multiple classes because all the functions for ToggleButtons are the same, either on or off, so I don&amp;#8217;t want to create three separate classes for each button.&lt;/p&gt;
&lt;p&gt;I can make a new ToggleButton and add it to the stage, but it doesn&amp;#8217;t do anything. When I make it there is no image (MovieClip) associated with it and I don&amp;#8217;t know how to add one.&lt;/p&gt;
&lt;p&gt;On the other hand, when I take an image (MovieClip) that is already on the stage and try to make it a ToggleButton, it appears to do nothing. No errors, no nothing.&lt;/p&gt;
&lt;p&gt;Thanks for asking your questions. I hope I was able to clarify better.&lt;/p&gt;</body-html>
    <created-at type="datetime">2009-11-07T18:06:33-08:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">1440106</id>
    <post-number type="integer">3</post-number>
    <topic-id type="integer">63876</topic-id>
    <updated-at type="datetime">2009-11-07T18:06:33-08:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>I've decided to move my main issue into a new thread where I can clearly state what I'm trying to do. Thanks to all who answered my other related questions. I have gotten further along because of you.

I have three different movie clips. I want to cast all of them to a ToggleButton so I can use the same functions for each. Now I have tried already to link each movie clip but that does not work because they want to be separately named classes.

The buttons are all on the stage already, but if it's easier I can grab them from my library instead.

I have tried this:
&lt;pre&gt;
&lt;code&gt;

buttonOne = new ToggleButton();
var containerOne:ToggleButtonContainer = new ToggleButtonContainer();

containerOne.addButton(buttonOne);
addChild(buttonOne);

&lt;/code&gt;
&lt;/pre&gt;

There is a mouse listener associated with a function of ToggleButton. I put a trace in there to tell if the button has been selected or not. It always comes back as not selected. This happens wherever I click on the stage, not just on the button.

I also have a mouse listener for the whole stage and a trace in that tells me what I've clicked on. For some reason when I click what should be a ToggleButton it says I clicked a buttonOne_XX, which is the name of the movie clip in the library with what appears to be a random number at the end. The funny part is when I click any of the other buttons that I have not tried to cast as a ToggleButton it says I have only clicked a MovieClip.</body>
    <body-html>&lt;p&gt;I&amp;#8217;ve decided to move my main issue into a new thread where I can clearly state what I&amp;#8217;m trying to do. Thanks to all who answered my other related questions. I have gotten further along because of you.&lt;/p&gt;
&lt;p&gt;I have three different movie clips. I want to cast all of them to a ToggleButton so I can use the same functions for each. Now I have tried already to link each movie clip but that does not work because they want to be separately named classes.&lt;/p&gt;
&lt;p&gt;The buttons are all on the stage already, but if it&amp;#8217;s easier I can grab them from my library instead.&lt;/p&gt;
&lt;p&gt;I have tried this:&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
&lt;code&gt;&lt;/p&gt;
&lt;p&gt;buttonOne = new ToggleButton();&lt;br /&gt;
var containerOne:ToggleButtonContainer = new ToggleButtonContainer();&lt;/p&gt;
&lt;p&gt;containerOne.addButton(buttonOne);&lt;br /&gt;
addChild(buttonOne);&lt;/p&gt;
&lt;p&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;There is a mouse listener associated with a function of ToggleButton. I put a trace in there to tell if the button has been selected or not. It always comes back as not selected. This happens wherever I click on the stage, not just on the button.&lt;/p&gt;
&lt;p&gt;I also have a mouse listener for the whole stage and a trace in that tells me what I&amp;#8217;ve clicked on. For some reason when I click what should be a ToggleButton it says I clicked a buttonOne_XX, which is the name of the movie clip in the library with what appears to be a random number at the end. The funny part is when I click any of the other buttons that I have not tried to cast as a ToggleButton it says I have only clicked a MovieClip.&lt;/p&gt;</body-html>
    <created-at type="datetime">2009-11-07T17:38:56-08:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">1440004</id>
    <post-number type="integer">1</post-number>
    <topic-id type="integer">63876</topic-id>
    <updated-at type="datetime">2009-11-07T17:40:26-08:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>OK, so I've done that and not getting any errors...

&lt;pre&gt;
&lt;code&gt;
emptyBottleBtn = new ToggleButton();
//magicBottleButton = new ToggleButton(magicBottleBtn);
//sprinklesButton = new ToggleButton(sprinklesBtn);

var buttonContainer:ToggleButtonContainer = new ToggleButtonContainer();

buttonContainer.addButton(emptyBottleBtn);
//buttonContainer.addButton(magicBottleButton);
//buttonContainer.addButton(sprinklesButton);

addChild(emptyBottleBtn);
&lt;/code&gt;
&lt;/pre&gt;

but now I have this container that holds ToggleButtons and when I try to put my new ToggleButton into it, it seems it won't take it. Should I make the container hold MovieClips instead?

Error: 1118: Implicit coercion of a value with static type flash.display:MovieClip to a possibly unrelated type poeClasses:ToggleButton

The container class extends Sprite at the suggestion of another poster in another thread.</body>
    <body-html>&lt;p&gt;OK, so I&amp;#8217;ve done that and not getting any errors&amp;#8230;&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
emptyBottleBtn = new ToggleButton();
//magicBottleButton = new ToggleButton(magicBottleBtn);
//sprinklesButton = new ToggleButton(sprinklesBtn);

var buttonContainer:ToggleButtonContainer = new ToggleButtonContainer();

buttonContainer.addButton(emptyBottleBtn);
//buttonContainer.addButton(magicBottleButton);
//buttonContainer.addButton(sprinklesButton);

addChild(emptyBottleBtn);
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;but now I have this container that holds ToggleButtons and when I try to put my new ToggleButton into it, it seems it won&amp;#8217;t take it. Should I make the container hold MovieClips instead?&lt;/p&gt;
&lt;p&gt;Error: 1118: Implicit coercion of a value with static type flash.display:MovieClip to a possibly unrelated type poeClasses:ToggleButton&lt;/p&gt;
&lt;p&gt;The container class extends Sprite at the suggestion of another poster in another thread.&lt;/p&gt;</body-html>
    <created-at type="datetime">2009-11-07T14:49:10-08:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">1439228</id>
    <post-number type="integer">6</post-number>
    <topic-id type="integer">63812</topic-id>
    <updated-at type="datetime">2009-11-07T14:49:10-08:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>Omg that was a dumb mistake.

Well I want my emptyBottleBtn, which is a movie clip on the stage, to be a ToggleButton so it can utilize the ToggleButton functions.</body>
    <body-html>&lt;p&gt;Omg that was a dumb mistake.&lt;/p&gt;
&lt;p&gt;Well I want my emptyBottleBtn, which is a movie clip on the stage, to be a ToggleButton so it can utilize the ToggleButton functions.&lt;/p&gt;</body-html>
    <created-at type="datetime">2009-11-07T13:37:03-08:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">1438896</id>
    <post-number type="integer">4</post-number>
    <topic-id type="integer">63812</topic-id>
    <updated-at type="datetime">2009-11-07T13:37:03-08:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>Here is my external class:

&lt;pre&gt;
&lt;code&gt;
package poeClasses{
	import flash.display.MovieClip;
	public class ToggleButton extends MovieClip {
		private var isSelected:Boolean=false;
		//private var clip:MovieClip;
		//var selectPicture:SelectBtn = new SelectBtn();

		public function ToggleButton() {
			super();
			//clip = movieClip;
		}

		public function getIsSelected():Boolean {
			return isSelected;
		}

		public function setIsSelected(selectValue):void {
			isSelected=selectValue;
			if (isSelected) {
				trace(&quot;Selected&quot;);
				//clip.gotoAndStop(&quot;selected&quot;);
			} else {
				trace(&quot;Not Selected&quot;);
				//clip.gotoAndStop(&quot;unselected&quot;);
			}
		}
	}
}
&lt;/code&gt;

&lt;code&gt;
package poeClasses{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	public class ToggleButtonContainer extends Sprite {
		private var buttons:Array = new Array();
		
		public function ToggleButtonContainer() {
			super();
		}
		
		public function addButton(btn:ToggleButton) {  
			buttons.push(btn);
			btn.addEventListener(MouseEvent.CLICK, onClick);
			addChild(btn);
		}
		
		public function deselectAll() {
			for(var i:uint;i &lt; buttons.length;i++) {
				ToggleButton(buttons[i]).setIsSelected(false);
			}
		}
		
		private function onClick(e:MouseEvent):void {
			trace(&quot;Target in container: &quot; + e.target);
			deselectAll(); 
			ToggleButton(e.target).setIsSelected(true);
		}
	}
}
&lt;/code&gt;
&lt;/pre&gt;

Here is my document code: 

&lt;pre&gt;
&lt;code&gt;
emptyBottleBtn:ToggleButton = new ToggleButton();
var buttonContainer:ToggleButtonContainer = new ToggleButtonContainer();

buttonContainer.addButton(emptyBottleBtn);

//addChild(buttonContainer);
addChild(emptyBottleBtn);
&lt;/code&gt;
&lt;/pre&gt;

Here are my errors: 
1067: Implicit coercion of a value of type poeClasses:ToggleButton to an unrelated type Class. (Error occurs on the line in which I am setting emptyBottleBtn equal to a new ToggleButton.)

1188: Illegal assignment to class ToggleButton. (Error occurs on the line in which I am setting emptyBottleBtn equal to a new ToggleButton.)

1067: Implicit coercion of a value of type emptyGameBottle to an unrelated type poeClasses:ToggleButton. (Error occurs on the line in which I am adding emptyBottleBtn to the buttonContainer.)

The movie clip on the stage is an emptyGameBottle.

*is frustrated* :P Thanks for any help

Edit: added lines above. 

@SuperMario my last thread you had said to have the class extend SelectBtn. That isn't what I wanted to do so instead of having a separate class for the select graphic I put it in the button graphic as a separate frame. Now I'm just trying to get my button to be of the class ToggleButton.</body>
    <body-html>&lt;p&gt;Here is my external class:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
package poeClasses{
	import flash.display.MovieClip;
	public class ToggleButton extends MovieClip {
		private var isSelected:Boolean=false;
		//private var clip:MovieClip;
		//var selectPicture:SelectBtn = new SelectBtn();

		public function ToggleButton() {
			super();
			//clip = movieClip;
		}

		public function getIsSelected():Boolean {
			return isSelected;
		}

		public function setIsSelected(selectValue):void {
			isSelected=selectValue;
			if (isSelected) {
				trace(&quot;Selected&quot;);
				//clip.gotoAndStop(&quot;selected&quot;);
			} else {
				trace(&quot;Not Selected&quot;);
				//clip.gotoAndStop(&quot;unselected&quot;);
			}
		}
	}
}
&amp;lt;/code&amp;gt;

&amp;lt;code&amp;gt;
package poeClasses{
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	public class ToggleButtonContainer extends Sprite {
		private var buttons:Array = new Array();
		
		public function ToggleButtonContainer() {
			super();
		}
		
		public function addButton(btn:ToggleButton) {  
			buttons.push(btn);
			btn.addEventListener(MouseEvent.CLICK, onClick);
			addChild(btn);
		}
		
		public function deselectAll() {
			for(var i:uint;i &amp;lt; buttons.length;i++) {
				ToggleButton(buttons[i]).setIsSelected(false);
			}
		}
		
		private function onClick(e:MouseEvent):void {
			trace(&quot;Target in container: &quot; + e.target);
			deselectAll(); 
			ToggleButton(e.target).setIsSelected(true);
		}
	}
}
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Here is my document code:&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
emptyBottleBtn:ToggleButton = new ToggleButton();
var buttonContainer:ToggleButtonContainer = new ToggleButtonContainer();

buttonContainer.addButton(emptyBottleBtn);

//addChild(buttonContainer);
addChild(emptyBottleBtn);
&lt;/code&gt;
&lt;/pre&gt;
&lt;p&gt;Here are my errors: &lt;br /&gt;
1067: Implicit coercion of a value of type poeClasses:ToggleButton to an unrelated type Class. (Error occurs on the line in which I am setting emptyBottleBtn equal to a new ToggleButton.)&lt;/p&gt;
&lt;p&gt;1188: Illegal assignment to class ToggleButton. (Error occurs on the line in which I am setting emptyBottleBtn equal to a new ToggleButton.)&lt;/p&gt;
&lt;p&gt;1067: Implicit coercion of a value of type emptyGameBottle to an unrelated type poeClasses:ToggleButton. (Error occurs on the line in which I am adding emptyBottleBtn to the buttonContainer.)&lt;/p&gt;
&lt;p&gt;The movie clip on the stage is an emptyGameBottle.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;is frustrated&lt;/strong&gt; :P Thanks for any help&lt;/p&gt;
&lt;p&gt;Edit: added lines above.&lt;/p&gt;
&lt;p&gt;@SuperMario my last thread you had said to have the class extend SelectBtn. That isn&amp;#8217;t what I wanted to do so instead of having a separate class for the select graphic I put it in the button graphic as a separate frame. Now I&amp;#8217;m just trying to get my button to be of the class ToggleButton.&lt;/p&gt;</body-html>
    <created-at type="datetime">2009-11-07T12:04:19-08:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">1438502</id>
    <post-number type="integer">1</post-number>
    <topic-id type="integer">63812</topic-id>
    <updated-at type="datetime">2009-11-07T12:16:51-08:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>F=ma

fBomb = massOfBomb * accelerationOfBomb (no... not that type of fbomb :P)

*If player has bomb and presses button
*Bomb gets thrown up
*Bomb goes up and comes down
*If bomb comes back with positive hitTest on player, player catches bomb (if bomb hits something else subtract life)

You need the bomb goes up and comes down part.

fUp - fBomb = fDirection

fThrow you can pretty much play around with to get a good value. You'll probably want the direction of throw at 45 degrees since you will be running, sort of like catching a football unless you want to make catching it more difficult.

the angle will split up the fThrow to go horizontal some and vertical some. Sorry if this is all too basic.

I think you are interested in just the part that goes up right now.
fUp = fThrow * sin(45) (you'll have to convert this to radians as sin uses radians in AS)

you can check if fDirection is positive or negative to tell in which direction you are going. Remember positive will be -y and negative will be +y since the coords on the stage are upside down.

subtract fBomb from fUp for each iteration and you should get a nice parabola.</body>
    <body-html>&lt;p&gt;F=ma&lt;/p&gt;
&lt;p&gt;fBomb = massOfBomb * accelerationOfBomb (no&amp;#8230; not that type of fbomb :P)&lt;/p&gt;
&lt;p&gt;*If player has bomb and presses button&lt;br /&gt;
*Bomb gets thrown up&lt;br /&gt;
*Bomb goes up and comes down&lt;br /&gt;
*If bomb comes back with positive hitTest on player, player catches bomb (if bomb hits something else subtract life)&lt;/p&gt;
&lt;p&gt;You need the bomb goes up and comes down part.&lt;/p&gt;
&lt;p&gt;fUp &amp;#8211; fBomb = fDirection&lt;/p&gt;
&lt;p&gt;fThrow you can pretty much play around with to get a good value. You&amp;#8217;ll probably want the direction of throw at 45 degrees since you will be running, sort of like catching a football unless you want to make catching it more difficult.&lt;/p&gt;
&lt;p&gt;the angle will split up the fThrow to go horizontal some and vertical some. Sorry if this is all too basic.&lt;/p&gt;
&lt;p&gt;I think you are interested in just the part that goes up right now.&lt;br /&gt;
fUp = fThrow * sin(45) (you&amp;#8217;ll have to convert this to radians as sin uses radians in AS)&lt;/p&gt;
&lt;p&gt;you can check if fDirection is positive or negative to tell in which direction you are going. Remember positive will be -y and negative will be +y since the coords on the stage are upside down.&lt;/p&gt;
&lt;p&gt;subtract fBomb from fUp for each iteration and you should get a nice parabola.&lt;/p&gt;</body-html>
    <created-at type="datetime">2009-11-07T10:55:16-08:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">1438313</id>
    <post-number type="integer">10</post-number>
    <topic-id type="integer">63796</topic-id>
    <updated-at type="datetime">2009-11-07T10:55:16-08:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>I've just gotten to start cleaning up my code. I had moved on to some other things before taking the time to clean it up. Now I am having a new issue. I don't know much about packages and ActionScript, but I made a class and am getting a compiler error: The public attribute can only be used inside a package.

Do I have to put my classes in external files and import them or can I make them in the document class. I know having them external is better because they can be reused. When I remove public from class it says that classes cannot be nested. I can only assume, since I have checked all my brackets, that it means the classes cannot be nested in the document class.

Edit: Well I've put the class in a separate file and got it all imported ok. So it's progressing. I'll get there. The cool thing is seeing this game come together and it already looks a lot better than my first 3 games.

Edit Again: I want to dynamically import my select button from my library so that I can use one for all three buttons since the picture is the same. I'm having trouble doing so. Is there some way I can put it in my button class? Let me know if you need code posted. Thanks!</body>
    <body-html>&lt;p&gt;I&amp;#8217;ve just gotten to start cleaning up my code. I had moved on to some other things before taking the time to clean it up. Now I am having a new issue. I don&amp;#8217;t know much about packages and ActionScript, but I made a class and am getting a compiler error: The public attribute can only be used inside a package.&lt;/p&gt;
&lt;p&gt;Do I have to put my classes in external files and import them or can I make them in the document class. I know having them external is better because they can be reused. When I remove public from class it says that classes cannot be nested. I can only assume, since I have checked all my brackets, that it means the classes cannot be nested in the document class.&lt;/p&gt;
&lt;p&gt;Edit: Well I&amp;#8217;ve put the class in a separate file and got it all imported ok. So it&amp;#8217;s progressing. I&amp;#8217;ll get there. The cool thing is seeing this game come together and it already looks a lot better than my first 3 games.&lt;/p&gt;
&lt;p&gt;Edit Again: I want to dynamically import my select button from my library so that I can use one for all three buttons since the picture is the same. I&amp;#8217;m having trouble doing so. Is there some way I can put it in my button class? Let me know if you need code posted. Thanks!&lt;/p&gt;</body-html>
    <created-at type="datetime">2009-11-06T17:41:26-08:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">1436308</id>
    <post-number type="integer">6</post-number>
    <topic-id type="integer">62820</topic-id>
    <updated-at type="datetime">2009-11-06T19:38:47-08:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>Thank you 8bit. I implemented a conditional in the stage event that said only do this if I'm not clicking a button, problem resolved.

edit: 
I'm reading CS4 The Missing Manual and have gotten some of my coding style from here as well as old experience in Java. I want to post some code here for comment because I'm not sure how efficient or clean looking it is. It seems a bit bulky to me.

&lt;pre&gt;&lt;code&gt; 
//Here is one of my button functions
function emptyBottleBtnClickListener(evt:MouseEvent):void {
	selectBtnStandard.visible=true;
	emptyBottleSelected=true;
	selectBtnSuper.visible=false;
	magicBottleSelected=false;
	selectBtnSprinkles.visible=false;
	sprinklesSelected=false;
}

//Here is my stage click function
function stageClickListener(evt:MouseEvent):void {
	//unselect button then detect mouse location and 
	//place item if location is in play area
	//trace(&quot;empty &quot; + emptyBottleSelected);
	//trace(&quot;super &quot; + magicBottleSelected);
	//trace(&quot;sprinkles &quot; + sprinklesSelected);
	var xLoc:Number=stage.mouseX;
	var yLoc:Number=stage.mouseY;
	//trace(&quot;X &quot; + xLoc);

	//if the mouse coordinates are not on a button
	/*trace(&quot;emptyBottleBtnX &quot; + emptyBottleBtn.x);
	trace(&quot;emptyBottleBtnY &quot; + emptyBottleBtn.y);

	trace(&quot;magicBottleBtnX &quot; + magicBottleBtn.x);
	trace(&quot;magicBottleBtnY &quot; + magicBottleBtn.y);

	trace(&quot;sprinklesBtnX &quot; + sprinklesBtn.x);
	trace(&quot;sprinklesBtnY &quot; + sprinklesBtn.y);*/
	if (!(magicButtonClicked(xLoc, yLoc)) &amp;&amp; !(emptyButtonClicked(xLoc, yLoc)) &amp;&amp; !(sprinkleButtonClicked(xLoc, yLoc))) {
		if (emptyBottleSelected) {
			emptyBottleSelected = !(emptyBottleSelected);
			selectBtnStandard.visible=false;
			//Drop item
		} else if (magicBottleSelected) {
			magicBottleSelected = !(magicBottleSelected);
			selectBtnSuper.visible=false;
			//Drop item
		} else if (sprinklesSelected) {
			sprinklesSelected = !(sprinklesSelected);
			selectBtnSprinkles.visible=false;
			//Drop item
		} else {

		}
	}
}

//Here is to check within my stage clicking function if I am clicking a button or not
function magicButtonClicked(xLoc:Number, yLoc:Number):Boolean {
	if (xLoc &gt;= magicBottleBtn.x &amp;&amp; xLoc &lt;= (magicBottleBtn.x + magicBottleBtn.width)) {
		if (yLoc &gt;= magicBottleBtn.y &amp;&amp; yLoc &lt;= (magicBottleBtn.y + magicBottleBtn.height)) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}
 &lt;/code&gt;&lt;/pre&gt;</body>
    <body-html>&lt;p&gt;Thank you 8bit. I implemented a conditional in the stage event that said only do this if I&amp;#8217;m not clicking a button, problem resolved.&lt;/p&gt;
&lt;p&gt;edit: &lt;br /&gt;
I&amp;#8217;m reading CS4 The Missing Manual and have gotten some of my coding style from here as well as old experience in Java. I want to post some code here for comment because I&amp;#8217;m not sure how efficient or clean looking it is. It seems a bit bulky to me.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt; 
//Here is one of my button functions
function emptyBottleBtnClickListener(evt:MouseEvent):void {
	selectBtnStandard.visible=true;
	emptyBottleSelected=true;
	selectBtnSuper.visible=false;
	magicBottleSelected=false;
	selectBtnSprinkles.visible=false;
	sprinklesSelected=false;
}

//Here is my stage click function
function stageClickListener(evt:MouseEvent):void {
	//unselect button then detect mouse location and 
	//place item if location is in play area
	//trace(&quot;empty &quot; + emptyBottleSelected);
	//trace(&quot;super &quot; + magicBottleSelected);
	//trace(&quot;sprinkles &quot; + sprinklesSelected);
	var xLoc:Number=stage.mouseX;
	var yLoc:Number=stage.mouseY;
	//trace(&quot;X &quot; + xLoc);

	//if the mouse coordinates are not on a button
	/*trace(&quot;emptyBottleBtnX &quot; + emptyBottleBtn.x);
	trace(&quot;emptyBottleBtnY &quot; + emptyBottleBtn.y);

	trace(&quot;magicBottleBtnX &quot; + magicBottleBtn.x);
	trace(&quot;magicBottleBtnY &quot; + magicBottleBtn.y);

	trace(&quot;sprinklesBtnX &quot; + sprinklesBtn.x);
	trace(&quot;sprinklesBtnY &quot; + sprinklesBtn.y);*/
	if (!(magicButtonClicked(xLoc, yLoc)) &amp;amp;&amp;amp; !(emptyButtonClicked(xLoc, yLoc)) &amp;amp;&amp;amp; !(sprinkleButtonClicked(xLoc, yLoc))) {
		if (emptyBottleSelected) {
			emptyBottleSelected = !(emptyBottleSelected);
			selectBtnStandard.visible=false;
			//Drop item
		} else if (magicBottleSelected) {
			magicBottleSelected = !(magicBottleSelected);
			selectBtnSuper.visible=false;
			//Drop item
		} else if (sprinklesSelected) {
			sprinklesSelected = !(sprinklesSelected);
			selectBtnSprinkles.visible=false;
			//Drop item
		} else {

		}
	}
}

//Here is to check within my stage clicking function if I am clicking a button or not
function magicButtonClicked(xLoc:Number, yLoc:Number):Boolean {
	if (xLoc &amp;gt;= magicBottleBtn.x &amp;amp;&amp;amp; xLoc &amp;lt;= (magicBottleBtn.x + magicBottleBtn.width)) {
		if (yLoc &amp;gt;= magicBottleBtn.y &amp;amp;&amp;amp; yLoc &amp;lt;= (magicBottleBtn.y + magicBottleBtn.height)) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;
	}
}
 &lt;/code&gt;&lt;/pre&gt;</body-html>
    <created-at type="datetime">2009-10-30T14:57:21-07:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">1418664</id>
    <post-number type="integer">4</post-number>
    <topic-id type="integer">62820</topic-id>
    <updated-at type="datetime">2009-10-30T15:13:01-07:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>Sorry if this has been asked a lot. I've only looked at the first couple of pages of topics.

I am new to AS3 and am trying to make buttons that look like they are clicked when I press them. I am doing everything in the Document class. 

I have the movie clip that mimics the look of the button being depressed (a border around it) that is set as not visible, then when you click the button the mouse listener picks it up and the border turns visible. 

The issue I am having is that I want to be able to click off of the button to deselect it, but my stage mouse listener is causing the border to remain invisible even when I click a button. The mouse listener function is set to make the border invisible when I click so I believe this is conflicting with the function for the button telling the border to be visible. I think I should maybe be trying to get the mouse coordinates to determine where I have clicked and only make the border invisible if I am not clicking on any buttons.

Is this the right way to go? In AS3 I do not know how to check the coordinates of the current buttons. Is there a hit test I could use?</body>
    <body-html>&lt;p&gt;Sorry if this has been asked a lot. I&amp;#8217;ve only looked at the first couple of pages of topics.&lt;/p&gt;
&lt;p&gt;I am new to AS3 and am trying to make buttons that look like they are clicked when I press them. I am doing everything in the Document class.&lt;/p&gt;
&lt;p&gt;I have the movie clip that mimics the look of the button being depressed (a border around it) that is set as not visible, then when you click the button the mouse listener picks it up and the border turns visible.&lt;/p&gt;
&lt;p&gt;The issue I am having is that I want to be able to click off of the button to deselect it, but my stage mouse listener is causing the border to remain invisible even when I click a button. The mouse listener function is set to make the border invisible when I click so I believe this is conflicting with the function for the button telling the border to be visible. I think I should maybe be trying to get the mouse coordinates to determine where I have clicked and only make the border invisible if I am not clicking on any buttons.&lt;/p&gt;
&lt;p&gt;Is this the right way to go? In AS3 I do not know how to check the coordinates of the current buttons. Is there a hit test I could use?&lt;/p&gt;</body-html>
    <created-at type="datetime">2009-10-29T18:59:17-07:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">1417174</id>
    <post-number type="integer">1</post-number>
    <topic-id type="integer">62820</topic-id>
    <updated-at type="datetime">2009-10-29T18:59:17-07:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>I am in the document class. Thanks Unknown. I'm so new I didn't know it was called that lol.</body>
    <body-html>&lt;p&gt;I am in the document class. Thanks Unknown. I&amp;#8217;m so new I didn&amp;#8217;t know it was called that lol.&lt;/p&gt;</body-html>
    <created-at type="datetime">2009-10-29T18:15:50-07:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">1417093</id>
    <post-number type="integer">8</post-number>
    <topic-id type="integer">62790</topic-id>
    <updated-at type="datetime">2009-10-29T18:15:50-07:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>I assume you would set myMovieClip.x = myOtherMovieClip.x

I have a similar question to yours. How do I find the x and y of the mouse? Mouse.x and Mouse.y? I'm new to AS3 :P</body>
    <body-html>&lt;p&gt;I assume you would set myMovieClip.x = myOtherMovieClip.x&lt;/p&gt;
&lt;p&gt;I have a similar question to yours. How do I find the x and y of the mouse? Mouse.x and Mouse.y? I&amp;#8217;m new to AS3 :P&lt;/p&gt;</body-html>
    <created-at type="datetime">2009-10-29T17:15:59-07:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">1416898</id>
    <post-number type="integer">6</post-number>
    <topic-id type="integer">62790</topic-id>
    <updated-at type="datetime">2009-10-29T17:15:59-07:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>Thanks so much, Since I am taking my sweet time with this one I may not get to look at it for a bit. It looks confusing at first but I'm sure I can make it out. My experience comes from programming simple java programs in school. The 4 games I've made before are my first :) and I haven't as I said before done any scrolling yet. I am using AS2 right now just because I was using the Flash game programming for dummies book that is fairly old. I'll certainly have to check out your blog too.

Also thanks billo!</body>
    <body-html>&lt;p&gt;Thanks so much, Since I am taking my sweet time with this one I may not get to look at it for a bit. It looks confusing at first but I&amp;#8217;m sure I can make it out. My experience comes from programming simple java programs in school. The 4 games I&amp;#8217;ve made before are my first :) and I haven&amp;#8217;t as I said before done any scrolling yet. I am using AS2 right now just because I was using the Flash game programming for dummies book that is fairly old. I&amp;#8217;ll certainly have to check out your blog too.&lt;/p&gt;
&lt;p&gt;Also thanks billo!&lt;/p&gt;</body-html>
    <created-at type="datetime">2008-11-14T18:46:36-08:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">522912</id>
    <post-number type="integer">4</post-number>
    <topic-id type="integer">26745</topic-id>
    <updated-at type="datetime">2009-09-17T01:25:06-07:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>So I'm about to very slowly put together my first racing game and would like to know opinions on scrolling the background to keep the camera player focused. Are you guys moving the background around the player or what? Also I haven't checked out the lab that has come online so is that something worth checking out? I did play it and see that it has some basic side scrolling but the background seems to repeat whereas my track would be interactive (hitting the sides and such) Thanks for any ideas. Currently I would make the background move around the player (a la Futurama) but if there's a better way please tell :)</body>
    <body-html>&lt;p&gt;So I&amp;#8217;m about to very slowly put together my first racing game and would like to know opinions on scrolling the background to keep the camera player focused. Are you guys moving the background around the player or what? Also I haven&amp;#8217;t checked out the lab that has come online so is that something worth checking out? I did play it and see that it has some basic side scrolling but the background seems to repeat whereas my track would be interactive (hitting the sides and such) Thanks for any ideas. Currently I would make the background move around the player (a la Futurama) but if there&amp;#8217;s a better way please tell :)&lt;/p&gt;</body-html>
    <created-at type="datetime">2008-11-13T18:50:53-08:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">521698</id>
    <post-number type="integer">1</post-number>
    <topic-id type="integer">26745</topic-id>
    <updated-at type="datetime">2009-09-17T01:25:06-07:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>Yeah, in my timeline I put a shape tween instead of a motion tween on it and when it dies on screen it goes through that animation and lags quite a bit. I know for sure that I can't edit those frames in the timeline (the green ones) so I'm supposing that it's shape tweening on the fly as you put it. I was just thinking about trying to get the picture out and reputting it statically as you suggested. Other than that though your comments helped me to get some interval things going for stuff that I could take out of the main loop like enemy creation and win checking and I got my code cleaned up a lot so thanks. I'll let you know if the static image solves anything. I tried doing my collision detection and bullet motion in an interval and it didn't work out for me, it was very rough and I had to lower the interval so much that it's better to just keep it in the enterframe. I don't want my bullet position and collision detection getting out of sync if one is by frame and the other by time. Also putting it in an interval didn't help the lag anyways, it was still that animation doing it.

Edit: That's exactly what happened. When I exported the images and put them back in statically, no more lag. Thanks Jabor.</body>
    <body-html>&lt;p&gt;Yeah, in my timeline I put a shape tween instead of a motion tween on it and when it dies on screen it goes through that animation and lags quite a bit. I know for sure that I can&amp;#8217;t edit those frames in the timeline (the green ones) so I&amp;#8217;m supposing that it&amp;#8217;s shape tweening on the fly as you put it. I was just thinking about trying to get the picture out and reputting it statically as you suggested. Other than that though your comments helped me to get some interval things going for stuff that I could take out of the main loop like enemy creation and win checking and I got my code cleaned up a lot so thanks. I&amp;#8217;ll let you know if the static image solves anything. I tried doing my collision detection and bullet motion in an interval and it didn&amp;#8217;t work out for me, it was very rough and I had to lower the interval so much that it&amp;#8217;s better to just keep it in the enterframe. I don&amp;#8217;t want my bullet position and collision detection getting out of sync if one is by frame and the other by time. Also putting it in an interval didn&amp;#8217;t help the lag anyways, it was still that animation doing it.&lt;/p&gt;
&lt;p&gt;Edit: That&amp;#8217;s exactly what happened. When I exported the images and put them back in statically, no more lag. Thanks Jabor.&lt;/p&gt;</body-html>
    <created-at type="datetime">2008-09-04T00:36:44-07:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">363273</id>
    <post-number type="integer">11</post-number>
    <topic-id type="integer">19420</topic-id>
    <updated-at type="datetime">2009-09-17T00:47:30-07:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>I got that to work thanks. I haven't put my main loop in the interval yet, what I put in was the code to make a new snake and add it to the screen. That didn't clear up any lag. The only lag that I've noticed, and I can't be sure of any others because of course players are pretty vague about what's wrong in the comments, the lag comes from the death animation of 2 enemies in particular. They happen to be a mid size brown snake. The two small red ones are fine and the large green one is ok, but sticks for a sec. Could it be because I'm using a shape tween for my death animation? I had my live snake and put some red streaks then tried shape tween and it gave me a really awesome looking exploding effect as the parts are moved and recolored. Perhaps changing from a brown color to red and changing the snake into the right shape is just too intensive to process?</body>
    <body-html>&lt;p&gt;I got that to work thanks. I haven&amp;#8217;t put my main loop in the interval yet, what I put in was the code to make a new snake and add it to the screen. That didn&amp;#8217;t clear up any lag. The only lag that I&amp;#8217;ve noticed, and I can&amp;#8217;t be sure of any others because of course players are pretty vague about what&amp;#8217;s wrong in the comments, the lag comes from the death animation of 2 enemies in particular. They happen to be a mid size brown snake. The two small red ones are fine and the large green one is ok, but sticks for a sec. Could it be because I&amp;#8217;m using a shape tween for my death animation? I had my live snake and put some red streaks then tried shape tween and it gave me a really awesome looking exploding effect as the parts are moved and recolored. Perhaps changing from a brown color to red and changing the snake into the right shape is just too intensive to process?&lt;/p&gt;</body-html>
    <created-at type="datetime">2008-09-03T23:55:12-07:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">363239</id>
    <post-number type="integer">9</post-number>
    <topic-id type="integer">19420</topic-id>
    <updated-at type="datetime">2009-09-17T00:47:30-07:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>Where do I need to put my setInterval? I tried to put it in the end of my init function which runs once when the screen is loaded but it doesn't do anything. Although I knew I probably shouldn't I put it in my onEnterFrame to see what happens and it did work, but severely lagged and crashed.

That's right the pellet collision contains the death animations. I'll have a look at that too.</body>
    <body-html>&lt;p&gt;Where do I need to put my setInterval? I tried to put it in the end of my init function which runs once when the screen is loaded but it doesn&amp;#8217;t do anything. Although I knew I probably shouldn&amp;#8217;t I put it in my onEnterFrame to see what happens and it did work, but severely lagged and crashed.&lt;/p&gt;
&lt;p&gt;That&amp;#8217;s right the pellet collision contains the death animations. I&amp;#8217;ll have a look at that too.&lt;/p&gt;</body-html>
    <created-at type="datetime">2008-09-03T21:49:17-07:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">363183</id>
    <post-number type="integer">7</post-number>
    <topic-id type="integer">19420</topic-id>
    <updated-at type="datetime">2009-09-17T00:47:30-07:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>I do have some nested loops and I know from my algorithms class that that can slow it down. The lag spikes occur when more than one enemy plays the death animation. It's trying to move all the snakes, bullets, player, and do the animation at the same time. Do you have any examples or a good tutorial for doing time-based events? Everything I've learned so far goes over frame based only. 

&lt;pre&gt;
if (!gamePaused) {

	//Move each bullet and collision detect.
        for(var i = 0; i &lt; bulletArray.length; i++) {
        	var currentBullet = bulletArray[i];
        	if (currentBullet._visible == true) { //active bullets are visible
            	    movePellet(currentBullet);
            	    pelletCollision(currentBullet);
                }
   	}

	//Same as above, laser has a different graphic.
        for(var i = 0; i &lt; laserArray.length; i++) {
        	var laserBullet = laserArray[i];
        	if (laserBullet._visible == true) { //active bullets are visible
            	    movePellet(laserBullet);
            	    pelletCollision(laserBullet);
        	}
   	}
	
        //Make a new enemy, this is done after so many seconds have passed but it always checks whether enough time has passed.
        releaseASnake();
	//Snake stuff (Move and collision detection on each type of enemy)
	doLoopItem(coralArray);
	doLoopItem(milkArray);
	doLoopItem(pythonArray);
	doLoopItem(viperArray);
	doLoopItem(boaArray);
		
	followMouse();                   //Check player direction
	keyCheck();                       //Check buttons pressed
	turn(player);                       //Reorient player
	turn(pants);                       //Reorient part of player
	turn(gun);                         //Reorient weapon
	moveIt(player);                  //Move player
	moveIt(pants);                  //Move part of player
	moveGun(gun);                  //Move weapon
	playerLives = player.lives;    //Display lives
	playerScore = _root.score;  //Display score
	winChecker();                   //Check for win condition
}
&lt;/pre&gt;</body>
    <body-html>&lt;p&gt;I do have some nested loops and I know from my algorithms class that that can slow it down. The lag spikes occur when more than one enemy plays the death animation. It&amp;#8217;s trying to move all the snakes, bullets, player, and do the animation at the same time. Do you have any examples or a good tutorial for doing time-based events? Everything I&amp;#8217;ve learned so far goes over frame based only.&lt;/p&gt;
&lt;pre&gt;
if (!gamePaused) {

	//Move each bullet and collision detect.
        for(var i = 0; i &amp;lt; bulletArray.length; i++) {
        	var currentBullet = bulletArray[i];
        	if (currentBullet._visible == true) { //active bullets are visible
            	    movePellet(currentBullet);
            	    pelletCollision(currentBullet);
                }
   	}

	//Same as above, laser has a different graphic.
        for(var i = 0; i &amp;lt; laserArray.length; i++) {
        	var laserBullet = laserArray[i];
        	if (laserBullet._visible == true) { //active bullets are visible
            	    movePellet(laserBullet);
            	    pelletCollision(laserBullet);
        	}
   	}
	
        //Make a new enemy, this is done after so many seconds have passed but it always checks whether enough time has passed.
        releaseASnake();
	//Snake stuff (Move and collision detection on each type of enemy)
	doLoopItem(coralArray);
	doLoopItem(milkArray);
	doLoopItem(pythonArray);
	doLoopItem(viperArray);
	doLoopItem(boaArray);
		
	followMouse();                   //Check player direction
	keyCheck();                       //Check buttons pressed
	turn(player);                       //Reorient player
	turn(pants);                       //Reorient part of player
	turn(gun);                         //Reorient weapon
	moveIt(player);                  //Move player
	moveIt(pants);                  //Move part of player
	moveGun(gun);                  //Move weapon
	playerLives = player.lives;    //Display lives
	playerScore = _root.score;  //Display score
	winChecker();                   //Check for win condition
}
&lt;/pre&gt;</body-html>
    <created-at type="datetime">2008-09-03T16:00:45-07:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">362585</id>
    <post-number type="integer">5</post-number>
    <topic-id type="integer">19420</topic-id>
    <updated-at type="datetime">2009-09-17T00:47:30-07:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>completely frame based, when it lags up everything goes slow until it speeds up again. Everything is in a main loop in the enterframe that repeats each frame.</body>
    <body-html>&lt;p&gt;completely frame based, when it lags up everything goes slow until it speeds up again. Everything is in a main loop in the enterframe that repeats each frame.&lt;/p&gt;</body-html>
    <created-at type="datetime">2008-09-03T14:43:13-07:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">362409</id>
    <post-number type="integer">3</post-number>
    <topic-id type="integer">19420</topic-id>
    <updated-at type="datetime">2009-09-17T00:47:30-07:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>In my new game Snakes in a Parking Lot I'm getting a lot of lag. I think I'm trying to do too many things in my main loop or maybe it's how my code is organized. Any suggestions to reduce lag?</body>
    <body-html>&lt;p&gt;In my new game Snakes in a Parking Lot I&amp;#8217;m getting a lot of lag. I think I&amp;#8217;m trying to do too many things in my main loop or maybe it&amp;#8217;s how my code is organized. Any suggestions to reduce lag?&lt;/p&gt;</body-html>
    <created-at type="datetime">2008-09-03T12:42:52-07:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">362131</id>
    <post-number type="integer">1</post-number>
    <topic-id type="integer">19420</topic-id>
    <updated-at type="datetime">2009-09-17T00:47:30-07:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>I'm a noob, but in my second game I have different frames for different menus in my timeline. I find that to switch menus I have to save state from my game frame and despawn everything before switching. When I learn more I'll give what you're doing a try.</body>
    <body-html>&lt;p&gt;I&amp;#8217;m a noob, but in my second game I have different frames for different menus in my timeline. I find that to switch menus I have to save state from my game frame and despawn everything before switching. When I learn more I&amp;#8217;ll give what you&amp;#8217;re doing a try.&lt;/p&gt;</body-html>
    <created-at type="datetime">2008-09-02T15:33:44-07:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">360753</id>
    <post-number type="integer">12</post-number>
    <topic-id type="integer">19142</topic-id>
    <updated-at type="datetime">2009-09-17T00:46:06-07:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>nvm I fixed it. When I went to reuse an enemy I forgot to make the child visible when I made the parent visible.</body>
    <body-html>&lt;p&gt;nvm I fixed it. When I went to reuse an enemy I forgot to make the child visible when I made the parent visible.&lt;/p&gt;</body-html>
    <created-at type="datetime">2008-09-02T08:46:43-07:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">359753</id>
    <post-number type="integer">2</post-number>
    <topic-id type="integer">19293</topic-id>
    <updated-at type="datetime">2009-09-17T00:46:54-07:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
  <post>
    <body>I have this code within my movie clip
&lt;pre&gt;
stop();
this._visible = false;
this._parent._visible = false;
trace(this._parent._visible);
&lt;/pre&gt;

The trace shows that this parent is set to false when the enemy is shot, and the parent movie clip is as expected. But for some reason I still get hit by ghosts and in my collision code the check shows that the parent _is_ visible and the child is not.

&lt;pre&gt;
//Check collisions
function snakeCollision(theSnake) {
	if (theSnake._visible == true) {
		if (theSnake.hitTest(player)) {
			trace(&quot;Snake: &quot; + theSnake._visible);
			trace(&quot;SnakeL: &quot; + theSnake.snakeL._visible);
			if (theSnake.snakeType == &quot;milk&quot;) {
				player.lives++;
			} else {
				player.lives--;
			}
		}//End if
	}
}//End checkCollisions
&lt;/pre&gt;</body>
    <body-html>&lt;p&gt;I have this code within my movie clip&lt;br /&gt;
&lt;pre&gt;&lt;br /&gt;
stop();&lt;br /&gt;
this.&lt;em&gt;visible = false;&lt;br /&gt;
this.&lt;/em&gt;parent.&lt;em&gt;visible = false;&lt;br /&gt;
trace(this.&lt;/em&gt;parent._visible);&lt;br /&gt;
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The trace shows that this parent is set to false when the enemy is shot, and the parent movie clip is as expected. But for some reason I still get hit by ghosts and in my collision code the check shows that the parent &lt;em&gt;is&lt;/em&gt; visible and the child is not.&lt;/p&gt;
&lt;pre&gt;
//Check collisions
function snakeCollision(theSnake) {
	if (theSnake._visible == true) {
		if (theSnake.hitTest(player)) {
			trace(&quot;Snake: &quot; + theSnake._visible);
			trace(&quot;SnakeL: &quot; + theSnake.snakeL._visible);
			if (theSnake.snakeType == &quot;milk&quot;) {
				player.lives++;
			} else {
				player.lives--;
			}
		}//End if
	}
}//End checkCollisions
&lt;/pre&gt;</body-html>
    <created-at type="datetime">2008-09-01T22:26:57-07:00</created-at>
    <flaggings-count type="integer">0</flaggings-count>
    <forced-visibility-state type="boolean">true</forced-visibility-state>
    <forum-id type="integer">4</forum-id>
    <hidden-by-id type="integer" nil="true"></hidden-by-id>
    <id type="integer">359174</id>
    <post-number type="integer">1</post-number>
    <topic-id type="integer">19293</topic-id>
    <updated-at type="datetime">2009-09-17T00:46:54-07:00</updated-at>
    <user-id type="integer">604811</user-id>
  </post>
</posts>
