1 Reply Latest reply on Aug 12, 2012 9:00 AM by Ned Murphy

    Making a object appear and dissapear


      okay i know this is way off but this is my attemp. So when i press space I want the 'sword' to appear and when its not i dont want it to be there.

      Sorry if this is actually not even 1% on the right track, any clue to what im talking about? cheers.




      var weopon_var:boolean = false;



      if (Key.isDown(Key.SPACE)){

      weopon_var = true;

      else {

      weopon_var = false;



      if (weopon_var = true){


      } else {

        (weopon_var = false){




        • 1. Re: Making a object appear and dissapear
          Ned Murphy Adobe Community Professional & MVP

          There are errors in the code you will need to fix before you can get anywhere with it... your if/else structuring/syntax is wrong.  Look for examples offor the correct way to structure them.


          When you compare values in a conditional for equality you use "==" not "=".  "=" is for assigning value to something.


          Further, if you are testing a boolean (true/false), you don't need to test it explicitly.  The conditional is evaluating the true/false nature of what you put in the parenthesis.  And if you are testing a boolean, if it isn't one it has to be the other.  So you could reduce your second test to be...



                  // do stuff

             } else {

                  // do other stuff



          Whether it will work when you get the errors out depends on where you have that code.  If that code sits as shown, it executes once when you enter that frame an only once.  What you really need to do is have a listener for a keyboard event that is tied to that code so that when you use the keyboard the function that code is in gets executed.  Look into "Key.addListener"