Be a Supporter!
Response to: How do YOU come up with ideas? Posted February 28th, 2014 in Animation

In all seriousness, i over-exaggerated idea's that already exist.
for example:

At 2/23/14 06:01 AM, Celshaded wrote:

:and will drop what im doing immediately to write it down before I forget.

That's perfect animation idea in its self, does he stop having sex with his wife to write down idea's?
Does he stop holding the door open for a crippled old lady?
Does he take his hands off the wheel whilst driving on the freeway.

Exaggeration is one of my favorite tools for creating little bits of humor.

Response to: How do YOU come up with ideas? Posted February 28th, 2014 in Animation

I do drugs.

Response to: MovieClip Rotation Posted February 27th, 2014 in Game Development

At 2/27/14 10:18 PM, Sam wrote: While your enthusiasm is great, you're making very basic mistakes. Your init was a separate function a few examples ago, and along the way it somehow made its way into your Main function (the constructor).

Here's a bit of advice: forget about the stage for now. Your Main class is your entry point to your game - you don't need the stage for things like addChild, addEventListener.

Do you think you could give me somewhat of a practice problem?
something that'll help grasp the idea a little better.
I'm trying to learn how to do this because it's organized better and make's things more simple down the road, but right now i'm struggling to understand how it works and implement it into my current project.

Response to: MovieClip Rotation Posted February 27th, 2014 in Game Development

At 2/27/14 09:24 PM, Sam wrote: Your code needs to be in functions, but your addEventListeners are not.

like this?

package 
{
	import flash.display.MovieClip;
	import flash.events.Event;

	public class Main extends MovieClip
	{
		private var dog:MovieClip = new Dog();
		public function Main():void
		{
			addChild(dog);
			if (stage)
			{
				init();
			}
			else
			{
				addEventListener(Event.ADDED_TO_STAGE, init);
			}
			function init(e:Event = null):void
			{
				removeEventListener(Event.ADDED_TO_STAGE, init);
			}
		}
		public function moveDog(Event)
		{
			stage.addEventListener(Event.ENTER_FRAME, moveDog);
			dog.x +=  5;
		}

	}
}

because this doesn't have any errors, but it also doesn't add 5 to x.

Response to: MovieClip Rotation Posted February 27th, 2014 in Game Development

At 2/27/14 09:19 PM, Jawnduss wrote: I don't get any errors, but the dog.x += 5; doesn't happen.

Strike that, I get the same error as from my other post, it isn't recognizing the functions or the stage.

Response to: MovieClip Rotation Posted February 27th, 2014 in Game Development

Okay, so still working with the dog example i tried this based on a combination of stuff from that article, and the code you pasted:

package 
{
	import flash.display.MovieClip;
	import flash.events.Event;

	public class Main extends MovieClip
	{
		private var dog:MovieClip = new Dog();
		public function Main()
		{
			addChild(dog);
			if (stage)
			{
				init();
			}
			else
			{
				addEventListener(Event.ADDED_TO_STAGE, init);
			}
			function init(e:Event = null):void
			{
				removeEventListener(Event.ADDED_TO_STAGE, init);
			}
		}
		stage.addEventListener(Event.ENTER_FRAME, moveDog);
		public function moveDog(Event)
		{
			dog.x +=  5;
		}

	}
}

I don't get any errors, but the dog.x += 5; doesn't happen.

Response to: MovieClip Rotation Posted February 27th, 2014 in Game Development

This worked fantastically, and i feel like it helps me to understand the context of class files better.
however, I don't understand how this could help me with the situation of my project.

package 
{
	import flash.ui.Keyboard;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.display.MovieClip;

	public class Main extends MovieClip
	{
		var keys:Object = {};

		public function Main():void
		{
			if (stage)
			{
				init();
			}
			else
			{
				addEventListener(Event.ADDED_TO_STAGE, init);
			}
		}
		public function init(e:Event = null):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
		}


		stage.addEventListener(Event.ENTER_FRAME, update);
		public function update(e:Event):void
		{

			var backSpeed:Number = 3;
			var speed:Number = 8;

			if (keys[Keyboard.RIGHT])
			{
				spaceShip.rotation +=  3;
				if (spaceShip.rotation >= 15)
				{
					spaceShip.rotation -=  3;
				}
				spaceShip.x +=  speed;
			}
			if (keys[Keyboard.LEFT])
			{
				spaceShip.rotation -=  3;
				if (spaceShip.rotation <= -15)
				{
					spaceShip.rotation +=  3;
				}
				spaceShip.x -=  speed;
			}
			if (keys[Keyboard.UP])
			{
				spaceShip.rotation *=  .5;
				spaceShip.y -=  speed;
			}
			if (keys[Keyboard.DOWN])
			{
				spaceShip.rotation *=  .9;
				spaceShip.y +=  backSpeed;
			}
		}

		stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
		public function onKeyDown(e:KeyboardEvent):void
		{
			keys[e.keyCode] = true;
		}

		stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
		public function onKeyUp(e:KeyboardEvent):void
		{
			keys[e.keyCode] = false;
		}
	}
}

