# AS2.0 Platformer

**URL:** https://forum.kirupa.com/t/as2-0-platformer/263577
**Category:** programming
**Created:** [June 17, 2008, 12:01pm UTC](https://forum.kirupa.com/t/as2-0-platformer/263577 "2008-06-17T12:01:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Lolghurt](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Lolghurt](https://forum.kirupa.com/u/Lolghurt)
#### Post date: [June 17, 2008, 12:01pm UTC](https://forum.kirupa.com/t/as2-0-platformer/263577/1 "2008-06-17T12:01:56Z")

</div>

I am working on a platformer in AS 2.0, using a modified script I found on another site. The problem is that:

1. It requires MC scripting in at least 2 objects
2. The hitTest function is buggy in any flash version after 6  
Character Script:

```auto
 
onClipEvent (load) {
xreset = _x;
left = 0;
yreset = _y;
fall = false;
_name = "circle";
jump = 0;
speed = 0;
jumpheight = 15;
maxfall = -54;
}
onClipEvent (enterFrame) {
xmin = getBounds(_root).xMin;
xmax = getBounds(_root).xMax;
ymin = getBounds(_root).yMin;
ymax = getBounds(_root).yMax;
if (Key.isDown(Key.UP) && fall == false && jump == undefined) {
fall = true;
jump = jumpheight;
}
if (jump<>undefined) {
if (jump>maxfall) {
jump--;
}
_y -= jump;
}
_x += speed;
if (Key.isDown(Key.RIGHT)) {
if (speed<=10) {
speed+=0.5;
}
} else {
if (Key.isDown(Key.LEFT)) {
if (speed>=-10) {
speed-=0.5;
}
} else {
speed *= 0.95;
}
}
if (Key.isDown(Key.SPACE)) {
_x = xreset;
_y = yreset;
}
_root._x = Stage.width/2-_x; 
_root._y = Stage.height/2-_y;
}

```

and this is on the platform(s):

```auto
 
onClipEvent (load) {
activated = false;
down = false;
}
onClipEvent (enterFrame) {
_root.report.text = Math.round(_root.circle.yMax)+" "+Math.round(yMin);
xmin = getBounds(_root).xMin;
xmax = getBounds(_root).xMax;
ymin = getBounds(_root).yMin;
ymax = getBounds(_root).yMax;
if (_root.circle.xMax>xMin && _root.circle.xMin<xMax && _root.circle.yMax<yMin) {
if (_root.circle.yMax-_root.circle.jump*2>yMin) {
_root.circle._y = ymin-_root.circle._height/2;
_root.circle.jump = undefined;
_root.circle.fall = false;
activated = true;
}
}
if (Math.round(_root.circle.yMax)>Math.round(yMin)) {
if (hitTest(_root.circle) && _root.circle.xmax<xmin) {
_root.circle._x -= _root.circle.speed;
}
if (hitTest(_root.circle) && _root.circle.xmin>xmax) {
_root.circle._x += _root.circle.speed;
}
if (hitTest(_root.circle) && _root.circle.ymin>ymax && _root.circle.jump>-1) {
_root.circle.jump = -1*(_root.circle.jump);
}
}
if (activated == true && not hitTest(_root.circle) && _root.circle.jump == undefined) {
_root.circle.jump = 0;
activated = false;
}
if (hitTest(_root.circle) && _root.circle.ymax>ymin && _root.circle.jump<>undefined && _root.circle._y<_y) {
_root.circle._y = ymin-_root.circle._height/2;
_root.circle.jump = undefined;
_root.circle.fall = false;
activated = true;
}
if (_root.circle.ymax-_root.circle.jump>ymin && _root.circle.xMin<xMax && _root.circle.xMax>xMin && _root.circle.jump<>undefined && _root.circle._y<_y) {
_root.circle._y = ymin-_root.circle._height/2;
_root.circle.jump = undefined;
_root.circle.fall = false;
activated = true;
}
}

```

Any ideas what to modify for bug correction?

---

<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: [June 17, 2008, 10:39pm UTC](https://forum.kirupa.com/t/as2-0-platformer/263577/2 "2008-06-17T22:39:20Z")

</div>

a good place to start would be to tell us what the bug is and what youve tried.

---

<div class="post-metadata">

### Author: ![Lolghurt](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Lolghurt](https://forum.kirupa.com/u/Lolghurt)
#### Post date: [June 18, 2008, 6:36am UTC](https://forum.kirupa.com/t/as2-0-platformer/263577/3 "2008-06-18T06:36:48Z")

</div>

the bug is that the landing is jumpy if you set it to AS2.0 and flash8, which i need to add filters

---

<div class="post-metadata">

### Author: ![rrh](https://avatars.discourse-cdn.com/v4/letter/r/67e7ee/32.png) [@rrh](https://forum.kirupa.com/u/rrh)
#### Post date: [June 18, 2008, 4:30pm UTC](https://forum.kirupa.com/t/as2-0-platformer/263577/4 "2008-06-18T16:30:46Z")

</div>

bugs that appear only when exported in later versions of Flash are usually caused by failing to initialize your variables. Trace a bunch of your variables, see if there’s one that’s undefined or NaN that shouldn’t be.
