4 Replies Latest reply on Jan 14, 2009 11:56 PM by Steveorevo

    calling lingo function from javascript

    gungupta
      hi,
      I want to invoke a director lingo function from a javascript. Can anybody help me in this? I got the solution for invoking javascript function from director, now i want to make other way around.
      Kindly help in this.
      Thank you
        • 1. Re: calling lingo function from javascript
          adam@blueapplestudio Level 1
          This thread is pretty old, but this is exactly what I am trying to do as well.

          I am using Lingo to perform some 3D operations when I can't find the JavaScript alternative, but the majority of my game is written in JavaScript. I would like to encapsulate the Lingo operations into functions and then call them from JavaScript. Could someone post a simple example or point me in the right direction?

          Thanks.
          • 2. Re: calling lingo function from javascript
            Level 7
            In a Javascript function, you can call any Lingo function just like you
            would from Lingo, but with a semicolon at the end.

            --Lingo moviescript--
            on doSomething me
            put "this is a Lingo command"
            end
            --


            --JS movieScript--
            function JSTest(){
            doSomething();
            }
            ---

            When you call the JSTest() function, it will run the doSomething()
            handler which will put some text into the message window.
            • 3. Re: calling lingo function from javascript
              adam@blueapplestudio Level 1
              Mike Blaustein

              Thank you very much for the response. I had a variable scope problem making this more challenging than it should have been.

              Works like a charm now.
              • 4. Re: calling lingo function from javascript
                Steveorevo Level 1
                There are some functions in Lingo that I simply can't find the Javascript equivilent for (like 'the platform' to determine the Operating System your application is running on). In these cases, it’s often handy to have a global Lingo function that returns results back to Javascript. Here is the recipe:

                1) Create a Lingo global method like so:

                on evalLingo sCode
                -- This opens the legacy Lingo interpreter
                -- to be invoked by Javascript and returns
                -- the results to Javascript.
                return do("return " & sCode)
                end


                2) Now you can use the generic lingo function from Javascript. The following displays the platform information in an alert box when the movie starts (coded in Javascript):

                function startMovie(){
                result = evalLingo("the platform");
                _player.alert(result);
                }

                Enjoy!