# Help with 2d platform game actionscripting

**URL:** <https://forum.kirupa.com/t/help-with-2d-platform-game-actionscripting/259739>\
**Category:** Uncategorized\
**Created:** [May 8, 2008, 9:37am UTC](https://forum.kirupa.com/t/help-with-2d-platform-game-actionscripting/259739 "2008-05-08T09:37:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cadz](https://avatars.discourse-cdn.com/v4/letter/c/c5a1d2/32.png) [@cadz](https://forum.kirupa.com/u/cadz)\
**Post date:** [May 8, 2008, 9:37am UTC](https://forum.kirupa.com/t/help-with-2d-platform-game-actionscripting/259739/1 "2008-05-08T09:37:05Z")

</div>

Hey there! 🙂 I have just started using flash MX quite a lot and Iam working on a 2d  
platform game. I have been using a tutorial on this website so far, however I have also added my own things here and there to the scripting to help my game function the way I want… by doing this I my game’s scripting is all over the place and Iam finding it difficult make certain things work… :S I was just wondering if somebody who is farmiliar with actionscripting in flash MX could possibly take the time to help me with my game, so I can make it functional 😛 this would be greatly appreciated thankyou

regards cadz xD

can be contacted via [blam\_020@hotmail.com](mailto:blam_020@hotmail.com) 🙂

---

<div class="post-metadata">

**Author:** ![cooldude88](https://avatars.discourse-cdn.com/v4/letter/c/e0b2c6/32.png) [@cooldude88](https://forum.kirupa.com/u/cooldude88)\
**Post date:** [May 8, 2008, 6:37pm UTC](https://forum.kirupa.com/t/help-with-2d-platform-game-actionscripting/259739/2 "2008-05-08T18:37:13Z")

</div>

sounds like your having some fun problems. if you can put up a code or a fla it might help so we can get an idea pof where your bugs are. o and one more thing alot of issues can come from having the code on the object if you read up a bit you can get it all on the timeline and will be around 100 times easier to debug. believe me ive been there and learned my lesson. keep your code in one spot.

---

<div class="post-metadata">

**Author:** ![cadz](https://avatars.discourse-cdn.com/v4/letter/c/c5a1d2/32.png) [@cadz](https://forum.kirupa.com/u/cadz)\
**Post date:** [May 10, 2008, 5:00am UTC](https://forum.kirupa.com/t/help-with-2d-platform-game-actionscripting/259739/3 "2008-05-10T05:00:59Z")

</div>

here is my characters coding

onClipEvent (load) {  
jumping = true;  
jump = 0;  
speed = 0;  
maxmove = 15;  
}  
onClipEvent (enterFrame) {  
if (\_root.dead) {  
this.gotoAndStop(“dead”);  
} else {  
speed \*= .93;  
if (speed\>0) {  
dir = “right”;  
} else if (speed\<0) {  
dir = “left”;  
}  
if (dir == “right” && !\_root.leftblock.hitTest(this.\_x+20, this.\_y, true)) {  
\_root.john.\_x += speed;  
\_root.sun.\_x += speed;  
\_root.score.\_x += speed;  
this.\_x += speed;  
\_root.\_x -= speed;  
}  
if (dir == “left” && !\_root.rightblock.hitTest(this.\_x-20, this.\_y, true)) {  
\_root.john.\_x += speed;  
\_root.sun.\_x += speed;  
\_root.score.\_x += speed;  
this.\_x += speed;  
\_root.\_x -= speed;  
}  
if (Key.isDown(Key.LEFT)) {  
if (speed\>-maxmove) {  
speed–;  
}  
this.gotoAndStop(“left”);  
} else if (Key.isDown(Key.RIGHT)) {  
if (speed\<maxmove) {  
speed++;  
}  
dir = “right”;  
this.\_xscale = 100;  
this.gotoAndStop(“run”);  
} else if (Key.isDown(Key.DOWN)) {  
this.gotoAndStop(“idle”);  
} else if (Key.isDown(Key.CONTROL)) {  
this.gotoAndStop(“attack”);  
attacking = true;  
speed = 0;  
} else if (speed\<1 && speed\>-1 && !attacking) {  
speed = 0;  
this.gotoAndStop(“idle”);  
}  
if (speed\<1 && speed\>-1 && !attacking) {  
speed = 0;  
this.gotoAndStop(“idle”);  
if (speed\<1 && speed\>-1 && !attacking) {  
speed = 0;  
this.gotoAndStop(“idle”);  
}  
if (Key.isDown(Key.UP) && !jumping) {  
jumping = true;  
}  
if (jumping) {  
this.gotoAndStop(“jump”);  
this.\_y -= jump;  
jump -= .5;  
if (jump\<0) {  
falling = true;  
}  
if (jump\<-15) {  
jump = -15;  
if (jump\<-15) {  
jump = -15;  
}  
}  
if (\_root.ground.hitTest(this.\_x, this.\_y, true) && falling) {  
jump = 12;  
jumping = false;  
falling = false;  
}  
}  
if (dir == “right” && !\_root.leftblock.hitTest(this.\_x+20, this.\_y, true)) {  
\_root.score.\_x += speed;  
this.\_x += speed;  
\_root.\_x -= speed;  
}  
if (dir == “left” && !\_root.rightblock.hitTest(this.\_x-20, this.\_y, true)) {  
\_root.score.\_x += speed;  
this.\_x += speed;  
\_root.\_x -= speed;  
}  
}  
}  
}  
onClipEvent (keyUp) {  
// on Key Up  
if (Key.getCode() == Key.CONTROL) {  
// if the release is control  
attacking = false;  
// attacking is false  
}  
}

and here is my enemy’s coding

onClipEvent (load) {  
enemyspeed = 2;  
//this sets the speed your enemy will move at  
enemystepsright = 0;  
//how far it has moved right  
enemystepsleft = 0;  
//how far it has moved left  
enemydir = “left”;  
//its direction is set left  
}  
onClipEvent (enterFrame) {  
if (!dead) {  
//if NOT dead  
if (enemydir == “right”) {  
//if the direction (enemydir) is right  
enemystepsright += 1;  
//its amount of steps (enemystepsright) right goes up 1  
this.\_xscale = -100;  
//\_xscale (flips character) is set to neg. 100  
this.\_x += enemyspeed;  
//its X goes up the value of enemyspeed  
} else if (enemydir == “left”) {  
//otherwise if the direction (enemydir) is left  
enemystepsleft += 1;  
//its amount of steps (enemystepsright) left goes up 1  
this.\_xscale = 100;  
//\_xscale (flips character) is set to 100  
this.\_x -= enemyspeed;  
//its X goes down the value of enemyspeed  
}  
if (enemystepsright == 100) {  
//if enemystepsright is equal to 100  
enemystepsright = 0;  
//enemystepsright is set to 0  
enemydir = “left”;  
//direction is set to left  
} else if (enemystepsleft == 100) {  
//otherwise if enemystepsleft is equal to 100  
enemystepsleft = 0;  
//enemystepsleft is set to 0  
enemydir = “right”;  
//direction is set to right  
}  
}  
}  
onClipEvent (enterFrame) {  
if (\_root.char.hitTest(this)) {  
\_root.hp–;  
}  
}  
onClipEvent (enterFrame) {  
distance = 5;  
ux = \_root.char.\_x;  
uy = \_root.char.\_y;  
hx = this.\_x;  
hy = this.\_y;  
if (Math.sqrt((ux-hx)_(ux-hx)+(uy-hy)_(uy-hx))) {  
}  
}  
onClipEvent (enterFrame) {  
if (\_root.char.hitTest(this)) {  
\_root.batman  
+= 10;  
unloadMovie(this);  
}  
}

---

<div class="post-metadata">

**Author:** ![youngtrill](https://avatars.discourse-cdn.com/v4/letter/y/6bbea6/32.png) [@youngtrill](https://forum.kirupa.com/u/youngtrill)\
**Post date:** [May 10, 2008, 10:54pm UTC](https://forum.kirupa.com/t/help-with-2d-platform-game-actionscripting/259739/4 "2008-05-10T22:54:29Z")

</div>

u should use frame coding instead of coding on movieclips

its so much faster and easier

i never use movieclip coding

the only codes on my moviclips are things like stop(); and

parent attack=false

thats so i can make it go to certain animations or make it stop attacking

but that is done by the code on the frame

message me if u dont get what im sayin