It's saying that all of the function names, and the stage are undefined.
Do you know any tutorials for working with the stage?

Response to: MovieClip Rotation Posted February 27th, 2014 in Game Development

Now it's telling me that "dog" is an undefined properties and "addChild" is an undefined method.

but the var dog is given under the class definition, and addChild is in the constructor because I want it to do so on start-up.

Response to: MovieClip Rotation Posted February 27th, 2014 in Game Development

At 2/27/14 12:21 PM, milchreis wrote: Think logically. Why would you want to add the dog to itself?

So then we would be adding the dog to the stage.

So then I would have to create a separate .as file (Main) and do this:

package 
{
	import flash.display.MovieClip;
	public class Main extends MovieClip
	{
		var dog:MovieClip = new Dog();

		public function Main();
		{
			addChild(dog);
		}
	}
};
Response to: MovieClip Rotation Posted February 27th, 2014 in Game Development

At 2/27/14 04:34 AM, milchreis wrote: Into which file did you copy the addChild code?
Hopefully not into Dog.as

it was Dog.as, it didn't specify where to put it.

Response to: MovieClip Rotation Posted February 27th, 2014 in Game Development

At 2/26/14 05:21 AM, milchreis wrote: Take a look at this, "Understanding Classes in AS3":
http://www.untoldentertainment.com/blog/flash-and-actionscript-911/
It's written to help people transition from timeline to class based code.

So i tried this one http://www.untoldentertainment.com/blog/2009/09/09/tutorial-understanding-classes-in-as3-part-2/
I attempted to follow along with the example but, It wouldn't work for me.
I created the symbol "A Dog Symbol" Linked it to the class Dog, saved the .as file as Dog.as than literally copied and pasted all the code (including the addChild example) to the .as, saved both and tested, and no trace.

Response to: MovieClip Rotation Posted February 26th, 2014 in Game Development

Just doing some research and here's something i found out that i need some help to clarifying.
In the code I recently posted I have some event listeners that happen on stage.
Clearly this is wrong considering the stage would then have to be added to the stage before the event listener can listen for the event.
Now how the hell are you supposed to go about that?
I though this transition from writing on frame to class documents would be easier than this, I mean not much easier but still.
If anyone can clarify the above for me, i would really appreciate it.

Response to: MovieClip Rotation Posted February 25th, 2014 in Game Development

So here is my code after trying to switch everything into a .as file

package 
{
	import flash.ui.Keyboard;
	import flash.events.Event;
	import flash.events.KeyboardEvent;

	public class Main extends MovieClip
	{
		public var keys:Array = [];
	}
	//Movement
	//-------------------------------------------------------------------------------------------------

	stage.addEventListener(Event.ENTER_FRAME, update);
	stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
	stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);

	public function update(e:Event):void
	{
	public var backSpeed:Number = 3;
	public var speed:Number = 8;
		
		if (keys[Keyboard.RIGHT])
		{
			spaceShip.rotation +=  3;
			if (spaceShip.rotation >= 15)
			{
				spaceShip.rotation -=  3;
			}
			spaceShip.x +=  speed;
		}
		if (keys[Keyboard.LEFT])
		{
			spaceShip.rotation -=  3;
			if (spaceShip.rotation <= -15)
			{
				spaceShip.rotation +=  3;
			}
			spaceShip.x -=  speed;
		}
		if (keys[Keyboard.UP])
		{
			spaceShip.rotation *=  .5;
			spaceShip.y -=  speed;
		}
		if (keys[Keyboard.DOWN])
		{
			spaceShip.rotation *=  .9;
			spaceShip.y +=  backSpeed;
		}
	}

	public function onKeyDown(e:KeyboardEvent):void
	{
		keys[e.keyCode] = true;
	}

	public function onKeyUp(e:KeyboardEvent):void
	{
		keys[e.keyCode] = false;
	}

	//Movement
	//-------------------------------------------------------------------------------------------------

	//Scrolling and Boarder Management
	//-------------------------------------------------------------------------------------------------

	stage.addEventListener( Event.ENTER_FRAME, onEnterFrame );
	public function onEnterFrame( evt:Event ):void
	{
		spaceShip.y +=  3;
		Background1.y +=  5;
		if (Background1.y > 700)
		{
			Background1.y = 0;
		}
		Background2.y +=  5;
		if (Background2.y > 700)
		{
			Background2.y = 0;
		}
		if (spaceShip.x > 400)
		{
			spaceShip.x -=  7;
		}
		if (spaceShip.x < 0)
		{
			spaceShip.x +=  7;
		}
		if (spaceShip.y > 615)
		{
			spaceShip.y -=  3;
		}
		if (spaceShip.y < 15)
		{
			spaceShip.y +=  7;
		}

	}
	//Scrolling and Boarder Management
	//-------------------------------------------------------------------------------------------------
}

