//Classes must always be wrapped in a package package { //importing display elements that we can use in this class import flash.display.*; import flash.events.*; //defining the class name and saying that it //extends the MovieClip class, meaning that it has the same //properties as a movieclip public class STAR extends MovieClip { public var MCBall:MovieClip; public var myscore:Number; //The main timeline! private var _root:MovieClip; //all classes must have a function that runs every time //an instance of the class is put on stage public function STAR() { //Code that will be run when the STAR is added to the stage addEventListener(Event.ADDED, beginClass); //Enter frame code addEventListener(Event.ENTER_FRAME, enterFrameEvents); } //private function are just functions that you can't access //from the main timeline, but only within the class itself private function beginClass(event:Event):void { //defining _root as the document root _root = MovieClip(root); } private function enterFrameEvents(event:Event):void { this.y += _root.starspeed; this.rotation+=1; if (this.y>(stage.stageHeight*0.8)) { //destroying this STAR this.parent.removeChild(this); //stop running this code removeEventListener(Event.ENTER_FRAME, enterFrameEvents); } else if (MovieClip(root).flag) { if (this.hitTestObject(this.parent['MCBall'])) { //destroying this STAR this.parent.removeChild(this); //stop running this code removeEventListener(Event.ENTER_FRAME, enterFrameEvents); //increase the score //_root.SCORE.text = "YAY"; _root.myscore ++; } } } } }