A little help here, please? array.push(child) problem


hey guys...

 

i lost... fine until decided add background picture , child stage , go wrong...

 

what trying do:

 

a background picture during level 1 , 2

1 enemy added each level

another background picture during level 3 , 4 (and on)

 

i have mc container (named background1) add stage , remove everything...

 

what happened , happens now:

 

before had 1 background pic, , enemies appearing in time...(enem1 , 2)

then added second background pic levels 3 , 4 , worked fine

once added 3rd enemy started working weird....since pushed on 1 enemy , 3 dissapeared....but timer still counting...

 

can check code me , tell me should fix, please?

 

addchild(background1);  //this mc, have defined in frame

 

var mic4:loader = new loader();

mic4.load(new urlrequest("nivel1.jpg"));

 

var nivel3pic:loader = new loader();

nivel3pic.load(new urlrequest("nivel3.jpg"));

 

var score_txt:textfield = new textfield();

score_txt.x = 517;

score_txt.y = 100;

score_txt.width = 115,95;

score_txt.height = 100.95;

 

var level_txt:textfield = new textfield();

level_txt.x = 917;

level_txt.y = 100;

level_txt.width = 115,95;

level_txt.height = 100.95;

 

var lives_txt:textfield = new textfield();

lives_txt.x = 1317;

lives_txt.y = 100;

lives_txt.width = 115,95;

lives_txt.height = 100.95;

 

var enem1:loader = new loader();

enem1.load(new urlrequest("1enemigo.png"));

 

var enem2:loader = new loader();

enem2.load(new urlrequest("1enemigo.png"));

 

var enem3:loader = new loader();

enem3.load(new urlrequest("2enemigo.png"));

  

var enemy1array:array = new array(enem1);

var enemyarray:array = new array(enem2);

var enemy3array:array = new array(enem3);

 

if (!lives){var lives:int = 3;}

if (!level){var level:int = 1;}

var lvlup:int = 200;

var updlvl:int = (lvlup * level);

if(!count){var count = 0;}

 

var t1:timer=new timer(5000,1);

var t2:timer=new timer(9990,1);

var t3:timer=new timer(4500,1);

var t4:timer=new timer(8990,1);

var t5:timer=new timer(4000,1);

var t6:timer=new timer(7990,1);

 

level1();

level3();

recycleenemy();

if (level >=2) recycleenemy1();

if (level >=3) recycleenemy3();

updatefields();

 

 

function level1(): void {

if (level >= 1 && level < 3){

    background1.addchild(mic4);

    background1.addchild(score_text);

    background1.addchild(score_txt);

    background1.addchild(level_text);

    background1.addchild(level_txt);

    background1.addchild(lives_text);

    background1.addchild(lives_txt);

}

}

 

 

function level3(): void {

if (level >= 3 && level < 5){

    removerviejonivel();

    addchild(background1);

    background1.addchild(nivel3pic);

    background1.addchild(score_text);

    background1.addchild(score_txt);

    background1.addchild(level_text);

    background1.addchild(level_txt);

    background1.addchild(lives_text);

    background1.addchild(lives_txt);

}

}

 

function removeenemy(){

            t1.stop();

            t2.stop();

            updatescore(100);

            updatefields();

           if (enem1.parent) {enem1.parent.removechild(enem1);}

           recycleenemy();

}

 

function touchlistener(event:mouseevent){

    enem1.removeeventlistener(mouseevent.click, touchlistener);

    removeenemy();

}

 

function recycleenemy():void{

        enem1.x=(50 + math.random() * (stage.stagewidth - 150));

        enem1.y=(50 + math.random() * (stage.stageheight + -100));

        t1.addeventlistener(timerevent.timer, addenemy);

        t1.start();

        t2.addeventlistener(timerevent.timer, bang1);

        t2.start();

}

 

function addenemy(e:timerevent):void {

        background1.addchild(enem1);

           enem1.addeventlistener(mouseevent.click, touchlistener);

        enemy1array.push(enem1);

}

 

