5 Replies Latest reply on Jul 25, 2006 5:29 AM by JustStupid

    Easy method call problem

    JustStupid
      Hi,

      Does anyone know how to call a certain method in a parent script from a behaviour script? Have a method called startit but when it I compile it says its the handler is not found.

      Cheers,

      Brenden


        • 1. Re: Easy method call problem
          Level 7
          Have you instantiated the object? If so, where is it stored. If it's
          stored in a global variable you can call the method using dot syntax

          globalVariableName.startit ()

          If you store it in a sprite's behavior's property it could be called this
          way from outside of that behavior

          sprite (someSpriteNumber).somePropertyName.startit ()

          There are various other ways but most Lingo user's I know store a child
          object in a global variable.
          --
          Craig Wollman
          Word of Mouth Productions

          phone 212 928 9581
          fax 212 928 9582
          159-00 Riverside Drive West #5H-70
          NY, NY 10032
          www.wordofmouthpros.com


          "JustStupid" <webforumsuser@macromedia.com> wrote in message
          news:ea4o9p$fp5$1@forums.macromedia.com...
          > Hi,
          >
          > Does anyone know how to call a certain method in a parent script from a
          > behaviour script? Have a method called startit but when it I compile it
          > says
          > its the handler is not found.
          >
          > Cheers,
          >
          > Brenden
          >
          >
          >
          >


          • 2. Re: Easy method call problem
            JustStupid Level 1
            Hi Craig,

            Thanks for the quick reply, yeah I think I have set the object (sorry to sound
            so dumb but just getting to grip with director). I have used the following code:

            Global beginConn
            beginConn = new(member("beginscript").script)
            beginConn.startit()

            The method I want to access:

            on startit me

            checker = timeout("looker").new(10000, #looker, me)

            end

            Which seems to work however I converted the handler script to a parent script from a movie script, to try and solve the problem of calling instances of its self (me) on the timeout script. As the target instance is not being found now even if I have converted to a parent script. Seems very strange!
            • 3. Re: Easy method call problem
              Lukewig Level 1
              Hi,

              > beginConn = new(member("beginscript").script)

              A more common way of doing this is with this syntax:

              beginConn = script("beginscript").new()

              > As the target instance is not being found now even if I have converted
              > to a parent script. Seems very strange!

              An object is an object regardless of the script type that made it (the reason why behaviours and parent scripts are generally better suited for making objects is that they have a 'protect scope' - if you call a handler without specifying the 'object' with that handler, then Director looks in all movie scripts for that handler; it wont attempt to call the handler or method defined in a parent script or behaviour unless you specify that script or an instance of that script ).

              > beginConn.startit()
              ..
              > on startit me
              > checker = timeout("looker").new(10000, #looker, me)
              > end

              Assuming 'beginConn' contains a reference to an instance of the script containing the 'startit' method, then your code looks fine (unless you are using DirectorMX2004, in which case it should be checker = timeout().new("looker", 10000, #looker, me)).

              Put a debug line in just before you create the timeout, and see what 'me' points to. eg.

              on startit me
              put "#startIt message received by " & me
              checker = timeout("looker").new(10000, #looker, me)
              end

              on looker (me, timeoutObject)
              put "#looker message sent by " & timeoutObject & " was received by " & me
              end

              -- Luke





              • 4. Re: Easy method call problem
                JustStupid Level 1
                Thanks Luke. I will try that out. Didn't know the sytnax for creating a timeout object was different for mx 2004 either. hehe
                • 5. Re: Easy method call problem
                  JustStupid Level 1
                  Wicked worked first time! All that time spend and solved so quickly.