class Poopies extends MovieClip{ public static var IDLE:Number = 0; public static var SAD:Number = 1; public static var HAPPY:Number = 2; public static var WONDER:Number = 3; public static var ANGRY:Number = 4; public static var LOVE:Number = 5; public static var CRAZY:Number = 6; private var poo:MovieClip; private var timeInterval:Number; private var speedx:Number; private var speedy:Number; private var newState:Number; private var deleteTime:Number = 30; function Poopies(){ super(); trace("i am a new poopie"); } public function init(stage):Void{ _x = Math.floor(Math.random()*7)*80; _y = Math.floor(Math.random()*5)*80; newState = Math.floor(Math.random()*6); setState(newState); poo = attachMovie("p", "poo", 1); onEnterFrame = changeState; timeInterval = setInterval(this, "changeState", 600); trace("poopie created!"); } public function changeState(){ newState = Math.floor(Math.random()*6); poo.setState(newState); deleteTime--; if(deleteTime <= 0){ clearInterval(timeInterval); removeMovieClip(this); } } public function setState(newState:Number):Void{ switch(newState){ case Poopies.HAPPY: this.gotoAndStop("HAPPY"); break; case Poopies.SAD: this.gotoAndStop("SAD"); break; case Poopies.IDLE: this.gotoAndStop("IDLE"); break; case Poopies.WONDER: this.gotoAndStop("WONDER"); break; case Poopies.ANGRY: this.gotoAndStop("ANGRY"); break; case Poopies.LOVE: this.gotoAndStop("LOVE"); break; case Poopies.CRAZY: this.gotoAndStop("CRAZY"); break; } } }