9 Replies Latest reply on Oct 23, 2006 4:08 AM by Laukvik

    Relatively urgent! Basic variables refreshing

    Laukvik
      hi... I have a co-worker that for some reason prefers to use Director:) He does not have the widest coding skills, but he has enough to get the work done and then some.

      I come from a coding background and work mostly with Flash, which could be good since director now accpets javascript syntax.

      Now, I just want to add a button, and attach a script to it (I have used director before, but its over 3 years ago, and I havent kept in touch..) This is fine.

      Now, I just want to add a variable in this button's behaviour, and when I try someVar=1, I get a very generic errormessage that I do not understand.

      So I, I have a button on sprite no 8, I just want to add a check for a variable in the code attached to it. And I'm not able to declare a varieble.......... help. help. help.... I do remeber something special about property inspector... but what I REALLY want is some way of just adding a variable directly in the sprite and do some checking, or do it like flash works, just add it on frame 1 in any layer, so I have global access... ( I can't find the equivalent of frame 1 in director...!!!! HELP.....!:)

      So, what I need is a basic walkthrough of just that - and believe me, I have been looking at the internet, and I do not seem to find enything worth while. I remember finding director kinda ok, but I bit cumbersome regarding variables... and it seems like I was correct.

      Anybody willing to correct me?? preferably so I can go back to work on sunday and do this thing... before monday.. I hate working right now....:( hehe
        • 1. Re: Relatively urgent! Basic variables refreshing
          Level 7
          Nothing like starting out with "for some resaon prefers to use Director"
          from a Flash person to get any of answers....Really sorry you have to use
          Director.

          "Laukvik" <webforumsuser@macromedia.com> wrote in message
          news:ehb5ba$3fh$1@forums.macromedia.com...
          > hi... I have a co-worker that for some reason prefers to use Director. He
          > does
          > not have the widest coding skills, but he has enough to get the work done
          > and
          > then some.
          >


          • 2. Relatively urgent! Basic variables refreshing
            Laukvik Level 1
            I was meerly trying to point out the fact that I am now in deep dodo. By all means, Director can be used very effectively, its just that what my co-worker is doing with it is not something he needs to use Director for. But I guess you can say the same about Flash vs Director as well...

            I have always found the way flash stores its variables and properties to be easier to understand from my point of view, and since all the tutorials I have seen the last 12 hours say little about this particular subject, I was hoping someone in here could help me.

            I just need to know where I can declare a local or global variable so I can read and write to it from a sprite, meaning I need a regular if statement on a button, checking the state of a variable beeing set from the get-go of the presentation.

            Thanks
            • 3. Re: Relatively urgent! Basic variables refreshing
              Level 7
              I'm nor really sure what it is you want, but:

              if you want to check or set a global var in a script on a button:
              write a behavior (just a script but make sure it's type is set to
              behavior in the property inspector) with something like this:

              -- declaration of a global variable
              global someVar

              on mouseUp me
              put someVar
              end

              If not previously been assigned a value it will put VOID in the message
              window. (Ctrl-M, like Flash's output window but it doesn't open
              automatically when you output to it)
              You can ofcourse give the var a value in for example the startMovie
              eventhandler in a movieScript (set it't type to movieScript in the
              property inspector):

              global someVar

              on startMovie
              someVar = "well, hello there"
              end

              Notice that you have to declare a global variable in eacht
              script-castmemebr that uses it.

              There is also property variables:

              property someVar

              on mouseUp me
              put me.someVar
              end

              but that variable exists only in the scope of that instance of the behavior.

              There is no equivalent of 'frame 1' in Director. If you vant to attach
              scripts to a button, the basic way to go is write a behavior and drag it
              onto the sprite.

              There's the script channel where you can place scripts, but using it to
              dynamically add scripts to a sprite is probably more than you bargained
              for...

              A good place to start with lingo is:

              http://www.fbe.unsw.edu.au/Learning/Director/

              I'm not familiar with any good Director tutorials on ECMA/JavaScript, sorry.

              hope this helps (somewhat)
              Manno

              Laukvik wrote:
              > hi... I have a co-worker that for some reason prefers to use Director. He does
              > not have the widest coding skills, but he has enough to get the work done and
              > then some.
              >
              > I come from a coding background and work mostly with Flash, which could be
              > good since director now accpets javascript syntax.
              >
              > Now, I just want to add a button, and attach a script to it (I have used
              > director before, but its over 3 years ago, and I havent kept in touch..) This
              > is fine.
              >
              > Now, I just want to add a variable in this button's behaviour, and when I try
              > someVar=1, I get a very generic errormessage that I do not understand.
              >
              > So I, I have a button on sprite no 8, I just want to add a check for a
              > variable in the code attached to it. And I'm not able to declare a
              > varieble.......... help. help. help.... I do remeber something special about
              > property inspector... but what I REALLY want is some way of just adding a
              > variable directly in the sprite and do some checking, or do it like flash
              > works, just add it on frame 1 in any layer, so I have global access... ( I
              > can't find the equivalent of frame 1 in director...!!!! HELP.....!:)
              >
              > So, what I need is a basic walkthrough of just that - and believe me, I have
              > been looking at the internet, and I do not seem to find enything worth while. I
              > remember finding director kinda ok, but I bit cumbersome regarding variables...
              > and it seems like I was correct.
              >
              > Anybody willing to correct me?? preferably so I can go back to work on sunday
              > and do this thing... before monday.. I hate working right now....:( hehe
              >

              --
              ----------
              Manno Bult
              manno@xs4all.nl
              • 4. Relatively urgent! Basic variables refreshing
                Laukvik Level 1
                Thanks! If I have understood you correctly, I believe this will work! This of course depends on if I do it right and nothing else is wrong:D

                But I think I got it, so I will write an update tomorrow when I go in for some sunday time work. Thanks again.
                • 5. Re: Relatively urgent! Basic variables refreshing
                  Level 7
                  Director is very different from Flash in terms of variable scope.
                  Director used three types of variable, local, property, and global. The
                  scope of these variables is also unique.

                  A local variable only holds it's value inside one function. A property
                  variable holds it's value in one behavior or parent script window. You
                  cannot declare a property variable in a movie script window. A global
                  variable holds it's value for the entire Director session, this means
                  that the variable is available to any number of movies. To use a global
                  variable, you have to declare it in any script window where you want to
                  use it's value. Global and property variables are declared outside of a
                  function, usually at the top of the script window where they will be
                  used. You do not assign a value to a global or property variable when
                  you declare it.

                  While the values of any property variable are private to the instance of
                  the behavior, you can read and write the value of a property variable
                  from outside the behavior.

                  For instance if you have a property variable declared in one behavior,
                  let's call it "myPropVar". You can then get or set the value of that
                  property variable from another behavior like this:

                  sprite(X).myPropVar = 17

                  You just need to relate the property variable to the sprite that it is
                  attached to.

                  You can use global variables to achieve the same thing.

                  --
                  Rob
                  _______
                  Rob Dillon
                  Adobe Community Expert
                  http://www.ddg-designs.com
                  412-243-9119

                  http://www.macromedia.com/software/trial/
                  • 6. Re: Relatively urgent! Basic variables refreshing
                    Laukvik Level 1
                    Thanks guys! It works now. The strange thing, that got me panicking in the first place is that it seems I can't assign my variable any value outside of a function. If I do, I get an error message (Handler definition expected).

                    So what I did was just declare a Global variable, and check if it is NOT 1, then assign any value etc etc etc. As long as I can catch it, I can use it.

                    I do not get this, so if you guys have an explenation, that would be helpful, but at least the code is working!:)
                    • 7. Relatively urgent! Basic variables refreshing
                      Laukvik Level 1
                      (repost - removed by me)
                      • 8. Re: Relatively urgent! Basic variables refreshing
                        duckets Level 1
                        quote:

                        Originally posted by: Laukvik
                        it seems I can't assign my variable any value outside of a function
                        <snip>
                        I do not get this, so if you guys have an explenation, that would be helpful


                        Hi Laukvik.

                        The reason you can't assign a variable outside of a function, is because that line of code which assigns the variable is a line of code which needs to be executed at a certain time. All code in director must be inside a function (or 'handler') which indicates when it should be executed.

                        Here's an example of a behaviour script which initialises and increments a counter, and outputs the counter value to the text member on which the behaviour is placed. (It assumes it is placed on a text member):

                        Javascript Version:

                        var myNum;
                        var myTextMem;

                        function beginsprite(me) {
                        myNum = 0;
                        myTextMem = sprite(me.spritenum).member;
                        myTextMem.text = "click me!";
                        }

                        function mouseUp(me) {
                        myNum += 1;
                        myTextMem.text = myNum.toString();
                        }

                        ---------------------------------------------------------------

                        Lingo Version:


                        property myNum
                        property myTextMem

                        on beginsprite me
                        myNum = 0
                        myTextMem = sprite(me.spritenum).member
                        myTextMem.text = "click me!"
                        end

                        on mouseUp me
                        myNum = myNum + 1
                        myTextMem.text = string(myNum)
                        end

                        -----------------------------------------------------

                        (sorry for the lack of indentation - this forum removes it)
                        There's 3 clear sections in the behaviour, the property declarations, the 'beginsprite' handler (which is called once, as the playback head encounters the sprite for the first time), and the 'mouseUp' handler (which is called each time the sprite is clicked).

                        The behaviour uses 'property' variables, which means that the values are local in scope to each instance of the behaviour. They persist through all the handlers/functions of the behaviour, but they are not shared between instances of the behaviour. This means each time you re-use a behaviour (eg, if you apply the same behaviour to many sprites), each behaviour has its own unique instances of the properties declared in the behaviour. A behaviour is like a 'class' and each time a behaviour is used on a sprite, you create an instance of that class. So in the case of the behaviour above, if you created multiple text fields and placed them on stage, then dragged this behaviour on to each of them, each sprite would maintain its own separate click counter.

                        Hope this helps to clarify what goes on in the crazy bizarro world of director! (which, incidentally, is how flash first appears to director users!)

                        - Ben










                        • 9. Re: Relatively urgent! Basic variables refreshing
                          Laukvik Level 1
                          aaaaaaaaaaaaaaaaaaaaaaaaaaha!

                          Yes! It all comes back to me now.. sort of:D You can't do anything outside a function or handler! Thats what I didn't get, and since I couldn't remember any other handler than onexitframe, I didn't want to set my variable inside this.. as you might understand, its very little point in a variable that resets every frame....

                          Thank you all - most informative.

                          P.S. I am sure Flash looks craaaazy from Director point of view, but, I believe its more akin to most other programing conventions regarding variables and such. But as in any tool, as soon as you understands the rules, they are all kinda the same:D

                          Thanks!