Skip to main content
Known Participant
June 8, 2013
Question

player move to tile

  • June 8, 2013
  • 1 reply
  • 623 views

I have a player movie clip and a tile movieclip. When I click the tile movieclip, it adds buttons on the screen. When I click the button, I want the player to go to that tile movieclip that was clicked, however, it isn't working.

function mouseclick(event:MouseEvent)

                              {

                                                  (event.currentTarget as Tile).outline.gotoAndStop("active");

                                                  addChild(skip_btn);

                                                  skip_btn.buttonMode = true;

                                                  ////////////////SKIP BUTTON FUNCTIONALITY/////////////////////

                                                  if (player.x == (event.currentTarget.x) && player.y == (event.currentTarget.y)) {

                                                            skip_btn.buttonMode = false;

                                                            skip_btn.gotoAndStop("inactive");

                                                  }

                                                  else {

                                                            skip_btn.gotoAndStop("out");

                                                            skip_btn.buttonMode = true;

                                                  }

                              }

if (skip_btn.skipClick == true){

                                                            removeChild(skip_btn);

                                                            player.x = (event.currentTarget.x);

  player.y = (event.currentTarget.y);

                                                            trace("MOVE!");

                                                            skip_btn.skipClick = false;

                                                  }

Basically if a player is on a tile and you click that tile, then the button appears, but it isn't clickable. If you click another tile that the player is not on, then it is clickable and the player should move there, but it doesn't. Any ideas on how to get this to work?

This topic has been closed for replies.

1 reply

kglad
Community Expert
June 8, 2013

i assume you're posting your tile listener function and have not posted the button's listener function. 

in the tile listener function i do not see that you're saving a reference to the tile so it's not clear how the button's listener function will know which tile to go to.  you probably need to fix that and you should post your button's listener function.

ultraruleAuthor
Known Participant
June 8, 2013

The button's listener function just declares a variable called skipClip true. To save a reference, should I create a new variable(let's call it tileSelected) that's a boolean and when the tile is clicked, say event.currentTarget.tileSelected = true?

kglad
Community Expert
June 8, 2013

if the button's listener function resets skipClip, how is mouseclick called AFTER that listener function executes?