1 Reply Latest reply on May 13, 2013 6:08 AM by kglad

    Need Help Understanding AS3

    stask

      Hi to all!

       

      Im a flash newby who visits this forum from time to time when i dont understand something =\ and i know that there are probably thousands of things you could be doing other than helping me out, but if you have a second please do.

       

      I've been learning flash by doing (because i simply cannot learn any other way -.-) and its been going great but recently ive upgraded from flash mx to cs5.5...

      This has brought me to a stand still because alot of the code i've learned has been replaced with new code, and although i have search and read alot of things on the net none of it is getting through.

       

      So i was hopeing to borrow some of your knowhow, if i put down some code from AS2 could you please translate it to AS3? any additional advise would also be great!

       

      On my first page i would have all of my variables in _global.. for example _global.money = 100; which would start the game with 100 money. and in an eventual page to come there would be a button to deduct some money to progress to a new page like

       

      on (release){

      if(_global.money<=50){

      _root.gotoAndPlay("nofunds");

      }else{

      _global.money -= 75;

      _root.gotoAndPlay("enterpark");

      }

      }

       

      But after moving my flashmx .fla to cs5.5 it sorta works but gets stuck on my variables from time to time... the .fla so far on flashmx was working fine but is now "glitchy" and i dont have enough skill to fix it without some help so please any and all are welcome to help with my problem.

       

      Thank you very much for reading!

        • 1. Re: Need Help Understanding AS3
          kglad Adobe Community Professional & MVP

          in as3, there are no global variables if you code on timelines and no code can be attached to objects so you must assign an instance name (eg, btn) to the object that has the shown code attached and use that instance name in your actionscript:

           

          btn.addEventListener(MouseEvent.CLICK,btnF);

           

          function btnF(e:MouseEvent):void{

          if(MovieClip(root).money<=50){

          MovieClip(root).gotoAndPlay("nofunds");

          } else {

          MovieClip(root).money-=75;

          MovieClip(root).gotoAndPlay("enterpark");

          }

          }