Ord values or constants for keys

how can I get the ord values of certain keys…say if i want a function to run when the left arrow key is pressed… or right arrow key…or is there a constants list?

I’m not sure whether this is what you want, but still…

http://actionscript-toolbox.com/keyobject.php

You can also find them on the Flash help files… :sigh:

http://livedocs.macromedia.com/flash/mx2004/main/appx_c_k.htm

ok thanks guys…also on a little different note…in the past i haven’t done a lot of actionscript manipulation with objects and what not but im finding that i need to in my current project…do any of you know of a good site that can really explain objects? i mean im just not seeing the logic behind almost any of it…ive sat down at my local book store and gone over a few different books’ objects’ section and they’ll tell me how to define an object and how to use it but theres no explanation of why its defined like that or why the commands work the way they do…so anything that explains that kind of stuff would be really helpful to me right now

maybe this will help:

think of an object as an object in everyday life. For example a dog.

sparky = new Dog();

‘sparky’ is a reference to a Dog (an object). sparky can contain different methods and variables:

spary.speak = function(){
trace(“arff, arff”);
}
sparky.hairColor = “brown”;
sparky.type = “poodle”;

…just a thought :beam:

how come when i want something to happen with an onKeyDown command or something similar I have to define a function within that assignment? This kinda goes with my mis understanding of objects…if its a conditional…which it seems to me it should be as it says “onKeyDown” which would either be a yes or a no…why does it continuously run a function that i place after the equals such as:
this.onKeyDown = myFunc();
where as if i do
this.onKeyDown = function () {
blah = blah + 1;
}
it works…see this is why i really need a reference…ive gotten by with my limited understanding of flash for a long while now but i really need to understand whats happening in these statements…also another problem is im just coming out of a pascal programming class at my school and so any of you who know pascal can probably understand my confusion with returning to flash…
so if someone could explain that to me id appreciate it and like before, any kind of explanation of flash’s use of objects and assignments and so on would greatly be appreciated…I can’t control the langauge until I can comprehend it.

the key here is the parentheses
if you say obj.fun = myFunc();
the interpreter excecutes myFun immediately, and places the return value into obj.fun.
This is not what you want.
You want to set obj.fun to be the function itself, so you should be saying
obj.fun = myFunc; //no parentheses
this way, obj.fun is now a reference to the myFunc function.
you can use
obj.fun()
to execute it, or in the case of onKeyDown, flash will execute it for you when that “event” occurs. An event is not an if statement, it is an independent action that causes code to execute, as if the onKeyDown function was its own little program that flash starts up when it receives the onKeyDown command from the user.
Hope this is helpful.

thanks a lot clown, I actually understood that…i suppose if i were able to watch flash’s actions I would have been able to see what you were saying but since i can’t, thats one of those things I just need someone to tell me…thats a mistake I wont make again…also just so i can say ive said it…that explanation was probably better then any i’ve read before…being as how out of all the ones i’ve read, yours is the only one i really understant so thanks again.

out of curiousity, to solve my current problem…for objects to evaluate to true in the hitTest() do they have to be of the same depth?

no

i love your sense of humor norie

based on your site, that is

thank you :beam:

does anyone see anything wrong with this script:
if (this.hitTest(_root.Ball)) {
if ((_root.Ball._x + Radius > this._x)&&
(_root.Ball._x - Radius < this._x + this._width)) {
BallYSpeed = -(BallYSpeed);
}else{
BallXSpeed = -(BallXSpeed);
}
this._visible = FALSE;
}

without knowing the rest of your code/fla, no. oh wait, it is missing ONE thing, ’

' tags. Please use them when posting code on here. :beam:

_root.Frame1:
/* Constants Section */
_global.Dead = FALSE;  // TRUE if player has lost, FALSE if player hasn't lost
var BallXSpeed = random(7) - 4;  // Horizontal distance traved in one movement of ball
var BallYSpeed = 10;  // Vertical distance traveled in one movement of ball
var MoveAmount = 20;  // Horizontal distance pad moves with one key press
_global.PadHeight = 10;  // Vertical size of user's pad
_global.PadWidth  = 130;  // Horizontal size of user's pad
var NumBlocks = 10;  // Number of blocks per row
var NumRows = 4;  // Number of rows of blocks
_global.StageWidth = Stage.width;  // Horizontal size of Stage in pixels
_global.StageHeight = Stage.height;  // Vertical size of Stage in pixels
var BlockWidth = StageWidth/NumBlocks;  // Horizontal size of blocks in pixels
var BlockHeight = BlockWidth/2;  // Vertical size of blocks in pixels
/* End Constants Section */
var BlockName = " ";  // used to name blocks

//Generate Rows Of Blocks 
for (RowCount = 1; RowCount <= NumRows; RowCount += 1) {
	for (BlockCount = 1; BlockCount <= NumBlocks; BlockCount += 1) {
		BlockName = "Block"+BlockCount+"Row"+RowCount;
		this.attachMovie("Block",BlockName,
						 ((RowCount*NumBlocks - NumBlocks)+BlockCount));
		with (_root[BlockName]) {
			_x = BlockWidth * BlockCount - BlockWidth;
			_y = BlockHeight * RowCount - BlockHeight;
			_width = BlockWidth;
			_height = BlockHeight;
		}
	}
}
//End Block Generation

