I'm having a little problem with this code, the idea is that the cat object follows the main character around and performs certain actions when the character is in range or out of range. on the whole the code is absolutely fine:
Expand|Select|Wrap|Line Numbers
- onClipEvent (enterFrame) {
- if (Key.isDown(Key.UP)&&((this._y - _root.Cat._y) <25)) {
- this.gotoAndStop("catstill");
- } else if (Key.isDown(Key.RIGHT) &&((this._x - _root.Cat._x)<-200)) {
- this._x += 8;
- this.gotoAndStop("catright");
- } else if (Key.isDown(Key.LEFT) && ((this._x - _root.Cat._x) > 200)){
- this._x -= 8;
- this.gotoAndStop("catleft");
- } else if ((this._y - _root.Cat._y) > 25){
- this.gotoAndStop("catjump");
- } else if ((this._y - _root.Cat._y) <25){
- this.gotoAndStop ("catstill")
- }
- if (((this._x - _root.Cat._x) > 200) && ((!Key.isDown(Key.LEFT)))){
- this._x -= 8;
- this.gotoAndStop("catleft");
- }
- if (((this._x - _root.Cat._x)<-200) && (!Key.isDown(Key.RIGHT))) {
- this._x += 8;
- this.gotoAndStop("catright");
- }
- }
Expand|Select|Wrap|Line Numbers
- if (((this._x - _root.Cat._x) > 200) && ((!Key.isDown(Key.LEFT)))){
- this._x -= 8;
- this.gotoAndStop("catleft");
- }
- if (((this._x - _root.Cat._x)<-200) && (!Key.isDown(Key.RIGHT))) {
- this._x += 8;
- this.gotoAndStop("catright");
- }
I know what is going wrong (I think) but being new to AS2 I'm not sure how to put it right. Currently if the cat is outside the 200 range it will continue towards the character until it hits that 200, then it will stop and run some other action/movie. But because of the onClipEvent(enterFrame) (I think this is the culprit) it goes to the first frame of the cat movie on each frame so all I get is a catatonic siding cat instead of the walking cat I would like(hope that I make sense).
Sorry about the code I have left the current version on a different computer so some of this is from memory.
Any help much appreciated.
CHinde