function removeenemy1(){

            t3.stop();

            t4.stop();

            updatescore(100);

            updatefields();

            if (enem2.parent) {enem2.parent.removechild(enem2);}

           recycleenemy1();

}

 

function touchlistener1(event:mouseevent){

    enem2.removeeventlistener(mouseevent.click, touchlistener1);

    removeenemy1();

}

 

 

function recycleenemy1():void{

        enem2.x=(50 + math.random() * (stage.stagewidth - 150));

        enem2.y=(50 + math.random() * (stage.stageheight + -100));

        t3.addeventlistener(timerevent.timer, addenemy1);

        t3.start();

        t4.addeventlistener(timerevent.timer, bang2);

        t4.start();

}

 

 

function bang1(e:timerevent):void {

    if(enem1.stage){

                lives--;

                if (lives >= 0) {

                    mychannel = mysound.play();

                    stoptime();

                    gotoandstop(5);

            }

    }

}

 

function bang2 (e:timerevent):void {

    if(enem2.stage){

                lives--;

                if (lives >= 0) {

                    mychannel = mysound.play();

                    stoptime();

                    gotoandstop(5);

            }

    }

}

 

function addenemy1(e:timerevent):void {

        background1.addchild(enem2);

           enem2.addeventlistener(mouseevent.click, touchlistener1);

        enemyarray.push(enem2);

}

 

function removeenemy3(){

            t5.stop();

            t6.stop();

            updatescore(100);

            updatefields();

           if (enem3.parent) {enem1.parent.removechild(enem3);}

           recycleenemy3();

}

 

function touchlistener3(event:mouseevent){

    enem3.removeeventlistener(mouseevent.click, touchlistener3);

    removeenemy3();

}

 

 

function recycleenemy3():void{

        enem3.x=(50 + math.random() * (stage.stagewidth - 150));

        enem3.y=(50 + math.random() * (stage.stageheight + -100));

        t5.addeventlistener(timerevent.timer, addenemy3);

        t5.start();

        t6.addeventlistener(timerevent.timer, bang3);

        t6.start();

}

 

function addenemy3(e:timerevent):void {

        background1.addchild(enem3);

        enem3.addeventlistener(mouseevent.click, touchlistener3);

        enemy3array.push(enem3);

}

 

function bang3(e:timerevent):void {

    if(enem3.stage){

                lives--;

                if (lives >= 0) {

                    mychannel = mysound.play();

                    stoptime();

                    gotoandstop(5);

            }

    }

}

 

function updatescore(amount:int):void {

    count += amount;

    if(count < 0) count = 0;

    if (count == updlvl) updatelevel(1);

}

function updatelevel(amount:int):void {

    //new levelup().play();

    level += amount;

    updlvl=(lvlup*level);

    if (level >=2) recycleenemy1();

    //if (level >=3) recycleenemy3();

    //if (level >=4) recycleenemy4();

    level1();

    level3();

}

 

function updatefields():void {

    score_txt.text = string(count);

    level_txt.text = string(level);

    lives_txt.text = string(lives);

   

}

 

function stoptime():void {

    t1.stop();

    t2.stop();

    t3.stop();

    t4.stop();

    t5.stop();

    t6.stop();

}

 

function removerviejonivel():void {

    if (mic4.parent) {mic4.parent.removechild(mic4);}

    if (enem1.parent) {enem1.parent.removechild(enem1);}

    if (enem2.parent) {enem2.parent.removechild(enem2);}

    if (enem3.parent) {enem3.parent.removechild(enem3);}

    if (enem4.parent) {enem4.parent.removechild(enem4);}

    if (background1.parent) {background1.parent.removechild(background1);}

}

 

thanks!!!!

use trace function debug code.



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

Adobe Acrobat Pro , Terminal Server Use

Thread: transmission-daemon isn't playing nice: "409: Conflict"

Thread: gpg: Conflicting Commands