import mx.utils.Delegate; class Kid extends CustomMC { private var body: MovieClip; private var handLeft: MovieClip; private var handRight: MovieClip; private var colorParts; private var colors = [0xd4ff5c,0xf7d4d9,0xF7455B]; // private var health = 2; private var healthInterval; private function onLoad () { healthInterval = setInterval (Delegate.create(this,decHealth),6000); colorParts = [body, handLeft.hand.handClean, handRight.hand.handClean]; updateHealth(); } public function stopHealthInterval () { clearInterval(healthInterval); } private function setClipColor (clip,value) { var hex = Tools.toHex (value); var r = parseInt("0x"+hex.substr(0,2)); var g = parseInt("0x"+hex.substr(2,2)); var b = parseInt("0x"+hex.substr(4,2)); var myColor = new Color (clip); var myColorTransform = new Object(); myColorTransform.ra = -15; myColorTransform.rb = r; myColorTransform.ga = -15; myColorTransform.gb = g; myColorTransform.ba = -15; myColorTransform.bb = b; myColorTransform.aa = 100; myColorTransform.ab = 0; myColor.setTransform(myColorTransform); } private function decHealth () { health--; updateHealth(); } private function updateHealth () { if (health>=0) { gotoAndStop (health+1); for (var i in colorParts) { setClipColor (colorParts[i],colors[health]); } } else { clearInterval (healthInterval); _global.setTimeout (Delegate.create(this,explode),200); popOut(false); } } private function explode () { var d= _parent.getNextHighestDepth (); var clip = _parent.attachMovie ("Explosion","explosion"+d,d); clip.setPos(this.getPos()); _parent.free (); Engine.onKidDead(); } private function onHandClean () { if (handLeft.state=="clean" && handRight.state=="clean") { health=2; gotoAndStop ("clean"); setClipColor (handLeft,colors[health]); setClipColor (handRight,colors[health]); setClipColor (body,colors[health]); clearInterval (healthInterval); _global.setTimeout (Delegate.create(this,doPopOut),500); _global.setTimeout (Delegate.create(this,addPoints),800); _global.setTimeout (Delegate.create(this,freeToilet),1200); } } private function doPopOut () { this.popOut (true,"Pop"); } private function freeToilet () { _parent.free (); } private function addPoints () { var d= _parent.getNextHighestDepth (); var clip = _parent.attachMovie ("Points","points"+d,d); clip.setPos(this.getPos()); //clip._x=_x; //clip._y=_y; clip.textField.text = Settings.washScore; clip.popIn (true); Engine.onSaveKid(); } }