-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFire.as
More file actions
38 lines (36 loc) · 1.06 KB
/
Fire.as
File metadata and controls
38 lines (36 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package {
import flash.display.MovieClip;
import flash.events.*;
public class Fire extends MovieClip {
private var _root:*;
private var damage:Number;
public function Fire(passedDamage:Number) {
damage = passedDamage;
addEventListener(Event.ADDED,beginClass);//this will run every time this guy is made
addEventListener(Event.ENTER_FRAME,eFrame);//this will run every frame
addEventListener(Event.REMOVED_FROM_STAGE, destroyThis);
}
private function beginClass(e:Event):void {
_root = MovieClip(root);
}
private function eFrame(e:Event):void {
if (this.hit.hitTestObject(_root.player.hit)){
dealDamage(0);
}
if (this.currentFrame == 8){
destroyThis();
}
}
private function dealDamage(whichHit:int):void{
if (whichHit == 0){
_root.inGamePlayerHealth -= this.damage;
}
}
public function destroyThis(event:Event = null):void{
this.removeEventListener(Event.ENTER_FRAME, eFrame);
if (event == null && this.parent){
this.parent.removeChild(this);
}
}
}
}