3 Replies Latest reply on Oct 13, 2006 7:53 AM by csthsl

    eval() function

    csthsl
      Hey all, I'm having a hard time figuring out how to use the eval function in actionscript

      I know how to use it in javascript but for some reason I can't get it to work in flash. I am using Flash 8.

      See the attached code.

      What am I doing wrong? Is there a better way to do it?

        • 1. Re: eval() function
          Level 7
          > Hey all, I'm having a hard time figuring out how to use the eval function
          > in
          > actionscript

          Reading the help helps .. good idea to read that first before asking as it
          is all explained there.

          > I know how to use it in javascript but for some reason I can't get it to
          > work
          > in flash. I am using Flash 8.

          That's because AS1 and AS2 are only limited subsets of Javascript, and some
          of the things hav edifferent semantics (meaning they look the same but work
          differently .. which is confusing).

          Flash player does not include a script compiler and player in it .. so you
          cannot execute arbitrary strings as script. You can only use eval to look
          at a vaiable.

          But that still can help you with some re-writing. eg

          >> function selectState(stateCode){
          >> eval("_root." + stateCode + "_mc").gotoAndPlay(2);
          >> }

          nicer still would be

          >> function selectState(stateCode){
          >> _root[stateCode + "_mc"].gotoAndPlay(2);
          >> }
          --
          Jeckyl


          • 2. Re: eval() function
            S4Potential Level 1
            You can also call a function using the square brackets instead of eval

            function test(t:Number) {
            trace(t);
            }
            this["test"](123);
            • 3. Re: eval() function
              csthsl Level 1
              OH RIGHT ON! You two are the best! Saved my hide! Whew!

              Many thanks!