2 Replies Latest reply on Nov 1, 2007 2:21 AM by Windy_Morgs

    Help - this must be simple!

      I'm tying to create a 'calculator' where the end user enters numeric values into 3 fields (gas, electricity and phone) then those values are added together and the answer automatically appears in a fourth field entitled 'total'. Seems easy but I am banging my head against a wall. Do I apply lingo to the field? What is the lngo? Aaaargh!

      Also, I need to add a print button. When pressed, an Adobe PDF file entitles 'form' is accessed from the same CD and printed, with or without opening first. The Director project will be saved as a Projector file.
      Thanks a million if you can help x
        • 1. Help - this must be simple!
          Chunick Level 3
          lingo can be placed in movie scripts (that act on the whole movie), parent scripts (that can be initialized by other scripts), behavior scripts (that are placed on sprites), frame scripts (that are placed in the frame script channel on the score), and the less used cast member script (which can be applied directly to members in casts using the 'cast member script' button). There are only three types of script members, #movie, #parent, #behavior. A frame script is really just a #behavior script that is triggered when the score playhead enters the frame in which the script starts. I've never really been sure what a cast member script is, but I suspect it may be a throwback to earlier versions of Director and as such, isn't used much anymore.

          As for what you want to do, think of lingo in Director as event based. You have all these graphics on the stage and it's easy enough to set up tweening to move them around, make them larger, etc.... that's all built into Director and that shows action, but it's not really interactive... I can't click on a sprite to stop it from moving, for instance... Hey! Well, there's an action - 'CLICK'. Remember, I said that Director is event based. Clicking a sprite on the stage is an event.

          But how do you code that event? The easiest method is to select a sprite that you want to add a click event to - such as a button, go to the behavior tab in the property inspector (on the right) and click on the '+' icon then select 'New Behavior...' Name it 'button click script' and click 'Ok'... now it's in the scripts list as a new behavior attached to that sprite... it also shows in the cast as a script member (if you're using the thumbnail view then you'll also see a little yellow cog wheel in the bottom-right of the member thumbnail which indicates it's a behavior script). Now, in order to add lingo code to the behavior object we're going to use the property inspector some more. The behavior tab should still be open and you should still see your new behavior script in the list. Click on it to hilite and then click the script icon just above it to open up the 'script window'. Now you can type some lingo. Functions in Director are called Handlers... the built-in handlers are all event-based, on mouseUp, on mouseDown, on enterFrame, on exitFrame, on activateWindow, etc. Here's some code you might use for your example:

          -- assuming the text members are labelled "gas", "electricity", "phone" and "total"
          -- and that we're attaching the script to a button
          on mouseUp me
          -- convert the text members from strings to number values
          gas = value(member("gas").text)
          electricity = value(member("electricity").text)
          phone = value(member("phone").text)
          -- calculate the total
          total = gas + electricity + phone
          -- set the total to a text/field member
          -- by converting to a string
          member("total").text = string(total)
          • 2. Re: Help - this must be simple!
            Windy_Morgs Level 1
            Many thanks for this, it really helped me out.