19 Replies Latest reply on Jan 29, 2012 10:47 PM by kglad

    Trace instance+Remove bitmaps

    McbainGames11 Level 2

      Hey,

       

      Well at the moment I am searching for my instance called instance11 but I can't find it because I need to remove a movieclip and I need that instance name to remove it(I think)

       

      package

      {

                import com.greensock.*;

                import com.greensock.easing.*;

                import com.greensock.plugins.*;

                import com.kglad.HitF;

       

                import flash.display.Bitmap;

                import flash.display.DisplayObject;

                import flash.display.MovieClip;

                import flash.display.Sprite;

                import flash.display.Stage;

                import flash.events.Event;

                import flash.events.MouseEvent;

                import flash.events.TimerEvent;

                import flash.filters.DisplacementMapFilter;

                import flash.utils.Timer;

       

                TweenPlugin.activate([AutoAlphaPlugin]);

       

       

                public class Level extends Sprite

                {

                          public var hitF:HitF = HitF.getInstance();

                          public var myTimer:Timer = new Timer(1000, 30);

                          public var birdImageHolder:Sprite = new Sprite();

       

                          public var timer_limit:int = 30;

                          public var _stage:Stage;

                          public var timerNum:int;

                          public var star_lives:int = 3;

                          public var hitClear:Boolean = true;

       

                          public var birdA:Array = [];

                          public var birdImage:Bitmap = new Assets.bird();

       

                          public var enemyA:Array = [];

                          public var enemyImageHolder:Sprite = new Sprite();

       

                          public var currentImage:Bitmap = new Assets.levelOne();

       

                          public var star:Sprite = new Sprite();

                          public var star_one:Bitmap = new Assets.star();

                          public var star_two:Bitmap = new Assets.star();

                          public var star_three:Bitmap = new Assets.star();

       

                          public var tryAgainImageHolder:Sprite = new Sprite();

                          public var tryAgainImage:Bitmap = new Assets.tryAgain();

       

                          public var mainMenuImageHolder:Sprite = new Sprite();

                          public var mainMenuImage:Bitmap = new Assets.mainMenu();

       

       

                          public function Level(stageVar:Stage)

                          {

                                    _stage = stageVar;

                                    activateControls();

                          }

                          public function activateControls():void

                          {

                                    createEnemy();

                                    createStars();

                                    createBird();

                                    currentLevel();

       

                                    myTimer.start();

                                    myTimer.addEventListener(TimerEvent.TIMER, TimerHandler);

       

                                    addEventListener(Event.ENTER_FRAME, loopF);

                          }

                          public function deactivateControls():void

                          {

                                    timerNum = 0;

       

                                    birdA[0].parent.removeChild(birdA[0]);

                                    birdA.splice(0,1);

       

                                    star_one.parent.removeChild(star_one);

                                    star_two.parent.removeChild(star_two);

                                    star_three.parent.removeChild(star_three);

       

                                    removeEventListener(Event.ENTER_FRAME, loopF);

                                    myTimer.stop();

                                    myTimer.removeEventListener(TimerEvent.TIMER, TimerHandler);

       

                                    //instance11 name goes here when found ??     .enemyImageHolder.removeChild(getChildByName("enemy"));

      //I want to remove my enemy objects..

       

       

                                    for(var i:int = enemyA.length - 1; i >= 0; i--)

                                    {

                                              enemyA[i].parent.removeChild(enemyA[i]);

                                              enemyA.splice(i,1);

                                    }

                          }

                          public function createBird():void

                          {

                                    addChild(birdImageHolder);

                                    birdImageHolder.y = 330;

       

                                    birdImageHolder.addChild(birdImage);

                                    birdImage.y = -37;

                                    birdImage.x = -40;

                                    birdA.push(birdImage);

       

                                    birdImage.alpha = 0;

                                    TweenLite.to(birdImage, 4, { alpha:1, visible:1, ease:Expo.easeOut });

                          }

                          public function createEnemy():void

                          {

                                    var max_enemies:int = 10;

                                    var gap:int = 100;

       

                                    for(var i:int=0; i<max_enemies; i++)

                                    {

                                              addChild(enemyImageHolder);

       

                                              var enemy:Bitmap = new Assets.iceBlock();

                                              enemyImageHolder.addChild(enemy);

                                              enemy.x = Math.random() * _stage.stageWidth - enemy.width;

                                              enemy.y = - i * (gap + enemy.height) - 60;

                                              enemyA.push(enemy);

                                              enemy.name = "enemy";

                                              trace(enemy);

      //this outputs: instance11.instance14.enemy

                                    }

                                    enemyImageHolder.alpha = 0;

                                    TweenLite.to(enemyImageHolder, 4, { alpha:1, visible:1, ease:Expo.easeOut });

                          }

                          public function createStars():void

                          {

                                    addChild(star);

       

                                    star_one.x = 0;

                                    star_one.y = 330;

                                    star_one.name = "star_one";

                                    star.addChild(star_one);

       

                                    star_two.x = 49;

                                    star_two.y = 330;

                                    star_two.name = "star_two";

                                    star.addChild(star_two);

       

                                    star_three.x = 95;

                                    star_three.y = 330;

                                    star_three.name = "star_three";

                                    star.addChild(star_three);

       

                                    star.alpha = 0;

                                    TweenLite.to(star, 4, { alpha:1, visible:1, ease:Expo.easeOut });

                          }

                          public function updateEnemyPosition():void

                          {

                                    var fall_limit:int = 2;

       

                                    for(var i:int; i<enemyA.length; i++)

                                    {

                                              var enemy:DisplayObject = enemyA[i] as DisplayObject;

                                              enemy.y += fall_limit;

                                    }

                          }

                          public function updateBirdPosition():void

                          {

                                    birdImageHolder.x = mouseX;

                          }

                          public function loopF(event:Event):void

                          {

                                    updateBirdPosition();

                                    updateEnemyPosition();

                                    checkHitF();

                          }

                          public function currentLevel():void

                          {

                                    addChild(currentImage);

                                    currentImage.x = 150;

                                    currentImage.y = -39;

                                    currentImage.name = "currentImage";

       

                                    currentImage.alpha = 0;

                                    TweenLite.to(currentImage, 2, {x:150, y:160, alpha:1, visible:1, ease:Expo.easeOut});

                          }

                          public function checkHitF():void

                          {

                                    for (var i:int=enemyA.length-1; i>=0; i--)

                                    {

                                              if (hitF.hit(birdA[0],enemyA[i]) && hitClear)

                                              {

                                                        star_lives--;

                                                        hitClear = false;

       

                                                        addChild(enemyA[i]);

                                                        removeChild(enemyA[i]);

                                                        enemyA.splice(i,1);

                                              } else {

                                                        hitClear = true;

                                              }

                                    }

                                    if ((star_lives == 1))

                                    {

                                              star_one.alpha = 1;

                                              star_two.alpha = 0.5;

                                              star_three.alpha = 0.5;

                                    }

                                    else if ((star_lives == 2))

                                    {

                                              star_one.alpha = 1;

                                              star_two.alpha = 1;

                                              star_three.alpha = 0.5;

                                    }

                                    else if ((star_lives == 3))

                                    {

                                              star_one.alpha = 1;

                                              star_two.alpha = 1;

                                              star_three.alpha = 1;

                                    }

                                    else if(star_lives < 1)

                                    {

                                              deactivateControls();

                                              tryAgain();

                                    }

                          }

                          public function TimerHandler(event:Event):void

                          {

                                    timerNum++;

       

                                    if(timerNum == 2)

                                    {

                                              removeChild(getChildByName("currentImage"));

                                    }

                                    if(timerNum == timer_limit)

                                    {

                                              deactivateControls();

                                              tryAgain();

                                    }

                          }

                          public function tryAgain():void

                          {

                                    addChild(tryAgainImageHolder);

       

                                    tryAgainImage.y = 115;

                                    tryAgainImage.x = 145;

                                    tryAgainImage.name = "tryAgain";

                                    tryAgainImageHolder.addChild(tryAgainImage);

       

                                    tryAgainImageHolder.addEventListener(MouseEvent.CLICK, tryAgainClick);

                                    tryAgainImageHolder.addEventListener(MouseEvent.ROLL_OVER, tryAgainRollOver, false, 0, true);

                                    tryAgainImageHolder.addEventListener(MouseEvent.ROLL_OUT, tryAgainRollOut, false, 0, true);

       

                                    addChild(mainMenuImageHolder);

       

                                    mainMenuImage.y = 190;

                                    mainMenuImage.x = 145;

                                    mainMenuImage.name = "mainMenu";

                                    mainMenuImageHolder.addChild(mainMenuImage);

       

                                    mainMenuImageHolder.addEventListener(MouseEvent.CLICK, mainMenuClick);

                                    mainMenuImageHolder.addEventListener(MouseEvent.ROLL_OVER, mainMenuRollOver, false, 0, true);

                                    mainMenuImageHolder.addEventListener(MouseEvent.ROLL_OUT, mainMenuRollOut, false, 0, true);

       

                                    tryAgainImage.alpha = 0;

                                    TweenLite.to(tryAgainImage, 4, { alpha:1, visible:1, ease:Expo.easeOut });

       

                                    mainMenuImage.alpha = 0;

                                    TweenLite.to(mainMenuImage, 4, { alpha:1, visible:1, ease:Expo.easeOut });

                          }

                          public function deleteTryAgain():void

                          {

                                    removeChild(getChildByName("tryAgain"));

                                    removeChild(getChildByName("mainMenu"));

                          }

                          public function tryAgainClick(event:Event):void

                          {

                                    //deleteTryAgain();

                                    activateControls();

                          }

                          public function tryAgainRollOver(event:Event):void

                          {

                                    event.currentTarget.alpha = 0.5;

                          }

                          public function tryAgainRollOut(event:Event):void

                          {

                                    event.currentTarget.alpha = 1;

                          }

                          public function mainMenuClick(event:Event):void

                          {

                                    //deleteTryAgain();

                                    Main.instance.arrangeMenu();

                          }

                          public function mainMenuRollOver(event:Event):void

                          {

                                    event.currentTarget.alpha = 0.5;

                          }

                          public function mainMenuRollOut(event:Event):void

                          {

                                    event.currentTarget.alpha = 1;

                          }

                }

      }

       

       

      Basically I want to find a way to remove my enemy bitmaps and tryagain and mainmenu bitmaps and I think I have to find where it is in the DisplayObjectContainer which is instance11.instance14.enemy but I am having trouble identifying instance11, I know instance 14 is enemyImageHolder.

       

      That is what I am trying to do please help me remove these things