import mx.utils.Delegate; class Gubbe { var falis:MovieClip; var mc:MovieClip; var hojd:Number; var bredd:Number; var x:Number; var y:Number; var klockId:Number; var riktning:String = "stilla"; var filmbredd:Number = 550; private var intervalId:Number; private var duration:Number = 10; function Gubbe(mc:MovieClip, startX:Number, startY:Number, lager:Number) { this.mc = mc; trace("Gubbe skapad"); this.falis = mc.attachMovie("fahl_stilla", "x", lager); var sidproportioner:Number = falis._height/falis._width; this.hojd = 70; this.bredd = this.hojd/sidproportioner; this.falis._height = this.hojd; this.falis._width = this.bredd; this.falis._x = startX; this.falis._y = startY; this.x = this.falis._x; this.y = this.falis._y; Key.addListener({onKeyDown:Delegate.create(this, knappTryck)}); _root.addEventListener("enterFrame", mx.utils.Delegate.create(this, Ga)); beginInterval(); } private function beginInterval():Void { if (intervalId != null) { clearInterval(intervalId); } intervalId = setInterval(this, "Ga", duration); } public function knappTryck():Void { switch (Key.getCode()) { case Key.RIGHT : if (this.riktning == "höger") { bytGubbe("fahl_stilla"); this.falis._xscale *= 1; this.riktning = "högerstopp"; } else { bytGubbe("fahl_promenadfilm"); this.falis._xscale *= 1; this.riktning = "höger"; } break; case Key.LEFT : if (this.riktning == "vänster") { bytGubbe("fahl_stilla"); this.falis._xscale *= -1; this.riktning = "vänsterstopp"; } else { bytGubbe("fahl_promenadfilm"); this.falis._xscale *= -1; this.riktning = "vänster"; } break; case Key.UP : bytGubbe("fahl_stilla"); this.riktning = "stilla"; break; } } private function bytGubbe(filmNamn:String) { this.falis = this.mc.attachMovie(filmNamn, "x", 5); this.falis._x = this.x; this.falis._y = this.y; this.falis._height = this.hojd; this.falis._width = this.bredd; } public function stoppa():Void{ this.riktning = "stilla"; var xSkala = this.falis._xscale; bytGubbe("fahl_stilla"); if (xSkala < 0){ this.falis._xscale *= -1; } trace("stilla"); } public function Ga():Void { switch (this.riktning) { case "höger" : if (this.x14) { this.x -= 1; this.falis._x = this.x; } break; case "stilla" : break; } } }