Changing frames in a class


so i'm working on pretty basic game @ moment. when press down key, want character (at moment, square) slide underneath obstacles. have standing animation 1 frame , sliding within same class, when press down key, switches second frame yet object on first frame remains on top. suspect because created square so:

 

//create square

          var newsquare:number = 1;

          var square:square = new square;

          square.x = 50;

          square.y = 180;

          stage.addchild(square);

 

that it's creating new squares overtop 1 that's sliding. code sliding follows:

 

//slide

          var down:boolean = false;

          stage.addeventlistener(keyboardevent.key_down, _slidedown);

          function _slidedown(e:keyboardevent):void {

                    if (e.keycode == 40) {

                              down = true;

                    }

          }

          stage.addeventlistener(keyboardevent.key_up, _slideup);

          function _slideup(e:keyboardevent):void {

                    if (e.keycode == 40) {

                              down = false;

                    }

          }

          stage.addeventlistener(event.enter_frame, _slide);

          function _slide(e):void {

                    if (down == true) {

                              square.gotoandplay(2);

                    }

                    if (down == false) {

                              square.gotoandplay(1);

                    }

          }

 

if i'm right generating infinite squares, me fix it? tried using conditional , number variable , changing number when square created, didn't help. if i'm not right, other appreciated.

when create things dynamically, not have home in timeline unless make them child of object secured timeline.



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

Warning, the Safe Path is not accessible vm3 - Joomla! Forum - community, help and support

uppercase letters in url - Joomla! Forum - community, help and support

Joomla! Update is not offering Joomla 3 - Joomla! Forum - community, help and support