14 Replies Latest reply on Sep 24, 2014 7:54 AM by juanaldinho

    How do i assign a keyboard function to a buttton created.

    juanaldinho

      How do i assign a keyboard function to a buttton created. I have a game witch if i press SPACE bar somethiong happens. but i want to crate a button on screen tha if i press it it would be the same as pressing the space bar

        • 1. Re: How do i assign a keyboard function to a buttton created.
          Ned Murphy Adobe Community Professional & MVP

          Just assign code to the button that processes the desired code when you click it...

           

          yourButton.onRelease = doSomethingFunction;

           

          function doSomethingFunction(){

              //  whatever...

          }

           

          Have the keypress calling that same function

          • 2. Re: How do i assign a keyboard function to a buttton created.
            juanaldinho Level 1

            thnk you Ned, for your response, im sorry but im new to flash and dont understand, If i have a button that has a instance name of spacebar. how do i program it so that when a press it is like pressing the space bar on the keyboard.

             

            Thank you very much

            • 3. Re: How do i assign a keyboard function to a buttton created.
              Ned Murphy Adobe Community Professional & MVP

              What does pressing the spacebar do?  Whatever that is, just assign the same kind of code for the button.  If the button is named spacebar, then just replace what I called "yourButton" with "spacebar"

              • 4. Re: How do i assign a keyboard function to a buttton created.
                juanaldinho Level 1

                Well thats the problem. that these is comething that i have not been abel to find out, This is a project that was started by someone else. , its a game. and the space bar releases something in the game. but i need to put a button on screen for a touch tv.

                • 5. Re: How do i assign a keyboard function to a buttton created.
                  Ned Murphy Adobe Community Professional & MVP

                  If you show the code for the spacebar then it might be possible to provide an example of the code to use for the button.

                  • 6. Re: How do i assign a keyboard function to a buttton created.
                    juanaldinho Level 1

                    stop();

                    _root.dropsoundon = 0;

                    _root.shrinkamount = 0.1;

                    _root.gamepaused = 0;

                    _root.wobbleamount = 0;

                    _root.moveamount = 1;

                    _root.combobonus = 100;

                    _root.combonumber = 0;

                    _root.panamount = 0.1;

                    _root.blocknumber = 0;

                    _root.score = 0;

                    _root.lives = 3;

                    _root.blockplaced = 0;

                    _root.blockpositions = new Array();

                    makeblock();

                    _global.placeblock = function ()

                    {

                        _root.towerheight = 0;

                        _root.towermove = 1;

                        _root.blockplaced = 0;

                        _root.blocknumber = _root.blocknumber + 1;

                        _root.dropsoundon = 0;

                        makeblock();

                    }

                    ;

                    _global.lifelost = function ()

                    {

                        if (_root.lives > 1)

                        {

                            _root.lives = _root.lives - 1;

                            _root.lifelostmovie.gotoAndPlay(2);

                            return;

                        }

                        explosion = _root.attachMovie("explosion", "explosion", 400);

                        explosion._x = _root.objcell_mc.ship._x + 250;

                        explosion._y = _root.objcell_mc.ship._y + 250;

                        _root.objcell_mc.removeMovieClip(this);

                        _root.towershrink = 1;

                        _root.gameovermovie.play();

                    }

                    ;

                    _root.attachMovie("shaker", "shaker", 50000);

                    _root.shaker._x = -45;

                    _root.shaker._y = -40;

                    _root.shaker.theshake.thecombobar._visible = 0;

                    _root.attachMovie("lifelostmovie", "lifelostmovie", 50001);

                    _root.lifelostmovie._x = 200;

                    _root.lifelostmovie._y = 280;

                    _root.attachMovie("combolost", "combolost", 50002);

                    _root.combolost._x = 300;

                    _root.combolost._y = 500;

                    _root.attachMovie("pausedmovie", "pausedmovie", 50003);

                    _root.pausedmovie._x = -450;

                    _root.pausedmovie._y = 300;

                    _root.attachMovie("gameovermovie", "gameovermovie", 50004);

                    _root.gameovermovie._x = 200;

                    _root.gameovermovie._y = 280;

                    • 7. Re: How do i assign a keyboard function to a buttton created.
                      Ned Murphy Adobe Community Professional & MVP

                      I do not see any code assigned for use of the keyboard in what you show.  You might have to select objects on the stage while the Actions window is open to see other code.

                      • 8. Re: How do i assign a keyboard function to a buttton created.
                        juanaldinho Level 1

                        //Maby this: thank you so much for the help//

                         

                         

                         

                        function swing_crane()

                        {

                            if (_root.gamepaused == 0)

                            {

                                myRadians = Math.atan2(-600 - this._y - 300, _root.SW / 2 - this._x - _root.SW / 2);

                                myDegrees = Math.round(myRadians * 180 / 3.14159265359);

                                if (_root.blockplaced == 0)

                                {

                                    this._rotation = myDegrees + 90;

                                }

                                hitvelocity = Math.sqrt(this.vx * this.vx + this.vy * this.vy);

                                this.vx = this.vx * kDamp;

                                this.vy = this.vy * kDamp;

                                this.vx = this.vx + gTx * kGravWeight;

                                this.vy = this.vy + gTy * kGravWeight;

                                var __reg4 = 0;

                                var __reg3 = 0;

                                this.vx = this.vx + __reg4;

                                this.vy = this.vy + __reg3;

                                this._x = this._x + this.vx;

                                this._y = this._y + this.vy;

                            }

                        }

                        stop();

                        _root.messageword = "SPACE TO RELEASE";

                        _root.messageUp.play();

                        _root.song.stop();

                        _root.song.attachSound("tune");

                        _root.song.start(0, 999999999);

                        kGravWeight = 0.9;

                        kDamp = 0.98;

                        kCollisionDamp = 0.3;

                        _root.SW = 580;

                        _root.SH = 500;

                        kRadiansToDegrees = 57.2957795131;

                        kDegreesToRadians = 0.0174532925199;

                        gTx = 0;

                        gTy = 0;

                        guys = [];

                        _root.createEmptyMovieClip("objcell_mc", 2);

                        objcell_mc._x = _root.SW / 2;

                        objcell_mc._y = _root.SH / 2;

                        _root.createEmptyMovieClip("thetower", 3);

                        thetower._x = objcell_mc._x;

                        thetower._y = objcell_mc._y;

                        _root.attachMovie("thetowerback", "thetowerback", 1);

                        _root.thetowerback._x = 300;

                        _root.thetowerback._y = 250;

                        miny = -4000;

                        maxy = -500;

                        minx = -1500;

                        maxx = -600;

                        i = 0;

                        while (i < 10)

                        {

                            cloud = _root.thetowerback.attachMovie("clouds", "clouds" + i, i);

                            cloud.gotoAndPlay(Math.round(random(1000) + 1));

                            cloud._y = Math.round(Math.random() * (maxy - miny + 1)) + miny;

                            cloud._x = Math.round(Math.random() * (maxx - minx + 1)) + minx;

                            ++i;

                        }

                        i = 10;

                        while (i < 20)

                        {

                            birds = _root.thetowerback.attachMovie("birds", "birds" + i, 12 + i);

                            birds.gotoAndPlay(Math.round(random(1000) + 1));

                            birds._y = Math.round(Math.random() * (maxy - miny + 1)) + miny;

                            birds._x = Math.round(Math.random() * (maxx - minx + 1)) + minx;

                            ++i;

                        }

                        _global.makeblock = function ()

                        {

                            var __reg2 = objcell_mc.attachMovie("ship", "ship", 1000);

                            guys.push(__reg2);

                            _root.blockstartingx = _root.blocknumber * 2 + 100;

                            __reg2._x = 0 - _root.blockstartingx + Math.floor(Math.random() * (_root.blockstartingx - (0 - _root.blockstartingx) + 1));

                            __reg2._y = -340;

                            __reg2.vx = __reg2.vy = 0;

                            __reg2.lx = __reg2.ly = 0;

                            __reg2.radius = 15;

                            var __reg3 = 128 + random(127);

                            __reg2.onEnterFrame = swing_crane;

                        }

                        ;

                        objcell_mc.onEnterFrame = function ()

                        {

                            var __reg2 = guys.length - 1;

                            for (;;)

                            {

                                if (__reg2 < 0)

                                {

                                    return;

                                }

                                var __reg1 = guys[__reg2];

                                var __reg3 = Math.sqrt(__reg1._x * __reg1._x + __reg1._y * __reg1._y);

                                var __reg4 = Math.atan2(__reg1._y, __reg1._x);

                                __reg1._x = Math.cos(__reg4 + kSpinR) * __reg3;

                                __reg1._y = Math.sin(__reg4 + kSpinR) * __reg3;

                                --__reg2;

                            }

                        }

                        ;

                        • 10. Re: How do i assign a keyboard function to a buttton created.
                          juanaldinho Level 1

                          Cant find it, is there any other way?

                          • 11. Re: How do i assign a keyboard function to a buttton created.
                            juanaldinho Level 1

                            Maby this:

                             

                            if (Key.isDown(32))

                                    {

                                        _root.blockplaced = 1;

                                        _root.objcell_mc.ship.rope._visible = false;

                                    }

                            • 12. Re: How do i assign a keyboard function to a buttton created.
                              juanaldinho Level 1

                              //  Action tag #1

                               

                               

                              stop();

                              _root.dropsoundon = 0;

                              _root.shrinkamount = 0.1;

                              _root.gamepaused = 0;

                              _root.wobbleamount = 0;

                              _root.moveamount = 1;

                              _root.combobonus = 100;

                              _root.combonumber = 0;

                              _root.panamount = 0.1;

                              _root.blocknumber = 0;

                              _root.score = 0;

                              _root.lives = 3;

                              _root.blockplaced = 0;

                              _root.blockpositions = new Array();

                              makeblock();

                              _global.placeblock = function ()

                              {

                                  _root.towerheight = 0;

                                  _root.towermove = 1;

                                  _root.blockplaced = 0;

                                  _root.blocknumber = _root.blocknumber + 1;

                                  _root.dropsoundon = 0;

                                  makeblock();

                              }

                              ;

                              _global.lifelost = function ()

                              {

                                  if (_root.lives > 1)

                                  {

                                      _root.lives = _root.lives - 1;

                                      _root.lifelostmovie.gotoAndPlay(2);

                                      return undefined;

                                  }

                                  explosion = _root.attachMovie("explosion", "explosion", 400);

                                  explosion._x = _root.objcell_mc.ship._x + 250;

                                  explosion._y = _root.objcell_mc.ship._y + 250;

                                  _root.objcell_mc.removeMovieClip(this);

                                  _root.towershrink = 1;

                                  _root.gameovermovie.play();

                              }

                              ;

                              _root.attachMovie("shaker", "shaker", 50000);

                              _root.shaker._x = -45;

                              _root.shaker._y = -40;

                              _root.shaker.theshake.thecombobar._visible = 0;

                              _root.attachMovie("lifelostmovie", "lifelostmovie", 50001);

                              _root.lifelostmovie._x = 200;

                              _root.lifelostmovie._y = 280;

                              _root.attachMovie("combolost", "combolost", 50002);

                              _root.combolost._x = 300;

                              _root.combolost._y = 500;

                              _root.attachMovie("pausedmovie", "pausedmovie", 50003);

                              _root.pausedmovie._x = -450;

                              _root.pausedmovie._y = 300;

                              _root.attachMovie("gameovermovie", "gameovermovie", 50004);

                              _root.gameovermovie._x = 200;

                              _root.gameovermovie._y = 280;

                               

                               

                              //  ClipEvent 213:1

                              //    On enterFrame

                              onClipEvent(enterFrame)

                              {

                                  if (_root.gamepaused == 0)

                                  {

                                      _root.towermovex = _root.thetower._x - _root.SW / 2;

                                      if (_root.blocknumber == 0)

                                      {

                                          _root.objcell_mc.ship.block.gotoAndStop(1);

                                      }

                                      else

                                      {

                                          _root.objcell_mc.ship.block.gotoAndStop(2);

                                      }

                                      _root.shaker.theshake.thecombobar.combobar._xscale = _root.combobonus;

                                      if (_root.combonumber > 0)

                                      {

                                          _root.combobonus = _root.combobonus - 0.3;

                                      }

                                      if (_root.combobonus <= 0)

                                      {

                                          _root.shaker.theshake.thecombobar._visible = 0;

                                          _root.combonumber = 0;

                                          _root.combobonus = 100;

                                          _root.combolost.gotoAndPlay(2);

                                      }

                                      _root.windstrength = _root.blocknumber;

                                      if (_root.blockplaced == 0)

                                      {

                                          if (_root.objcell_mc.ship._y < -200)

                                          {

                                              _root.blockrise = 1;

                                          }

                                          else if (_root.objcell_mc.ship._y > -150)

                                          {

                                              _root.blockrise = 0;

                                          }

                                          if (_root.objcell_mc.ship._x > _root.blocknumber / 3 + 10)

                                          {

                                              _root.blockdirection = 1;

                                          }

                                          else if (_root.objcell_mc.ship._x < 0 - _root.blocknumber / 3 + 10)

                                          {

                                              _root.blockdirection = 0;

                                          }

                                          if (_root.blockrise == 1)

                                          {

                                              _root.objcell_mc.ship.vy = _root.objcell_mc.ship.vy + (0.15 + _root.blocknumber / 500);

                                          }

                                          else

                                          {

                                              _root.objcell_mc.ship.vy = _root.objcell_mc.ship.vy - (0.15 + _root.blocknumber / 500);

                                          }

                                          if (_root.blockdirection == 1)

                                          {

                                              _root.objcell_mc.ship.vx = _root.objcell_mc.ship.vx - (0.2 + _root.blocknumber / 500);

                                          }

                                          else

                                          {

                                              _root.objcell_mc.ship.vx = _root.objcell_mc.ship.vx + (0.2 + _root.blocknumber / 500);

                                          }

                                      }

                                      else

                                      {

                                          if (_root.dropsoundon == 0)

                                          {

                                              var randomnote = Math.random();

                                              if (randomnote >= 0.86)

                                              {

                                                  dropsound = new Sound(this);

                                                  dropsound.attachSound("piano1");

                                                  dropsound.start(0, 1);

                                              }

                                              else if (randomnote >= 0.72)

                                              {

                                                  dropsound = new Sound(this);

                                                  dropsound.attachSound("piano2");

                                                  dropsound.start(0, 1);

                                              }

                                              else if (randomnote >= 0.58)

                                              {

                                                  dropsound = new Sound(this);

                                                  dropsound.attachSound("piano3");

                                                  dropsound.start(0, 1);

                                              }

                                              else if (randomnote >= 0.44)

                                              {

                                                  dropsound = new Sound(this);

                                                  dropsound.attachSound("piano4");

                                                  dropsound.start(0, 1);

                                              }

                                              else if (randomnote >= 0.3)

                                              {

                                                  dropsound = new Sound(this);

                                                  dropsound.attachSound("piano5");

                                                  dropsound.start(0, 1);

                                              }

                                              else if (randomnote >= 0.16)

                                              {

                                                  dropsound = new Sound(this);

                                                  dropsound.attachSound("piano6");

                                                  dropsound.start(0, 1);

                                              }

                                              else

                                              {

                                                  dropsound = new Sound(this);

                                                  dropsound.attachSound("piano7");

                                                  dropsound.start(0, 1);

                                              }

                                              _root.dropsoundon = 1;

                                          }

                                          _root.objcell_mc.ship.vy = _root.objcell_mc.ship.vy + 1;

                                      }

                                      if (_root.wobbleamount > 0.3)

                                      {

                                          if (_root.thetower._x < 290 - 10 * _root.wobbleamount)

                                          {

                                              _root.towerdirection = 1;

                                          }

                                          else if (_root.thetower._x > 310 + 30 * _root.wobbleamount)

                                          {

                                              _root.towerdirection = 0;

                                          }

                                          if (_root.towerdirection == 1)

                                          {

                                              _root.thetower._x = _root.thetower._x + (_root.wobbleamount + _root.blocknumber / 100);

                                              _root.thetower["block" + (_root.blocknumber - 1)]._rotation = _root.thetower["block" + (_root.blocknumber - 1)]._rotation + 0.1;

                                              _root.thetower["block" + (_root.blocknumber - 1)]._x = _root.toweramountx;

                                              _root.thetower["block" + (_root.blocknumber - 2)]._rotation = _root.thetower["block" + (_root.blocknumber - 2)]._rotation + 0.1;

                                              _root.thetower["block" + (_root.blocknumber - 2)]._x = _root.toweramountx;

                                          }

                                          else

                                          {

                                              _root.thetower._x = _root.thetower._x - (_root.wobbleamount + _root.blocknumber / 100);

                                              _root.thetower["block" + (_root.blocknumber - 1)]._rotation = _root.thetower["block" + (_root.blocknumber - 1)]._rotation - 0.1;

                                              _root.thetower["block" + (_root.blocknumber - 1)]._x = _root.toweramountx;

                                              _root.thetower["block" + (_root.blocknumber - 2)]._rotation = _root.thetower["block" + (_root.blocknumber - 2)]._rotation - 0.1;

                                              _root.thetower["block" + (_root.blocknumber - 2)]._x = _root.toweramountx;

                                          }

                                      }

                                      if (Key.isDown(32))

                                      {

                                          _root.blockplaced = 1;

                                          _root.objcell_mc.ship.rope._visible = false;

                                      }

                                      if (_root.towermove == 1)

                                      {

                                          if (_root.towerheight < 100)

                                          {

                                              _root.thetowerback._y = _root.thetowerback._y + _root.moveamount;

                                              _root.thetower._y = _root.thetower._y + _root.moveamount;

                                              _root.towerheight = _root.towerheight + _root.moveamount;

                                              _root.moveamount = _root.moveamount + 2;

                                          }

                                          else

                                          {

                                              _root.towermove = 0;

                                              _root.towerheight = 0;

                                              _root.moveamount = 1;

                                          }

                                      }

                                      _root.dropheight = 20;

                                      if (_root.objcell_mc.ship._y > _root.dropheight)

                                      {

                                          _root.blockpositions[_root.blocknumber] = _root.objcell_mc.ship._x - _root.towermovex;

                                          if (_root.blocknumber == 0)

                                          {

                                              _root.score = _root.score + 50;

                                              myblock = _root.thetower.attachMovie("block", "block" + _root.blocknumber, 50 + _root.blocknumber);

                                              myblock._x = _root.blockpositions[_root.blocknumber];

                                              myblock._y = _root.dropheight - _root.blocknumber * 100;

                                              _root.shaker.gotoAndPlay("lighthit");

                                              placeblock();

                                          }

                                          else if (0 != _root.blockpositions[_root.blocknumber] < _root.blockpositions[_root.blocknumber - 1] + 10 & 0 != _root.blockpositions[_root.blocknumber] > _root.blockpositions[_root.blocknumber - 1] - 10)

                                          {

                                              trace("Perfect");

                                              _root.wobbleamount = _root.wobbleamount / 2;

                                              _root.combonumber = _root.combonumber + 1;

                                              if (_root.combobonus <= 75)

                                              {

                                                  _root.combobonus = _root.combobonus + 25;

                                              }

                                              else

                                              {

                                                  _root.combobonus = 100;

                                              }

                                              _root.shaker.gotoAndPlay(1);

                                              _root.shaker.theshake.thecombobar._visible = 1;

                                              _root.score = _root.score + 100 * _root.blocknumber;

                                              randomcheer = Math.random();

                                              if (randomcheer > 0.8)

                                              {

                                                  _root.messageword = "NICE";

                                              }

                                              else if (randomcheer > 0.6)

                                              {

                                                  _root.messageword = "BRICKIN COOL";

                                              }

                                              else if (randomcheer > 0.4)

                                              {

                                                  _root.messageword = "UBER AIM";

                                              }

                                              else if (randomcheer > 0.2)

                                              {

                                                  _root.messageword = "WICKED AIM";

                                              }

                                              _root.messageUp.gotoAndPlay(2);

                                              _root.shaker.theshake.combobonus.gotoAndPlay(2);

                                              myblock = _root.thetower.attachMovie("block", "block" + _root.blocknumber, 50 + _root.blocknumber);

                                              myblock._x = _root.blockpositions[_root.blocknumber - 1];

                                              myblock._y = _root.dropheight - _root.blocknumber * 100;

                                              myblock.attachMovie("perfecteffect", "perfecteffect", 40000);

                                              myblock.perfecteffect._x = -50;

                                              myblock.perfecteffect._y = 100;

                                              _root.effectx = 50;

                                              myblock.attachMovie("perfecteffect1", "perfecteffect1", 40001);

                                              myblock.perfecteffect1._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                              myblock.perfecteffect1._y = 100;

                                              myblock.perfecteffect1._rotation = random(300);

                                              myblock.attachMovie("perfecteffect1", "perfecteffect2", 40002);

                                              myblock.perfecteffect2._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                              myblock.perfecteffect2._y = 100;

                                              myblock.perfecteffect2._rotation = random(300);

                                              myblock.attachMovie("perfecteffect1", "perfecteffect3", 40003);

                                              myblock.perfecteffect3._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                              myblock.perfecteffect3._y = 100;

                                              myblock.perfecteffect3._rotation = random(300);

                                              myblock.attachMovie("perfecteffect1", "perfecteffect4", 40004);

                                              myblock.perfecteffect4._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                              myblock.perfecteffect4._y = 100;

                                              myblock.perfecteffect4._rotation = random(300);

                                              myblock.attachMovie("perfecteffect1", "perfecteffect5", 40005);

                                              myblock.perfecteffect5._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                              myblock.perfecteffect5._y = 100;

                                              myblock.perfecteffect5._rotation = random(300);

                                              if (_root.blocknumber == 0)

                                              {

                                                  myblock.gotoAndStop(1);

                                              }

                                              else

                                              {

                                                  myblock.gotoAndStop(2);

                                              }

                                              _root.blockpositions[_root.blocknumber] = myblock._x;

                                              placeblock();

                                          }

                                          else if (!(0 != _root.blockpositions[_root.blocknumber] < _root.blockpositions[_root.blocknumber - 1] - 100 | 0 != _root.blockpositions[_root.blocknumber] > _root.blockpositions[_root.blocknumber - 1] + 100))

                                          {

                                              if (_root.blockpositions[_root.blocknumber] < _root.blockpositions[_root.blocknumber - 1] - 50)

                                              {

                                                  myblockfall = _root.objcell_mc.attachMovie("blockleft", "blockleft", 15);

                                                  myblockfall._x = _root.objcell_mc.ship._x;

                                                  myblockfall._y = _root.objcell_mc.ship._y;

                                                  if (_root.blocknumber == 0)

                                                  {

                                                      myblockfall.theblock.block.gotoAndPlay(1);

                                                  }

                                                  else

                                                  {

                                                      myblockfall.theblock.block.gotoAndPlay(2);

                                                  }

                                                  _root.shaker.gotoAndPlay("blockhitleft");

                                                  trace("oh noooo fall left");

                                                  myblockfall.attachMovie("dust", "dust", 40000);

                                                  myblockfall.dust._x = -50;

                                                  myblockfall.dust._y = 100;

                                                  _root.effectx = 50;

                                                  myblockfall.attachMovie("dust", "dust1", 40001);

                                                  myblockfall.dust1._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                                  myblockfall.dust1._y = 100;

                                                  myblockfall.dust1._rotation = random(300);

                                                  myblockfall.attachMovie("dust", "dust2", 40002);

                                                  myblockfall.dust2._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                                  myblockfall.dust2._y = 100;

                                                  myblockfall.dust2._rotation = random(300);

                                                  myblockfall.attachMovie("dust", "dust3", 40003);

                                                  myblockfall.dust3._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                                  myblockfall.dust3._y = 100;

                                                  myblockfall.dust3._rotation = random(300);

                                                  myblockfall.attachMovie("dust", "dust4", 40004);

                                                  myblockfall.dust4._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                                  myblockfall.dust4._y = 100;

                                                  myblockfall.dust4._rotation = random(300);

                                                  myblockfall.attachMovie("dust", "dust5", 40005);

                                                  myblockfall.dust5._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                                  myblockfall.dust5._y = 100;

                                                  myblockfall.dust5._rotation = random(300);

                                                  if (randomcheer > 0.8)

                                                  {

                                                      _root.messageword = "WATCH OUT";

                                                  }

                                                  else if (randomcheer > 0.6)

                                                  {

                                                      _root.messageword = "BELOW";

                                                  }

                                                  else if (randomcheer > 0.4)

                                                  {

                                                      _root.messageword = "BOOOOO";

                                                  }

                                                  else if (randomcheer > 0.2)

                                                  {

                                                      _root.messageword = "NOOOOOO";

                                                  }

                                                  else

                                                  {

                                                      _root.messageword = "CAREFUL";

                                                  }

                                                  _root.messageUp.gotoAndPlay(2);

                                                  _root.blockplaced = 0;

                                                  lifelost();

                                                  makeblock();

                                              }

                                              else if (_root.blockpositions[_root.blocknumber] > _root.blockpositions[_root.blocknumber - 1] + 50)

                                              {

                                                  myblockfall = _root.objcell_mc.attachMovie("blockright", "blockright", 15);

                                                  myblockfall._x = _root.objcell_mc.ship._x;

                                                  myblockfall._y = _root.objcell_mc.ship._y;

                                                  if (_root.blocknumber == 0)

                                                  {

                                                      myblockfall.theblock.block.gotoAndPlay(1);

                                                  }

                                                  else

                                                  {

                                                      myblockfall.theblock.block.gotoAndPlay(2);

                                                  }

                                                  myblockfall.attachMovie("dust", "dust", 40000);

                                                  myblockfall.dust._x = -50;

                                                  myblockfall.dust._y = 100;

                                                  _root.effectx = 50;

                                                  myblockfall.attachMovie("dust", "dust1", 40001);

                                                  myblockfall.dust1._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                                  myblockfall.dust1._y = 100;

                                                  myblockfall.dust1._rotation = random(300);

                                                  myblockfall.attachMovie("dust", "dust2", 40002);

                                                  myblockfall.dust2._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                                  myblockfall.dust2._y = 100;

                                                  myblockfall.dust2._rotation = random(300);

                                                  myblockfall.attachMovie("dust", "dust3", 40003);

                                                  myblockfall.dust3._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                                  myblockfall.dust3._y = 100;

                                                  myblockfall.dust3._rotation = random(300);

                                                  myblockfall.attachMovie("dust", "dust4", 40004);

                                                  myblockfall.dust4._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                                  myblockfall.dust4._y = 100;

                                                  myblockfall.dust4._rotation = random(300);

                                                  myblockfall.attachMovie("dust", "dust5", 40005);

                                                  myblockfall.dust5._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                                  myblockfall.dust5._y = 100;

                                                  myblockfall.dust5._rotation = random(300);

                                                  _root.shaker.gotoAndPlay("blockhitright");

                                                  randomcheer = Math.random();

                                                  if (randomcheer > 0.8)

                                                  {

                                                      _root.messageword = "WATCH OUT";

                                                  }

                                                  else if (randomcheer > 0.6)

                                                  {

                                                      _root.messageword = "BELOW";

                                                  }

                                                  else if (randomcheer > 0.4)

                                                  {

                                                      _root.messageword = "BOOOOO";

                                                  }

                                                  else if (randomcheer > 0.2)

                                                  {

                                                      _root.messageword = "NOOOOOO";

                                                  }

                                                  else

                                                  {

                                                      _root.messageword = "CAREFUL";

                                                  }

                                                  _root.messageUp.gotoAndPlay(2);

                                                  trace("oh noooo fall right");

                                                  _root.blockplaced = 0;

                                                  lifelost();

                                                  makeblock();

                                              }

                                              else

                                              {

                                                  _root.blockprecision = _root.blockpositions[_root.blocknumber] - _root.blockpositions[_root.blocknumber - 1];

                                                  _root.blockprecision = _root.blockprecision / 100;

                                                  if (_root.blockprecision < 0)

                                                  {

                                                      _root.blockprecision = _root.blockprecision * -1;

                                                  }

                                                  normaldropsound = new Sound(this);

                                                  normaldropsound.attachSound("normaldrop");

                                                  normaldropsound.start(0, 1);

                                                  trace(_root.blockprecision);

                                                  _root.wobbleamount = _root.wobbleamount + _root.blockprecision;

                                                  _root.score = _root.score + 20 * _root.blocknumber;

                                                  myblock = _root.thetower.attachMovie("block", "block" + _root.blocknumber, 50 + _root.blocknumber);

                                                  myblock._x = _root.blockpositions[_root.blocknumber];

                                                  myblock._y = _root.dropheight - _root.blocknumber * 100;

                                                  myblockfall.attachMovie("dust", "dust", 40000);

                                                  myblockfall.dust._x = -50;

                                                  myblockfall.dust._y = 100;

                                                  _root.effectx = 50;

                                                  myblock.attachMovie("dust", "dust1", 40001);

                                                  myblock.dust1._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                                  myblock.dust1._y = 100;

                                                  myblock.dust1._rotation = random(300);

                                                  myblock.attachMovie("dust", "dust2", 40002);

                                                  myblock.dust2._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                                  myblock.dust2._y = 100;

                                                  myblock.dust2._rotation = random(300);

                                                  myblock.attachMovie("dust", "dust3", 40003);

                                                  myblock.dust3._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                                  myblock.dust3._y = 100;

                                                  myblock.dust3._rotation = random(300);

                                                  myblock.attachMovie("dust", "dust4", 40004);

                                                  myblock.dust4._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                                  myblock.dust4._y = 100;

                                                  myblock.dust4._rotation = random(300);

                                                  myblock.attachMovie("dust", "dust5", 40005);

                                                  myblock.dust5._x = 0 - _root.effectx + Math.floor(Math.random() * (_root.effectx - (0 - _root.effectx) + 1));

                                                  myblock.dust5._y = 100;

                                                  myblock.dust5._rotation = random(300);

                                                  if (_root.blocknumber == 0)

                                                  {

                                                      myblock.gotoAndStop(1);

                                                  }

                                                  else

                                                  {

                                                      myblock.gotoAndStop(2);

                                                  }

                                                  _root.shaker.gotoAndPlay("lighthit");

                                                  placeblock();

                                              }

                                          }

                                      }

                                      if (_root.objcell_mc.ship._y > 300)

                                      {

                                          _root.shaker.gotoAndPlay("freefall");

                                          _root.blockplaced = 0;

                                          if (randomcheer > 0.8)

                                          {

                                              _root.messageword = "WATCH OUT";

                                          }

                                          else if (randomcheer > 0.6)

                                          {

                                              _root.messageword = "BELOW";

                                          }

                                          else if (randomcheer > 0.4)

                                          {

                                              _root.messageword = "BOOOOO";

                                          }

                                          else if (randomcheer > 0.2)

                                          {

                                              _root.messageword = "NOOOOOO";

                                          }

                                          else

                                          {

                                              _root.messageword = "CAREFUL";

                                          }

                                          _root.messageUp.gotoAndPlay(2);

                                          lifelost();

                                          makeblock();

                                          trace("total miss");

                                      }

                                  }

                                  if (Key.isDown(80))

                              • 13. Re: How do i assign a keyboard function to a buttton created.
                                Ned Murphy Adobe Community Professional & MVP

                                Yes, the spacebar keycode is 32, so what you would need to do is assign the same code that it executes for the button.

                                spacebar.onPress = function(){

                                            _root.blockplaced = 1;

                                            _root.objcell_mc.ship.rope._visible = false;

                                }

                                 

                                and you might need to reverse that when the button is released (you'll have to figure that out)...

                                 

                                spacebar.onRelease = function(){

                                            _root.blockplaced = 0;

                                            _root.objcell_mc.ship.rope._visible = true;

                                }

                                • 14. Re: How do i assign a keyboard function to a buttton created.
                                  juanaldinho Level 1

                                  Hey Ned that was it, i cant thank you enough.