I'm getting an error 1114: The public attribute can only be used inside a package.
I don't really trust myself on having transferred to code to package correctly, but if someone can show me what i did wrong it would really help me understand how to do it better.

Response to: MovieClip Rotation Posted February 25th, 2014 in Game Development

Here are 2 options:
1) copy the line from the ENTER_FRAME and put it into your code modified so it manipulates your ship.

this helped, thanks :)

2) use my code entirely, therefore, read this link:
http://code.tutsplus.com/tutorials/how-to-use-a-document-class-in-flash--active-3233
My code is a document class. Create another .fla file as suggested in the article.
This allows you to play around with it and see what's going on.

and that last tut you sent me really helped so i'll make sure to check out this one.

If you have errors, problems or questions, don't hate to ask here.

and i'll be sure to ask, thanks :)

Response to: MovieClip Rotation Posted February 25th, 2014 in Game Development

I hate to ask, but what are the chances you can add comments to this to help me understand it?
I'm still on a beginner level with AS3, and there's somethings going on this code that i don't understand. Such as: The Shape variable type and the function init.

At 2/25/14 12:29 PM, milchreis wrote: //here's some demo:

package
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;

public class Main extends Sprite
{
private var ship:Shape;

public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}

private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point

ship = new Shape;
ship.graphics.beginFill(0xff0000);
ship.graphics.lineTo(10, 30);
ship.graphics.lineTo(-10, 30);
ship.graphics.lineTo(0, 0);
ship.graphics.endFill();

addChild(ship);

ship.x = ship.y = 200;

addEventListener(Event.ENTER_FRAME, loop);
stage.addEventListener(MouseEvent.CLICK, click);
}

private function click(e:MouseEvent):void
{
ship.rotation = Math.random() * 180 - 90;
}

private function loop(e:Event):void
{
ship.rotation *= .9; // this causes the rotation to go back to 0.
}

}

}

If you want a constant speed of rotation, you have to subtract from it.
This would also require checking when 0 is reached.

If it's too much to ask I understand, but I'm eager to learn and I'll do anything to do so.

Response to: MovieClip Rotation Posted February 25th, 2014 in Game Development

At 2/25/14 05:23 AM, milchreis wrote:

This is what i was attempting to accomplish

I don't really understand what you mean here, do you want the rotation to slowly go back to 0 while somebody presses UP?

But this is ideally what i want.

:Or should this happen regardless if UP is pressed?

And this was a mistake, i was experimenting with something that i forgot to take out before posting this.

if (keys[Keyboard.UP,false])
{
trace("what");
}
That's just wrong, what do you want to do here?
Response to: MovieClip Rotation Posted February 25th, 2014 in Game Development

Here is the current code for the movement of my game

import flash.ui.Keyboard;
import flash.events.Event;
import flash.events.KeyboardEvent;

stage.addEventListener(Event.ENTER_FRAME, update);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);

var keys:Array = [];

function update(e:Event):void
{
	if (keys[Keyboard.RIGHT])
	{
		spaceShip.rotation +=  3;
		if (spaceShip.rotation >= 15)
		{
			spaceShip.rotation -=  3;
		}
		spaceShip.x +=  7;
	}

	if (keys[Keyboard.LEFT])
	{
		spaceShip.rotation -=  3;
		if (spaceShip.rotation <= -15)
		{
			spaceShip.rotation +=  3;
		}
		spaceShip.x -=  7;
	}
	if (keys[Keyboard.UP])
	{
		spaceShip.y -=  7;
	}
	if (keys[Keyboard.DOWN])
	{
		spaceShip.y +=  3;
	}
	if (keys[Keyboard.UP,false])
	{
		trace("what");
	}
}