_root.Frame2:
stop();


Block.Frame1:
BallXSpeed = _root.BallXSpeed;
BallYSpeed = _root.BallYSpeed;
if (this.hitTest(_root.Ball)) {
	if ((_root.Ball._x + Radius > this._x)&&
		 (_root.Ball._x - Radius < this._x + this._width)) {
		BallYSpeed = -(BallYSpeed);
	}else{
		BallXSpeed = -(BallXSpeed);
	}
}



Block.Frame2:
if (this.hitTest(_root.Ball)) {
	if ((_root.Ball._x + Radius > this._x)&&
		 (_root.Ball._x - Radius < this._x + this._width)) {
		BallYSpeed = -(BallYSpeed);
	}else{
		BallXSpeed = -(BallXSpeed);
	}
}



Block.Frame3:
gotoAndPlay(2);


Ball.Frame1:
var BallXSpeed = _root.BallXSpeed;
var BallYSpeed = _root.BallYSpeed;
function CheckBoundaries() {
	var Radius = this._width/2;
	if ((this._x - Radius + BallXSpeed) < 0) {
		this._x = 0 + Radius;
		BallXSpeed = -(BallXSpeed);
	}else{
		if ((this._x + Radius + BallXSpeed) > Stage.width) {
			this._x = Stage.width - Radius;
			BallXSpeed = -(BallXSpeed);
		}
	}
	if ((this._y - Radius + BallYSpeed) < 0) {
		this._y = 0 + Radius;
		BallYSpeed = -(BallYSpeed);
	}else{
		if ((this._y + Radius) > Stage.height) {
			Dead = TRUE;
		}
	}
	if (this.hitTest(_root.Pad)) {
		BallYSpeed = -(BallYSpeed);
	}
}
function MoveBall() {
	this._x = this._x + BallXSpeed;
	this._y = this._y + BallYSpeed;
}



Ball.Frame2:
CheckBoundaries();
MoveBall();

Ball.Frame3:
CheckBoundaries();
MoveBall();
gotoAndPlay(2);

Pad.Fram1:
this._width = PadWidth;     //Global Variable
this._height = PadHeight;   //Global Variable 
this._x = Stage.width/2;
this._y = Stage.height - (this._height + 2);


function MoveLeft() {
	if (this._x - (this._width / 2) - _root.MoveAmount <= 0) {
		this._x = 0 + (this._width / 2);
	}else{
		this._x = this._x - _root.MoveAmount;
	}
}
function MoveRight() {
	if ((this._x + (this._width /2) + _root.MoveAmount) >= Stage.width) {
		this._x = Stage.width - (this._width / 2);
	}else{
		this._x = this._x + _root.MoveAmount;
	}
}
padListener = new Object();
padListener.onKeyDown = function () {
	var KeyPressed = Key.getCode();
	
	if (KeyPressed == Key.LEFT) {
		MoveLeft();
	}
	
	if (KeyPressed == Key.RIGHT) {
		MoveRight();
	}
}
Key.addListener(padListener);


Hope I got those tags right.

Um basically the root actions set some constants and global variables in what is going to be basically a simple recreation of the game Breakout. Right now, with those actions, I have a ball that bounces off the left, right, and top sides of the screen and bounces off the pad. As you can see in the code for the Block mc, which by the way is duplicated by the number of blocks and then number of rows, I try to have the Ball’s speed invert when it hits the blocks. This same line of code works in the Ball’s mc to change the global variable, but it doesn’t work in the Block mc to change the global variable.

For Example: This code segment comes from above:
"if (this.hitTest(_root.Pad)) {
BallYSpeed = -(BallYSpeed);
}"
that is from the Ball mc and works fine, however this one from the Block mc does not:
"if (this.hitTest(_root.Ball)) {
if ((_root.Ball._x + Radius > this._x)&&
(_root.Ball._x - Radius < this._x + this._width)) {
BallYSpeed = -(BallYSpeed);
}else{
BallXSpeed = -(BallXSpeed);
}
}"
So like I said, the same assignment to BallXSpeed and BallYSpeed, yet the ball doesn’t chagne directions. Can anyone find problems here? Please point out all that you see.

NOTES OF INTEREST: I have of course tried fixing the problem myself but have been unsuccessful. I did some echo checking in the Block actions. I do know for certain that when the ball makes contact with a block, the block acknowledges it. Therefore I know it enters that if statement about the hitTest(). At that point I couldn’t figure out why it wasn’t adjusting the global speeds of the ball so I traced those as well. The output says that the balls direction is changing, yet there is no visual change in direction, that is, the ball continues on its current course until it hits a wall.

Its all very confusing to me…and with the way I am presenting the data I doubt any of you will be able to figure it out…but I have to try. Thanks.

nm guys…after a couple hours im back on the right track…my variables had their paths all messed up…sorry to bother you all