[Solved] Camera and enemy behaviour in AS3 platformer

Daniel Angel Diz Garcia Asks: Camera and enemy behaviour in AS3 platformer
beginner in AS3 here. I am working on a platformer game based on the code of a provided example exercise. I have the following problem:

  • I have an enemy who shoots bullets. The enemy is the parent, and the bullet are the child. When I move to the next scene (level), the bullets are still there, but invisible, even using the removeEventListener to shut down the bullet hit check.

Here is the code of the child “disparoEnemigo_mov”:

addEventListener(Event.ENTER_FRAME, fl_MoveEnemyShot);
function fl_MoveEnemyShot(event: Event) {
try {
    if (enemy_shot.y < 300) {
        if (enemy_shot.hitTestObject(Object(this.parent).mario)) {

            variablesGlobales.variables().vidas -= 1;
            Object(root).texto.text = 
            trace("vidas: " + variablesGlobales.variables().vidas);
            if (variablesGlobales.variables().vidas < 1) {
            removeEventListener(Event.ENTER_FRAME, fl_MoveEnemyShot);
        } else {
            enemy_shot.y += 3;
    } else {
        removeEventListener(Event.ENTER_FRAME, fl_MoveEnemyShot);
} catch (error: Error) {
    removeEventListener(Event.ENTER_FRAME, fl_MoveEnemyShot);

import flash.events.Event;
import flash.media.SoundMixer;

addEventListener(Event.ENTER_FRAME, fl_EnterFrameHandler);

function fl_EnterFrameHandler(event: Event): void {
if (this.hitTestObject(Object(this.parent).mario)) {

    var sound:gameOver = new gameOver();
    trace("Mario dies");
    var cartel:StageLose = new StageLose();
    cartel.x = -85;
    Object(this.parent).mario.y = 1000;
}catch(error: Error){
removeEventListener (Event.ENTER_FRAME, fl_EnterFrameHandler);

And this is the code of the parent, “enemigo_mov”:

var leftPressed: Boolean = true;
var rightPressed: Boolean = false;
stage.addEventListener(Event.ENTER_FRAME, fl_MoveEnemy);
function fl_MoveEnemy(event: Event) {
if (leftPressed) {
    enemy1.x -= 0;
    if (enemy1.x < -120) {
        leftPressed = false;
        rightPressed = true;
} else if (rightPressed) {
    enemy1.x += 1;
    if (enemy1.x > 120) {
        rightPressed = false;
        leftPressed = true;
var number: Number = Math.random();
if (number < 0.05){// && 
variablesGlobales.variables().coleccionEnemigos.indexOf(this) != -1) {
    var disparo: disparoEnemigo_mov = new disparoEnemigo_mov();
    disparo.x=enemy1.x +115;
    disparo.y=enemy1.y +115;

    trace(disparo.x + " " + disparo.y);

removeEventListener(Event.ENTER_FRAME, fl_MoveEnemy);

In both codes, “mario” is the player character.

What I need to do is to stop the bullet creation of “”disparoEnemigo_mov” when we move to the next scene. Shouldn’t the “removeEventListener(Event.ENTER_FRAME, fl_MoveEnemy)” line stop the bullets to check if there is any collision with the player?

Any help or resource will be helpful. Thank you so much!

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.