Skip to main content
Participant
September 10, 2015
Question

how to check if a button is clicked in an if statement

  • September 10, 2015
  • 1 reply
  • 298 views

Alright so, I'm making a game. I forgot how to do some coding over the year and I'm starting up back again. So here's the deal; I can't remember how to check if a button has been clicked in an if statement. For example, if button1 is down, than invoke this function.

Anyone got any ideas? Here's what I have:

package{

  import flash.display.MovieClip;

  import flash.text.TextField;

  public class FirstClass extends MovieClip {//

  public var b1:TextField = new TextField

  public var pic1:picture1 = new picture 1

  public var background:BG = new BG

 

  private function summonGabe(){//assigns properties to b1 and adds it

  b1.addEventListener(MouseEvent. CLICK, clickHandler);

  function ClickHandler(event:MouseEvent){

  b1.boarder = true

  b1.text = Summon Lord Gaben 

  b1.x = 300

  b1.y = 350

  b1.height = 100

  }

  }

 

  private function stateOne(){//the function in which i want to check if the button is pressed, if so than invoke summonGabe

  if( ){

      summonGabe();

      trace("You have awoken the one and only, Lord Gaben!")

    }

  }

  private function FirstClass(){//constructor

  addChild(background);

  trace(“Welcome to the Land of Lord Gaben”);

  summonGabe();

  }

  }//end of class

}//end of package


Help please  ^^

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
September 10, 2015

package{

  import flash.display.MovieClip;

  import flash.text.TextField;

  public class FirstClass extends MovieClip {//

  public var b1:TextField = new TextField

  public var pic1:picture1 = new picture 1

  public var background:BG = new BG

 

  private function summonGabe(){//assigns properties to b1 and adds it

  b1.addEventListener(MouseEvent. CLICK, clickHandler);

  }


// never nest named functions

private function clickHandler(event:MouseEvent){  // case counts since fp 6, as2.

  b1.boarder = true; 

  b1.text = Summon Lord Gaben 

  b1.x = 300

  b1.y = 350

  b1.height = 100

  }

 

  private function stateOne(){//the function in which i want to check if the button is pressed, if so than invoke summonGabe

if(b1.boader ){

      summonGabe(); 

      trace("You have awoken the one and only, Lord Gaben!")

    }

  }

  private function FirstClass(){//constructor

  addChild(background);

  trace(“Welcome to the Land of Lord Gaben”);

  summonGabe();

  }

  }//end of class

}//end of package