billowillo
10-31-2008, 10:39 PM
i have it so when the character gets hit it flashes red then goes back to normal, that works fine but theres an issue when another child of enemy is added. the old child wont make it turn red but the new one will, and it just continues like that whenver a new one is added the old one wont make it blink
package {
import flash.display.*;
import flash.events.*;
public class EnemyClass extends MovieClip {
private var _root:MovieClip;
private var enemyYSpeed:Number = 6;
private var enemyXSpeed:Number = 6;
public function EnemyClass() {
addEventListener(Event.ADDED, beginClass);
addEventListener(Event.ENTER_FRAME, enterFrameEvents);
}
public function beginClass(event:Event):void {
_root = MovieClip(root);
}
public function enterFrameEvents(event:Event):void {
x += enemyXSpeed;//Move the ball horizontally
y += enemyYSpeed;//Move the ball vertically
//Bouncing the ball off of the walls
if (this.x >= stage.stageWidth-this.width) {
//if the ball hits the right side
//of the screen, then bounce off
enemyXSpeed *= -1;
}
if (this.x <= 0) {
//if the ball hits the left side
//of the screen, then bounce off
enemyXSpeed *= -1;
}
if (this.y >= stage.stageHeight-this.height) {
//if the ball hits the bottom
//then bounce up
enemyYSpeed *= -1;
}
if (this.y <= 0) {
//if the ball hits the top
//then bounce down
enemyYSpeed *= -1;
}
if (hitTestObject(_root.mcChar) &&(_root.canBeHit=true)) {
trace("hit");
_root.mcChar.gotoAndStop(2)
}
if (! this.hitTestObject(_root.mcChar)){
_root.mcChar.gotoAndStop(1)
}
}
}
}
package {
import flash.display.*;
import flash.events.*;
public class EnemyClass extends MovieClip {
private var _root:MovieClip;
private var enemyYSpeed:Number = 6;
private var enemyXSpeed:Number = 6;
public function EnemyClass() {
addEventListener(Event.ADDED, beginClass);
addEventListener(Event.ENTER_FRAME, enterFrameEvents);
}
public function beginClass(event:Event):void {
_root = MovieClip(root);
}
public function enterFrameEvents(event:Event):void {
x += enemyXSpeed;//Move the ball horizontally
y += enemyYSpeed;//Move the ball vertically
//Bouncing the ball off of the walls
if (this.x >= stage.stageWidth-this.width) {
//if the ball hits the right side
//of the screen, then bounce off
enemyXSpeed *= -1;
}
if (this.x <= 0) {
//if the ball hits the left side
//of the screen, then bounce off
enemyXSpeed *= -1;
}
if (this.y >= stage.stageHeight-this.height) {
//if the ball hits the bottom
//then bounce up
enemyYSpeed *= -1;
}
if (this.y <= 0) {
//if the ball hits the top
//then bounce down
enemyYSpeed *= -1;
}
if (hitTestObject(_root.mcChar) &&(_root.canBeHit=true)) {
trace("hit");
_root.mcChar.gotoAndStop(2)
}
if (! this.hitTestObject(_root.mcChar)){
_root.mcChar.gotoAndStop(1)
}
}
}
}