I was following a tutorial on moving clips with the keypad - I got the character moving around fine, but just using 'if (Key.isDown(Key.RIGHT)' type statements, which means the sprite just moves while the key is down. So I tried to come up with a way to make the sprite move continuously using this code attached to an mc:
How can I fix it? Am I on the right track? Is there a different appraoch?Code:onClipEvent (load) { step = 5; movieWith = 300; movieHeight = 300; this.stop(); _root.dir = ""; } onClipEvent (keyDown) { if (Key.getCode() == Key.UP) { _root.dir = "up"; } else if (Key.getCode() == Key.RIGHT) { _root.dir = "right"; } else if (Key.getCode() == Key.DOWN) { _root.dir = "down"; } else if (Key.getCode() == Key.LEFT) { _root.dir = "left"; } } onClipEvent (enterFrame) { if (_root.dir="right" and this._x<300) { this.attachMovie("sprite", "bug", 10); this._x = this._x+step; this._rotation = 45; this._xscale = -100; } else if (_root.dir="left" and this._x>0) { this.attachMovie("sprite", "bug", 10); this._x = this._x-step; this._rotation = -45; this._xscale = 100; } else if (_root.dir="up" and this._y>0) { this.attachMovie("sprite", "bug", 10); this._y = this._y-step; this._rotation = 0; this._xscale = 100; } else if (_root.dir="down" and this._y<300) { this.attachMovie("sprite", "bug", 10); this._y = this._y+step; this._rotation = 180; this._xscale = 100; } else { this.attachMovie("sprite", "bug", 10); _root.dir = ""; } }




Reply With Quote