function onKeyDown(e:KeyboardEvent):void
{
	keys[e.keyCode] = true;
}

function onKeyUp(e:KeyboardEvent):void
{
	keys[e.keyCode] = false;
}
MovieClip Rotation Posted February 25th, 2014 in Game Development

It seems pretty simple, basically I have the movement code for an asteroids type game, but to make it look more alive i would like to make it so that when the char. moves left, the movieclip rotates up to a maximum of say, 15. This; i was able to make happen. however i tried to make it so that pressing UP would return it to 0, and though i could get it to return to 0, i couldn't get it to return to 0 periodically say, in intervals of 3.

Response to: Making Packages? Posted February 25th, 2014 in Game Development

:there are a few IDEs out there, but I prefer Flashdevelop, which is also free and open source.
I just recently downloaded this but haven't actually used it yet, i'll check that tutorial probably later tomorrow though.

Making Packages? Posted February 25th, 2014 in Game Development

So, I recently invested a lot of time into a simple Space Invaders like game, I've gotten the movements, scrolling background and health bar all set up.
I decided that, before i go any further I should put everything into a package and separate the files (animations and code) because I've been told writing directly onto the frames can be problematic. If anyone could tell me the difference between writing in these two ways (on frame and externally) I would appreciate it.
I know it's set up differently, but i don't know how to approach the external version, if anyone knows any good tutorials or anything, or has any good advice or can simplify anything for me I would greatly appreciate it.
Everyone here has proven to be so helpful over these past few weeks that I decided to take a journey into action script and i really just hope i'm not being too much of a burden by asking these simple questions.

Response to: && Statement For Multiple Key_up Posted February 24th, 2014 in Game Development

At 2/24/14 12:52 PM, milchreis wrote: Add the listeners to the stage.

that was a stupid mistake... haha, sorry.

Response to: && Statement For Multiple Key_up Posted February 24th, 2014 in Game Development

Although, if you go to the .SWF project you'll notice that they key recognition occurs after clicking on one of the buttons along the sides.
Any idea's why?
Here is the .SWF: http://www.newgrounds.com/dump/item/925a24d9c4ee595b29b3ac0202eb3dc8

I meant to add that I want to occur whenever the keys are pressed, without having to click the buttons first.

Response to: && Statement For Multiple Key_up Posted February 24th, 2014 in Game Development

I put the Keyboard Events and the Mouse Events together and got this:

import flash.events.MouseEvent;
import flash.events.KeyboardEvent;

var framenumber:Number = 1;
var Shift:Boolean = false;
var Up:Boolean = false;
var Down:Boolean = false;

FrameNumber.text = String(framenumber);

up.addEventListener(MouseEvent.CLICK, upaction);
function upaction(ev:MouseEvent)
{
	if (framenumber >= 10 )
	{
		framenumber = 0;
	}
	framenumber +=  1;
	actionFrame.gotoAndStop(framenumber);
	trace(framenumber);
	FrameNumber.text = String(framenumber);
}

up2.addEventListener(MouseEvent.CLICK, upaction);

down.addEventListener(MouseEvent.CLICK, downaction);
function downaction(ev:MouseEvent)
{
	if (framenumber <= 1 )
	{
		framenumber = 11;
	}

	framenumber -=  1;
	actionFrame.gotoAndStop(framenumber);
	trace(framenumber);
	FrameNumber.text = String(framenumber);
}

down2.addEventListener(MouseEvent.CLICK, downaction);

addEventListener(KeyboardEvent.KEY_DOWN, onKeyPress);

function onKeyPress(e:KeyboardEvent):void
{
	if (e.keyCode == 16)
	{
		Shift = true;
	}
	if (e.keyCode == 38)
	{
		Up = true;
	}
	if (e.keyCode == 40)
	{
		Down = true;
	}
	if (Shift && Up)
	{
		if (framenumber >= 10 )
		{
			framenumber = 0;
		}
		framenumber +=  1;
		actionFrame.gotoAndStop(framenumber);
		trace(framenumber);
		FrameNumber.text = String(framenumber);
	}
	if (Shift && Down)
	{
		if (framenumber <= 1 )
		{
			framenumber = 11;
		}

		framenumber -=  1;
		actionFrame.gotoAndStop(framenumber);
		trace(framenumber);
		FrameNumber.text = String(framenumber);
	}
}
addEventListener(KeyboardEvent.KEY_UP, onKeyUp);

