class Key_ob extends MovieClip { //variables var scrollSpeed:Number =8; var i:Number = 0; var n:Number = 0; var collision:Boolean; var bell:Sound; var keys:Number = 0 var keyHit:Boolean = false; var time:Number = 0; //functions function setKeyPosition () { this.attachMovie ('key_mc','key'+i,i); this['key'+i]._x=350; this['key'+i]._y=3600; i++; this.attachMovie ('key_mc','key'+i,i); this['key'+i]._x=360; this['key'+i]._y=5250; i++; this.attachMovie ('key_mc','key'+i,i); this['key'+i]._x=175; this['key'+i]._y=6400; i++; this.attachMovie ('key_mc','key'+i,i); this['key'+i]._x=425; this['key'+i]._y=7700; } function collisionTest () { if (keyHit==false) { for (n=0;n<4;n++) { if (this['key'+n].hitTest(_root.sprite)) { keyHit=true; time=getTimer() + 1000; bell.start(); keys++; _root.ground.keys++; this['key'+n]._visible=false; _root.keyIndicator.gotoAndPlay (_root.keyIndicator._currentframe +4); } } } } //handlers function onEnterFrame () { if (_root.ground.scrollStop == false) { this._y -= scrollSpeed; collisionTest (); if (keyHit=true) { if (time < getTimer()) { keyHit=false; } } } } //constructor function Key_ob() { setKeyPosition (); bell= new Sound (); bell.attachSound('bell'); } }