10 Replies Latest reply: Aug 31, 2012 1:49 PM by mr.shumi RSS

    Time line

    mr.shumi

      i know its a bad practice to use timeline scripting but  i was obliged to do that

      if user clicked a button that will goto and play for example frame 10 and at frame 10 i have my game code that ill start

      the problem is when user clicks the button ( i have a mosue event that shoots) so directly when its loaded i can see the shot in the middle of the screen how can i avoid this

      is there something i can do to delay that

        • 1. Re: Time line
          Ned Murphy MVP

          Timeline scripting is not a bad practice, thoug when using it there are numerous bad practices that should be avoided.

           

          Your problem is not clear to me.  If you are indicating that you have a moiuse event the results in something shooting, like a gun/bullet, then chances are you need to hold off assigning that event listener until it is time for it to exist.  If you mean that you assign this listner in frame 1 but do not need it un til frame 10, then you could put a conditional inside its event handler that checks the frame before allowing anything to shoot.

          • 2. Re: Time line
            mr.shumi Community Member

            no not like this

            at frame 1 i got the button that when i click it goes at frame 10 for example at frame 10 we have the code of our game all the listeners etc...

            the problem when i click the button everything works fine but when the game is loaded ( the bullets is there moving )

             

            Date: Wed, 11 Apr 2012 07:32:04 -0600

            [... contact info removed ...]

            Subject: Re: Time line Time line

             

             

             

             

             

             

             

             

             

             

                Re: Time line

             

             

                created by Ned Murphy in Action Script 3 - View the full discussion

             

             

             

            Timeline scripting is not a bad practice, thoug when using it there are numerous bad practices that should be avoided. Your problem is not clear to me.  If you are indicating that you have a moiuse event the results in something shooting, like a gun/bullet, then chances are you need to hold off assigning that event listener until it is time for it to exist.  If you mean that you assign this listner in frame 1 but do not need it un til frame 10, then you could put a conditional inside its event handler that checks the frame before allowing anything to shoot.

             

             

            Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: Re: Time line

            To unsubscribe from this thread, please visit the message page at Re: Time line. In the Actions box on the right, click the Stop Email Notifications link.

             

            Start a new discussion in Action Script 3 by email or at Adobe Forums

              For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

            • 3. Re: Time line
              Ned Murphy MVP

              If clicking the button isn't doing it, then it sounds like just entering the frame causes a bullet to be there.  What makes the bullet appear?  You need to make it such that it cannot happen. 

               

              You'll need to show relevant code if you want help... just explaining with words is not likely to work for you.

              • 4. Re: Time line
                mr.shumi Community Member

                http://dl.dropbox.com/u/54627535/Untitled-1.swf

                check this man , level 2 ( modern era) a

                see when the game start the bullet

                • 5. Re: Time line
                  Ned Murphy MVP

                  Seeing it doesn't help solve it.  If you cannot answer the questions or provide what is asked for, there is nothing I can do to help you.

                  • 6. Re: Time line
                    mr.shumi Community Member

                    i only thought i didnt explain whats happening well anyway here is the code

                    here is the code

                    function startLevel2(event:MouseEvent):void

                    {

                              gotoAndStop("Modern Era " );

                     

                     

                    }

                    here we wo go load the game

                     

                    from here we call the movebullet function

                    function frameListener(event:Event):void

                                        {

                     

                     

                                                  if(!myTank.ismyTankDestroyed)

                                                  {

                                                  moveTank();

                                                  }

                                                  l2moveBullets();

                     

                                                  if (! anEnemyTank.isDestroyed && !myTank.myTankisDestroyed)

                                                  {

                                                            moveEnemyTank(anEnemyTank);

                                                  }

                     

                     

                                                  moveGroundUnits();

                     

                                                  moveEnemyBulletl2();

                     

                                        }

                    and here is the function of moving bullets

                    function l2moveBullets()

                                        {

                                                  for (var i:int = 0; i < _l2bullets.length; i++)

                                                  {

                                                            bullet = _l2bullets[i];

                                                            //bullet.rotation = _turretAngle

                                                            bullet.x +=  bullet.vx;

                                                            bullet.y +=  bullet.vy;

                                                            //check the bullet's stage boundaries

                                                            if (bullet.y < 0 || bullet.x < 0 || bullet.x > stage.stageWidth || bullet.y > stage.stageHeight)

                                                            {etc .... }}

                     

                    and we listen when the user click mouse to add the bullet to the array and prepare it for movement

                     



                    function mouseDownHandler(event:MouseEvent):void


                    {



                    fireBullet();

                     

                     



                    }

                     

                     



                    function fireBullet()


                    {



                    var bullet:TankBullet = new TankBullet(getAnglel2());



                    stage.addChild(bullet);

                     

                     




                    var radius:int = -20;

                     

                     




                    var angle:Number = (myTank.rotation + myTank.turretMovieClip.rotation) * Math.PI / 180;

                     

                     

                     

                     




                    //3. Position the bullet



                    bullet.x = myTank.x +myTank.turretMovieClip.x + 20 + radius * Math.cos(angle);



                    bullet.y = myTank.y +myTank.turretMovieClip.y - 5 + radius * Math.sin(angle);



                    //Set the bullet's velocity based



                    //on the angle



                    bullet.vx = Math.cos(angle) * -7 + myTank.vx;



                    bullet.vy = Math.sin(angle) * -7 + myTank.vy;

                     

                     

                     

                     




                    //Push the bullet into the _l2bullets array



                    _l2bullets.push(bullet);



                    controlAudiol2(shootSoundl2);



                    bombsLeftl2--;



                    bombsLeftDisplay2.text = String(bombsLeftl2);

                     

                     




                    trace("you still have " + bombsLeftl2);



                    if (bombsLeftl2 == 0)



                    {




                    stage.removeEventListener(MouseEvent.CLICK,mouseDownHandler);




                    //stage.addEventListener(MouseEvent.CLICK , playemptySound);

                     

                     









                    }


                    }
                    • 7. Re: Time line
                      Ned Murphy MVP

                      It is nearly impossible to read the code you posted.  While I can find that you have a MOUSE_DOWN event that triggers firing a bullet, I don't see where you added that listener, only where you remove it.

                       

                      What I would guess is that you are entering the frame with the MOUSE_DOWN still registering from having clicked to get to the frame, which triggers the bullet to fire.

                       

                      What kind of MouseEvent do you have triggering the startLevel2 function ?  It should be a CLICK event

                      • 8. Re: Time line
                        mr.shumi Community Member

                        stop();

                         

                            import flash.display.*;

                            import flash.events.*;

                            import flash.ui.Keyboard;

                            import flash.ui.Mouse;

                            import flash.geom.Point;

                            import flash.utils.Timer;

                            import flashx.textLayout.formats.BackgroundColor;

                            import flash.media.*;

                            import flash.media.SoundChannel;

                            import flash.media.SoundTransform;

                            import flash.text.*;

                            import flash.events.MouseEvent;

                            import level2.greensock.*;

                            import level2.greensock.easing.*;

                            import level2.shumi.l2Building;

                            import level2.shumi.enemy;

                            import level2.shumi.enemyTank;

                            import level2.shumi.ExplosionClass;

                            import level2.shumi.groundUnits;

                            import level2.shumi.Tank;

                            import level2.shumi.TankBullet;

                         

                         

                         

                         

                           

                         

                         

                                var rightInnerBoundary:uint;

                                var leftInnerBoundary:uint;

                                var topInnerBoundary:uint;

                                var bottomInnerBoundary:uint;

                                var level2bg:aBackground ;

                         

                                var aBuilding:l2Building;

                         

                         

                         

                                var myTank:Tank ;

                                var ghostTank:Tank;

                         

                                var hitCount:Number = 0;

                         

                                var _l2bullets:Array ;

                                var _Gunit:Array  ;

                                var groundUnit:groundUnits  ;

                                var groundUnit2:groundUnits  ;

                                var groundUnit3:groundUnits  ;

                                var groundUnit4:groundUnits  ;

                         

                                var enemySoldier1;

                                var enemySoldier2;

                               

                                var anEnemyTank:enemyTank  ;

                                var speed:int = 1;

                                var radians:Number = 180 / Math.PI;

                                var turnRate:Number = .05;

                                var agroRange:Number = 300;

                                var distanceX:Number = 0;

                                var distanceY:Number = 0;

                                var distanceTotal:Number = 0;

                                var moveDistanceX:Number = 0;

                                var moveDistanceY:Number = 0;

                                var moveX:Number = 0;

                                var moveY:Number = 0;

                                var totalmove:Number = 0;

                                var hitCounter:Number = 5;

                                var bullet:TankBullet;

                                var shootSoundl2:shoot1;

                                var soundControl:SoundChannel;

                                var deadSound:dead;

                                var explodeSoundl2:explode;

                                var emptySound:empty;

                                var hitSound:hit;

                                var bombsLeftl2:Number ;

                         

                                var textFormat:TextFormat = new TextFormat ;

                                var numberDisplay:TextField  = new TextField ;

                                var Score:int ;

                         

                                var scoreDisplay:TextField = new TextField  ;//score display  text field

                                var bombsLeftDisplay2:TextField = new TextField  ;

                                var BombsNum:TextField = new TextField  ;

                         

                                var mybtn:btn = new btn  ;

                                var mybtn2:btn2 = new btn2  ;

                               

                                var myCursor:cursor = new cursor  ;

                                var _l2Timer:Timer;

                                var enemyBullet1l2:TankBullet;

                                var _eBulletl2:Array;

                                var myTankHealth : uint = 10;

                                var gameOverScreen : MovieClip;

                         

                         

                         

                                // var tankOffsetX :int = myTank.x + level2bg.x;

                                // var tankOffsetY : int = myTank.y + level2bg.y;

                         

                               

                                    init();

                                   

                         

                               

                                function setuptextfieldsl2()

                                {

                                    textFormat.font = "Helvetica";

                                    textFormat.size = 25;

                                    textFormat.color = 0x000000;

                                    textFormat.align = TextFormatAlign.CENTER;

                                    //Configure the  score  text field

                                    numberDisplay.defaultTextFormat = textFormat;

                                    numberDisplay.autoSize = TextFieldAutoSize.CENTER;

                                    numberDisplay.border = false;

                                    numberDisplay.text = "0";

                         

                                    scoreDisplay.defaultTextFormat = textFormat;

                                    scoreDisplay.autoSize = TextFieldAutoSize.CENTER;

                                    scoreDisplay.border = false;

                                    scoreDisplay.text = "Score : ";

                                    bombsLeftDisplay2.defaultTextFormat = textFormat;

                                    bombsLeftDisplay2.autoSize = TextFieldAutoSize.CENTER;

                                    bombsLeftDisplay2.border = false;

                                    bombsLeftDisplay2.text = "50";

                         

                                    BombsNum.defaultTextFormat = textFormat;

                                    BombsNum.autoSize = TextFieldAutoSize.CENTER;

                                    BombsNum.border = false;

                                    BombsNum.text = "Bombs Left :";

                         

                         

                                    //=====

                         

                                    //Display and score text field

                                    stage.addChild(numberDisplay);

                                    stage.addChild(scoreDisplay);

                                    stage.addChild(bombsLeftDisplay2);

                                    stage.addChild(BombsNum);

                         

                                    numberDisplay.x = stage.stageWidth - 40;

                                    numberDisplay.y = 10;

                         

                         

                                    scoreDisplay.x = stage.stageWidth - 150;

                                    scoreDisplay.y = 10;

                                    bombsLeftDisplay2.x = stage.stageWidth - 55;

                                    bombsLeftDisplay2.y = 40;

                                    BombsNum.x = stage.stageWidth - 200;

                                    BombsNum.y = 40;

                                   

                                }

                                function init()

                                {

                                   

                                Mouse.hide();

                                    setuptextfieldsl2();

                                   

                                level2bg = new aBackground  ;

                         

                                aBuilding= new l2Building  ;

                         

                         

                         

                                myTank = new Tank  ;

                                ghostTank = new Tank  ;

                         

                               

                         

                        _l2bullets = new Array  ;

                                _Gunit = new Array  ;

                                groundUnit = new groundUnits  ;

                                groundUnit2 = new groundUnits  ;

                        groundUnit3 = new groundUnits  ;

                                groundUnit4 = new groundUnits  ;

                         

                               

                               

                                anEnemyTank = new enemyTank  ;

                               

                        bombsLeftl2= 50;

                         

                         

                                Score = 0;

                                                                                                        myTankHealth = 10;

                                                                                                        // set patroling points in an array, as many as u like, soldier will start at

                                    // startPointX and StartPointY parameters passed in enemy creation

                                    var patrolPointsSoldier1:Array = new Array  ;

                                    patrolPointsSoldier1.push(new Point(333,1440));

                                    patrolPointsSoldier1.push(new Point(998,1447));

                                    patrolPointsSoldier1.push(new Point( 600 , 1800));

                         

                                    var patrolPointsSoldier2:Array = new Array  ;

                                    patrolPointsSoldier2.push(new Point(444,1440));

                                    patrolPointsSoldier2.push(new Point(1000,1460));

                         

                                   

                                    //enemy parameter (displayObjectContainer for stage refrence, PatrolPointArray,;

                                    // startPointX, startPointY)

                                    enemySoldier1 = new enemy(this,patrolPointsSoldier1,440,1440);

                                    enemySoldier2 = new enemy(this,patrolPointsSoldier2,500,500);

                         

                         

                                    rightInnerBoundary = stage.stage.width;

                                    leftInnerBoundary = 0;

                                    topInnerBoundary = 0;

                                    bottomInnerBoundary = stage.stageHeight;

                         

                                    level2bg.x = 0;

                                    level2bg.y = 0;

                                    aBuilding.x = 700;

                                    aBuilding.y = 750;

                                    level2bg.addChild(aBuilding);

                         

                         

                         

                                    addChild(level2bg);

                                    groundUnit.x = 500;

                                    groundUnit.y = 290;

                                    level2bg.addChild(groundUnit2);

                                    level2bg.addChild(groundUnit);

                                    level2bg.addChild(groundUnit3);

                                    level2bg.addChild(groundUnit4);

                         

                                    level2bg.addChild(enemySoldier1);

                                    level2bg.addChild(enemySoldier2);

                                    groundUnit2.x = 780;

                                    groundUnit2.y = 290;

                         

                                    groundUnit3.x = 500;

                                    groundUnit3.y = 700;

                         

                                    groundUnit4.x = 70;

                                    groundUnit4.y = 960;

                         

                                   

                         

                                    _Gunit.push(groundUnit,groundUnit2,groundUnit3,groundUnit4);

                         

                         

                         

                                    myTank.x = 300;

                                    myTank.y = 400;

                                    this.addChild(myTank);

                                    this.addChild(ghostTank);

                                    ghostTank.alpha = 0;

                         

                                    anEnemyTank.x = level2bg.x + 500;

                                    anEnemyTank.y = level2bg.y + 500;

                         

                         

                                    level2bg.addChild(anEnemyTank);

                                    shootSoundl2 = new shoot1  ;

                                    deadSound = new dead  ;

                                    explodeSoundl2 = new explode  ;

                                    hitSound = new hit  ;

                         

                        mybtn.x = stage.stageWidth - 55;

                                    mybtn.y = stage.stageHeight - 50;

                                    mybtn2.x = stage.stageWidth - 90;

                                    mybtn2.y = stage.stageHeight - 50;

                                   

                                    myCursor.x = mouseX;

                                    myCursor.y = mouseY;

                                    addChild(myCursor);

                                    addChild(mybtn);

                                    addChild(mybtn2);

                                   

                         

                        _l2Timer = new Timer(200);

                        _eBulletl2 = new Array ();

                         

                                    addListenersl2();

                         

                                }

                         

                         

                         

                         

                                function controlAudiol2(snd:Sound):void

                                {

                                    // if statement to avoid overlapping of sound objects

                                    if (soundControl)

                                    {

                                        soundControl.stop();

                                        soundControl = null;

                                    }

                                    var trans:SoundTransform = new SoundTransform(0.8);

                                    soundControl = snd.play(0,0,trans);

                                }

                                function l2moveBullets()

                                {

                                    for (var i:int = 0; i < _l2bullets.length; i++)

                                    {

                                        bullet = _l2bullets[i];

                                        //bullet.rotation = _turretAngle

                                        bullet.x +=  bullet.vx;

                                        bullet.y +=  bullet.vy;

                                        //check the bullet's stage boundaries

                                        if (bullet.y < 0 || bullet.x < 0 || bullet.x > stage.stageWidth || bullet.y > stage.stageHeight)

                                        {

                                            //Remove the bullet from the stage

                                            stage.removeChild(bullet);

                                            //Remove the bullet from the _l2bullets

                                            //array

                                            _l2bullets.splice(i,1);

                                            bullet = null;

                                            //Reduce the loop counter

                                            //by one to compensate

                                            //for the removed bullet

                                            i--;

                                        }

                         

                                        if (bullet != null && bullet.hitTestObject(aBuilding.buildingMovieClip.buildinghitTest))

                                        {

                                            //Update the score, the score display

                                            //and remove the bullet

                                            aBuilding.destroyBuilding();

                                            stage.removeChild(bullet);

                         

                                            numberDisplay.text = String(Score);

                         

                         

                                            controlAudiol2(explodeSoundl2);

                                            _l2bullets.splice(i,1);

                                            bullet = null;

                                            i--;

                                        }

                         

                                        if (bullet != null && bullet.hitTestObject(anEnemyTank.enemyTankMovieClip.eTankHitTest))

                                        {

                                            //Update the score, the score display

                                            //and remove the bullet

                                            anEnemyTank.destroyEnemyTank();

                                            stage.removeChild(bullet);

                                            _l2Timer.stop();

                                  _l2Timer.addEventListener(TimerEvent.TIMER, enemyTankShoot);

                                            Score = Score + 50;

                         

                         

                                            numberDisplay.text = String(Score);

                         

                         

                                            controlAudiol2(explodeSoundl2);

                                            _l2bullets.splice(i,1);

                                            bullet = null;

                                           

                                        }

                         

                         

                                        for (var j:int = 0; j < _Gunit.length; j++)

                                        {

                                            if (bullet != null && bullet.hitTestObject(_Gunit[j].base.baseHitTest))

                                            {

                                                _Gunit[j].bulletHit();

                                                controlAudiol2(hitSound);

                                                Score = Score + 50;

                                                numberDisplay.text = String(Score);

                                                stage.removeChild(bullet);

                                                _l2bullets.splice(i,1);

                                                bullet = null;

                                               

                         

                         

                                            }

                         

                                        }

                         

                         

                                    }

                                }

                         

                                function moveTank()

                                {

                                    //THE TANK

                                    //Increase the tank's speed if the up key is being pressed

                                    if (myTank.accelerate)

                                    {

                                        myTank.speed +=  0.1;

                                        myTank.tankMovieClip.atank.play();

                                        //Add some optional drag;

                                        myTank.speed *=  myTank.friction;

                                    }

                                    else

                                    {

                                        //Add friction to the speed if the tank is

                                        //not accelerating

                                        myTank.speed *=  myTank.friction;

                                        myTank.tankMovieClip.atank.stop();

                         

                         

                                    }

                                    //Calculate the acceleration based on the angle of rotation;

                                    var tankAngle = myTank.rotation * Math.PI / 180;

                                    myTank.acceleration_X = myTank.speed * Math.cos(tankAngle);

                                    myTank.acceleration_Y = myTank.speed * Math.sin(tankAngle);

                         

                                    //Update the tank's velocity

                                    myTank.vx = myTank.acceleration_X;

                                    myTank.vy = myTank.acceleration_Y;

                         

                         

                                    //Force the tanks's velocity to zero

                                    //it falls below 0.1

                                    if (Math.abs(myTank.vx) < 0.1 && Math.abs(myTank.vy) < 0.1)

                                    {

                                        myTank.vx = 0;

                                        myTank.vy = 0;

                                    }

                                    if (myTank.x - myTank.width / 2 < leftInnerBoundary)

                                    {

                                        myTank.x = leftInnerBoundary + myTank.width / 2;

                                        rightInnerBoundary = stage.stageWidth - myTank.x;

                                        level2bg.x -=  myTank.vx;

                                    }

                                    else if (myTank.x + myTank.width / 2 > rightInnerBoundary)

                                    {

                                        myTank.x = rightInnerBoundary - myTank.width / 2;

                                        leftInnerBoundary = myTank.width / 2 + 10;

                         

                                        level2bg.x -=  myTank.vx;

                                    }

                         

                                    if (myTank.y - myTank.height / 2 < topInnerBoundary)

                                    {

                                        myTank.y = topInnerBoundary + myTank.height / 2;

                                        bottomInnerBoundary = stage.stageHeight - myTank.y;

                                        level2bg.y -=  myTank.vy;

                         

                                    }

                                    else if (myTank.y + myTank.height / 2 > bottomInnerBoundary)

                                    {

                         

                                        myTank.y = bottomInnerBoundary - myTank.height / 2;

                                        topInnerBoundary = myTank.height;

                                        level2bg.y -=  myTank.vy;

                                    }

                                    if (level2bg.x > 0)

                                    {

                                        level2bg.x = 0;

                                        leftInnerBoundary = 0;

                                    }

                                    else if (level2bg.y > 0)

                                    {

                                        level2bg.y = 0;

                                        topInnerBoundary = 0;

                                    }

                                    else if (level2bg.x < stage.stageWidth - level2bg.width)

                                    {

                                        level2bg.x = stage.stageWidth - level2bg.width;

                                        rightInnerBoundary = stage.stageWidth;

                                    }

                                    else if (level2bg.y < stage.stageHeight - level2bg.height)

                                    {

                                        level2bg.y = stage.stageHeight - level2bg.height;

                                        bottomInnerBoundary = stage.stageHeight;

                                    }

                         

                         

                         

                         

                                    //Move and rotate the tank

                                    myTank.x +=  myTank.vx;

                                    myTank.y +=  myTank.vy;

                                    myTank.rotation +=  myTank.rotationSpeed;

                         

                         

                                    if (myTank.hitTestObject(level2bg.hitTest1) || myTank.hitTestObject(level2bg.hitTest2) || myTank.hitTestObject(level2bg.hitTest3) || myTank.hitTestObject(level2bg.hitTest4) || myTank.hitTestObject(level2bg.hitTest5) || myTank.hitTestObject(level2bg.hitTest6) || myTank.hitTestObject(level2bg.hitTest7) || myTank.hitTestObject(level2bg.hitTest8) || myTank.hitTestObject(level2bg.hitTest9) || myTank.hitTestObject(level2bg.hitTest10) || myTank.hitTestObject(level2bg.hitTest11) ||myTank.hitTestObject(level2bg.gameHitTest1) || myTank.hitTestObject(level2bg.gameHitTest2) || myTank.hitTestObject(level2bg.gameHitTest3))

                                    {

                                        trace("tank hit" + myTank.x);

                                        myTank.x = ghostTank.x;

                                        myTank.y = ghostTank.y;

                         

                         

                         

                                    }

                                    else

                                    {

                                        ghostTank.x = myTank.x;

                                        ghostTank.y = myTank.y;

                                    }

                         

                                    if (myTank.tankMovieClip.tankHitTest.hitTestObject(enemySoldier1._player.soldierHitTestPoint ))

                                    {

                                        if (! enemySoldier1.isDead)

                                        {

                                            trace("hit soldier");

                                            enemySoldier1.killSoldier();

                                            controlAudiol2(deadSound);

                                            Score = Score + 100;

                                            //numberDisplay.text = String(Score);

                                        }

                         

                                    }

                                    if (myTank.tankMovieClip.tankHitTest.hitTestObject(enemySoldier2._player.soldierHitTestPoint ))

                                    {

                                        if (! enemySoldier2.isDead)

                                        {

                                            enemySoldier2.killSoldier();

                                            controlAudiol2(deadSound);

                                            Score = Score + 200;

                                            //numberDisplay.text = String(Score);

                                        }

                         

                                    }

                         

                                    //THE TURRET

                                    //THE TURRET

                         

                                    var _turretAngle:Number = getAnglel2();

                                    _turretAngle -=  myTank.rotation;

                         

                                    //Rotate the turret towards the mouse

                                    myTank.turretMovieClip.rotation = _turretAngle;

                         

                                    //var angle:Number = Math.atan2 (mouseY - myTank.y, mouseX - myTank.x);

                                    //myTank.turretMovieClip.rotation = (angle * 180 / Math.PI) - 180;

                                }

                         

                                function getAnglel2():Number

                                {

                                    //Convert turrets points from local to global coordinates

                                    //Compensate for the rotation of the tank

                                    var turretPoint:Point = new Point(myTank.turretMovieClip.x,myTank.turretMovieClip.y);

                                    var turretPoint_X:Number = myTank.localToGlobal(turretPoint).x;

                                    var turretPoint_Y:Number = myTank.localToGlobal(turretPoint).y;

                                    var angle = Math.atan2(turretPoint_Y - stage.mouseY,turretPoint_X - stage.mouseX) * 180 / Math.PI;

                                    return angle;

                                }

                         

                                function addListenersl2()

                                {

                                    stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);

                                    stage.addEventListener(KeyboardEvent.KEY_UP,keyUpHandler);

                                    stage.addEventListener(Event.ENTER_FRAME,frameListener);

                                    stage.addEventListener(MouseEvent.CLICK,mouseDownHandler);

                                    mybtn.addEventListener(MouseEvent.MOUSE_DOWN,onClickl2);

                                    mybtn2.addEventListener(MouseEvent.MOUSE_DOWN,onClick2);

                                    stage.addEventListener(Event.ENTER_FRAME,pauseListener);

                                    _l2Timer.addEventListener(TimerEvent.TIMER, enemyTankShoot);

                         

                                   

                               

                                }

                                function getAngle2l2(aObject2:MovieClip):Number

                                {

                                    var turPoint:Point = new Point(aObject2.x,aObject2.y);

                                    var turPoint_X:Number = aObject2.localToGlobal(turPoint).x;

                                    var turPoint_Y:Number = aObject2.localToGlobal(turPoint).y;

                                    var angle2 = Math.atan2(turPoint_Y - myTank.y,turPoint_X - myTank.x) * 180 / Math.PI;

                                    return angle2;

                                }

                         

                                function enemyTankShoot(event:TimerEvent):void

                                {

                                    //Create a bullet and add it to the stage

                                    enemyBullet1l2 = new TankBullet(getAngle2l2(anEnemyTank.enemyTurretMovieClip));

                                    level2bg.addChild(enemyBullet1l2);

                         

                                    //Set the bullet's starting position

                                    var radius:int = 30;

                                    var angle:Number = (anEnemyTank.rotation + anEnemyTank.enemyTurretMovieClip.rotation - 15)  * Math.PI / 180;

                                    enemyBullet1l2.x = anEnemyTank.x    + anEnemyTank.enemyTurretMovieClip.x + radius * Math.cos(angle);

                                    enemyBullet1l2.y = anEnemyTank.y  +anEnemyTank.enemyTurretMovieClip.y+ radius * Math.sin(angle);

                         

                                    //Set the bullet's velocity based

                                    //on the angle

                                    enemyBullet1l2.vx = Math.cos(angle) * 5;

                                    enemyBullet1l2.vy = Math.sin(angle) * 5;

                         

                                    //Push the bullet into the _l2bullets array

                                    _eBulletl2.push(enemyBullet1l2);

                         

                                    //Find a random start time for the next bullet

                                    //var randomFireTime:Number = Math.round(Math.random() * 1000) + 200;

                                    _l2Timer.delay = 750;

                                }

                         

                                function onClick2(event:MouseEvent):void

                                {

                                    stage.addEventListener(Event.ENTER_FRAME,frameListener);

                                    stage.addEventListener(MouseEvent.CLICK,mouseDownHandler);

                         

                                }

                                function onClickl2(event:MouseEvent):void

                                {

                                    stage.removeEventListener(Event.ENTER_FRAME,frameListener);

                                    stage.removeEventListener(MouseEvent.CLICK,mouseDownHandler);

                                    anEnemyTank.enemyTankMovieClip.eTreads.stop();

                                    //Mouse.show();

                                   

                         

                                }

                               

                                function mouseDownHandler(event:MouseEvent):void

                                {

                                    fireBullet();

                         

                                }

                         

                                function fireBullet()

                                {

                                    var bullet:TankBullet = new TankBullet(getAnglel2());

                                    stage.addChild(bullet);

                         

                                    var radius:int = -20;

                         

                                    var angle:Number = (myTank.rotation + myTank.turretMovieClip.rotation) * Math.PI / 180;

                         

                         

                                    //3. Position the bullet

                                    bullet.x = myTank.x +myTank.turretMovieClip.x + 20 + radius * Math.cos(angle);

                                    bullet.y = myTank.y +myTank.turretMovieClip.y - 5 + radius * Math.sin(angle);

                                    //Set the bullet's velocity based

                                    //on the angle

                                    bullet.vx = Math.cos(angle) * -7 + myTank.vx;

                                    bullet.vy = Math.sin(angle) * -7 + myTank.vy;

                         

                         

                                    //Push the bullet into the _l2bullets array

                                    _l2bullets.push(bullet);

                                    controlAudiol2(shootSoundl2);

                                    bombsLeftl2--;

                                    bombsLeftDisplay2.text = String(bombsLeftl2);

                         

                                    trace("you still have " + bombsLeftl2);

                                    if (bombsLeftl2 == 0)

                                    {

                                        stage.removeEventListener(MouseEvent.CLICK,mouseDownHandler);

                                        //stage.addEventListener(MouseEvent.CLICK , playemptySound);

                                        explodeTank(myTank.x ,myTank.y,myTank);

                                                myTank.ismyTankDestroyed = true;

                                        endGamel2("You Loose");

                                       

                                    }

                                }

                         

                         

                                function keyUpHandler(event:KeyboardEvent):void

                                {

                                    switch (event.keyCode)

                                    {

                                        case Keyboard.LEFT :

                                            myTank.rotationSpeed = 0;

                                            break;

                         

                                        case Keyboard.RIGHT :

                                            myTank.rotationSpeed = 0;

                                            break;

                         

                                        case Keyboard.UP :

                                            myTank.accelerate = false;

                                    }

                                }

                                function pauseListener(event:Event):void

                                {

                                    updateCursor();

                                }

                                function frameListener(event:Event):void

                                {

                         

                                    if(!myTank.ismyTankDestroyed)

                                    {

                                    moveTank();

                                    }

                                    l2moveBullets();

                                   

                                    if (! anEnemyTank.isDestroyed && !myTank.myTankisDestroyed)

                                    {

                                        moveEnemyTank(anEnemyTank);

                                    }

                                   

                                   

                                    moveGroundUnits();

                                   

                                    moveEnemyBulletl2();

                                    //checkWinner();

                                   

                         

                         

                         

                                }

                               

                                /* function rangeListener( )

                                {

                                    var eDistanceX:Number = myTank.x - anEnemyTank.x;

                                    var eDitanceY:Number = myTank.y - anEnemyTank.y;

                                    var rangeDistance:Number = Math.sqrt(eDistanceX * eDistanceX + eDitanceY * eDitanceY);

                                    if (rangeDistance <= 200)

                                    {

                                       

                                            _l2Timer.start();

                                        }

                                        else

                                        {

                                            _l2Timer.stop();

                                        }}*/

                                function moveEnemyBulletl2()

                                {

                                    for (var i:int = 0; i < _eBulletl2.length; i++)

                                        {

                                            enemyBullet1l2 = _eBulletl2[i];

                                            enemyBullet1l2.x +=  enemyBullet1l2.vx;

                                            enemyBullet1l2.y +=  enemyBullet1l2.vy;

                                           

                                            if (enemyBullet1l2.y < 0 || enemyBullet1l2.x < 0 || enemyBullet1l2.x > stage.stageWidth || enemyBullet1l2.y > stage.stageHeight)

                                        {

                                            //Remove the bullet from the stage

                                            level2bg.removeChild(enemyBullet1l2);

                                            //Remove the bullet from the _l2bullets

                                            //array

                                            _eBulletl2.splice(i,1);

                                            enemyBullet1l2 = null;

                                            //Reduce the loop counter

                                            //by one to compensate

                                            //for the removed bullet

                                           

                                        }

                                        if(enemyBullet1l2 != null && enemyBullet1l2.hitTestObject(myTank.tankMovieClip.tankHitTest))

                                        {

                                            level2bg.removeChild(enemyBullet1l2);

                                            _eBulletl2.splice(i,1);

                                            enemyBullet1l2 = null;

                                            myTankHealth --;

                                            if(myTankHealth ==0)

                                            {

                                                explodeTank(myTank.x ,myTank.y,myTank);

                                                myTank.ismyTankDestroyed = true;

                                                endGamel2("You Loose ");

                                                Mouse.show();

                                               

                                            }

                                        }

                                        }

                                }

                                function endGamel2(Message:String)

                                {

                                    Mouse.show();

                                    gameOverScreen  = new GameOVer();

                                    gameOverScreen.gameover_txt.text = Message;

                                    gameOverScreen.playAgain_btn.addEventListener(MouseEvent.CLICK, restartGame);

                                    gameOverScreen.l2main_btn.addEventListener(MouseEvent.CLICK, l2MainMenu);

                                    gameOverScreen.l2score_btn.addEventListener(MouseEvent.CLICK, l2Score);

                                    addChild(gameOverScreen);

                                    gameOverScreen.x = stage.stageWidth/2;

                                    gameOverScreen.y = stage.stageHeight/2;

                                    removeChild(level2bg);

                                    stage.removeChild(numberDisplay);

                                    stage.removeChild(scoreDisplay);

                                    stage.removeChild(bombsLeftDisplay2);

                                    BombsNum.text ="" ;

                                    removeChild(mybtn);

                                    removeChild(mybtn2);

                                    bombsLeftDisplay2.text = "";

                                    removeChild(myCursor);

                                   

                                }

                                function restartGame(event:MouseEvent):void

                                {

                                    init();

                                    removeChild(gameOverScreen);

                                    myTankHealth = 10;

                                   

                                   

                                }

                                function l2MainMenu(event:MouseEvent):void

                                {

                                   

                                    removeChild(gameOverScreen);

                                    gotoAndPlay("GUI");

                                   

                                   

                                }

                                function l2Score(event:MouseEvent):void

                                {

                                   

                                    removeChild(gameOverScreen);

                                    gotoAndPlay("Score2");

                                   

                                   

                                }

                                function explodeTank(xPos:uint,yPos:uint,target:DisplayObject)

                                {

                         

                                  var anExp:ExplosionClass = new ExplosionClass(xPos,yPos,"bombExplosion");

                                    addChild(anExp);

                                    removeChild(target);

                                    if (target == myTank)

                                    {

                                        stage.removeEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler);

                                    stage.removeEventListener(KeyboardEvent.KEY_UP,keyUpHandler);

                                    stage.removeEventListener(Event.ENTER_FRAME,frameListener);

                                    stage.removeEventListener(MouseEvent.CLICK,mouseDownHandler);

                                    mybtn.removeEventListener(MouseEvent.MOUSE_DOWN,onClickl2);

                                    mybtn2.removeEventListener(MouseEvent.MOUSE_DOWN,onClick2);

                                    stage.removeEventListener(Event.ENTER_FRAME,pauseListener);

                                    _l2Timer.removeEventListener(TimerEvent.TIMER, enemyTankShoot);

                                   

                         

                                    }

                         

                         

                                    //removeEventListener( Event:Timer,timerHandler);

                                }

                                function updateCursor()

                                {

                         

                         

                                    myCursor.x = mouseX;

                                    myCursor.y = mouseY;

                                   

                                }

                         

                         

                              function moveGroundUnits()

                                {

                                    for (var j:int = 0; j < _Gunit.length; j++)

                                    {

                                        if(!_Gunit[j].isDestroyed && !myTank.myTankisDestroyed)

                                    {

                                        _Gunit[j].moveBase(myTank.x,myTank.y);

                         

                                    }

                                    }

                                }

                                function moveEnemyTank(object:MovieClip)

                                {

                         

                                    distanceX = myTank.x - object.x;

                                    distanceY = myTank.y - object.y;

                                    //get total distance as one number

                                    distanceTotal = Math.sqrt(distanceX * distanceX + distanceY * distanceY);

                                    //trace("dTotal"+ distanceTotal);

                                    //check if target is within agro range

                                    if (distanceTotal > agroRange  )

                                    {

                                        //calculate how much to move

                                        moveDistanceX = turnRate * distanceX / distanceTotal;

                                        moveDistanceY = turnRate * distanceY / distanceTotal;

                                        //increase current speed

                                        moveX +=  moveDistanceX;

                                        moveY +=  moveDistanceY;

                                        //get total move distance

                                        totalmove = Math.sqrt(moveX * moveX + moveY * moveY);

                                        //apply easing

                                        moveX = speed * moveX / totalmove;

                                        moveY = speed * moveY / totalmove;

                                        object.x +=  moveX;

                                        object.y +=  moveY;

                                        object.rotation = Math.atan2(moveY,moveX) * radians;

                                        object.enemyTurretMovieClip.rotation = 0;

                                        object.enemyTankMovieClip.eTreads.play();

                        _l2Timer.stop();

                                    }

                                    else

                                    {

                                    var eturretPoint:Point = new Point(object.enemyTurretMovieClip.x,object.enemyTurretMovieClip.y);

                                    var eturretPoint_X:Number = object.localToGlobal(eturretPoint).x;

                                    var eturretPoint_Y:Number = object.localToGlobal(eturretPoint).y;

                                    var angle2 = Math.atan2(eturretPoint_Y - myTank.y,eturretPoint_X - myTank.x) * 180 / Math.PI;

                                   

                                   

                                    object.enemyTurretMovieClip.rotation = angle2;

                         

                         

                        _l2Timer.start();

                         

                                        object.enemyTankMovieClip.eTreads.stop();

                                       

                         

                         

                                    }

                         

                         

                         

                         

                         

                                }

                               

                               

                         

                                function keyDownHandler(event:KeyboardEvent):void

                                {

                                    //trace("keyDownHandler");

                                    switch (event.keyCode)

                                    {

                                        case Keyboard.LEFT :

                                            myTank.rotationSpeed = -3;

                                            break;

                         

                                        case Keyboard.RIGHT :

                                            myTank.rotationSpeed = 3;

                                            break;

                         

                                        case Keyboard.UP :

                                            myTank.accelerate = true;

                                            break;

                                           

                                           

                         

                                   

                         

                                        case Keyboard.SPACE :

                                            //fireMissiles();

                                       

                                    }

                                }

                         

                        here is the full code at the frame that got loaded  from the button

                        the listener im using is an enter frame

                        hope it is clear now

                        if u check the game play u might under stand what i mean

                         

                        Subject: Re: Time line Time line

                         

                         

                         

                         

                         

                         

                         

                         

                         

                         

                            Re: Time line

                         

                         

                            created by Ned Murphy in Action Script 3 - View the full discussion

                         

                         

                         

                        It is nearly impossible to read the code you posted.  While I can find that you have a MOUSE_DOWN event that triggers firing a bullet, I don't see where you added that listener, only where you remove it. What I would guess is that you are entering the frame with the MOUSE_DOWN still registering from having clicked to get to the frame, which triggers the bullet to fire. What kind of MouseEvent do you have triggering the startLevel2 function ?  It should be a CLICK event

                         

                         

                        Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: Re: Time line

                        To unsubscribe from this thread, please visit the message page at Re: Time line. In the Actions box on the right, click the Stop Email Notifications link.

                         

                        Start a new discussion in Action Script 3 by email or at Adobe Forums

                          For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

                        • 9. Re: Time line
                          Ned Murphy MVP

                          I already told you I know what you mean.  I will not even begin to try to find relevant code in all of what you posted.

                          • 10. Re: Time line
                            mr.shumi Community Member

                            so what i have to do now to fix the problem ?

                             

                            Date: Fri, 13 Apr 2012 20:35:41 -0600

                            Subject: Re: Time line Time line

                             

                             

                                created by Ned Murphy in Action Script 3 - View the full discussion

                             

                             

                             

                            I already told you I know what you mean.  I will not even begin to try to find relevant code in all of what you posted.

                             

                             

                            Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: Re: Time line

                            To unsubscribe from this thread, please visit the message page at Re: Time line. In the Actions box on the right, click the Stop Email Notifications link.

                             

                            Start a new discussion in Action Script 3 by email or at Adobe Forums

                              For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.