function onKeyUp(e:KeyboardEvent):void
{
	if (e.keyCode == 16)
	{
		Shift = false;
	}
	if (e.keyCode == 38)
	{
		Up = false;
	}
	if (e.keyCode == 40)
	{
		Down = false;
	}
}

Although, if you go to the .SWF project you'll notice that they key recognition occurs after clicking on one of the buttons along the sides.
Any idea's why?
Here is the .SWF: http://www.newgrounds.com/dump/item/925a24d9c4ee595b29b3ac0202eb3dc8

Response to: && Statement For Multiple Key_up Posted February 24th, 2014 in Game Development

Knight, that worked perfectly.
I understand the first half, but this:

function onKeyUp(e:KeyboardEvent):void
{
	if (e.keyCode == 16)
	{
		shift = false;
	}
	if (e.keyCode == 38)
	{
		up = false;
	}
}

threw me off, could you explain this function a little better for me please?

Response to: && Statement For Multiple Key_up Posted February 24th, 2014 in Game Development

You have to set one listener to listen to KeyUp, and set the value to false there. Settings value to false in KeyDown isn't correct.

This kind of drove it home, I'm not really somewhere I can test this yet, but I'll have to try it out.
I'm trying to learn this just based off some forums I've read, so asking questions and getting answers and everything to make sure I'm practicing things properly isn't exactly an option.
But I do appreciate the help and will give an update when I get the chance

Response to: && Statement For Multiple Key_up Posted February 24th, 2014 in Game Development

Alright.
Since the event is fire when a single key is pressed, so you'll need to store the value that the key is pressed somewhere. Oh and you'll need to listen to key release event as well, because you'll have to change the value back when that key is released.

Isn't that kind of what I did here?

var shift: Boolean = false;
var up: Boolean = false;
var frameNumber: Number = 1;
stage.addEventListener(KeyboardEvent.KEY_DOWN, shiftdown);
function shiftdown (event:KeyboardEvent)
{
if(event.keyCode == Keyboard.SHIFT)
{
shift == true;
updown();
}
else
{
shift == false;
}
}
stage.addEventListiner(KeyboardEvent.KEY_DOWN, updown);
function updown(event:KeyBoardEvent)
{
if(event.keyCode == Keyboard.UP)
{
up == true;
}
else
{
up == false;
}
if(shift == true; && up == true;)
{
framenumber ++;
}
}

As I said before, ignore any minor syntax errors

Response to: && Statement For Multiple Key_up Posted February 24th, 2014 in Game Development

At 2/24/14 01:58 AM, Knight52 wrote: I believe you're in need of OR statement.

From the look of the code, I guess you want the code to execute if either key is lifted. In that case replace && with || in original code and it should do the job.

Actually I only want it to help if both keys are pressed.
In the case of shift being held / pressed
And up being pressed

Response to: && Statement For Multiple Key_up Posted February 24th, 2014 in Game Development

At 2/24/14 12:58 AM, MSGhero wrote:
At 2/24/14 12:41 AM, Jawnduss wrote:
If your next question will be "How do I press the key but not hold it down?", then you might as well just use the key class I linked you.

I might not mind that if i knew how to..
I started to learn Action Script back in AS2 and it was a lot more simple, and now i'm just having trouble adjusting..
I really don't understand the idea of the class you linked, or how I would go about using it.
I'm sorry to start so much trouble.

Response to: Lost with this math Posted February 24th, 2014 in Game Development

:Basically, whenever your if-statement evaluated to true you changed the value of framenumber, which made FrameNumber.text represent what framenumber used to be, but not what it is.

That's really helpful, thank you so much! :)

Response to: && Statement For Multiple Key_up Posted February 24th, 2014 in Game Development

sorry, just noticed some errors in that last one.

var shift:Boolean = false;
var up:Boolean = false;

stage.addEventListener(KeyboardEvent.KEY_DOWN, down);
function down(event:KeyboardEvent)
{
	if (event.keyCode == 16)
	{
		shift == true;
	}
	else
	{
		shift == false;
	}
	if (event.keyCode == 38)
	{
		up == true;
	}
	else
	{
		up == false;
	}
	if (shift == true && up == true)
	{
		trace("it works");
	}
}