10 Replies Latest reply on Mar 12, 2007 7:04 AM by Newsgroup_User

    ParentScript me and Mouse events

    Level 7
      hello everyone

      I have a parent script with several handlers and methods.
      I just dont know how to pass information from mouse events such as mouseUp
      mouseLeave to the parent script.

      Cud some one tell me how I could use the me parameter of both parent script
      and mouse event handlers in such situations.
      btw when do u have me parameter in a bracket.

      thanx
      ahmed


        • 1. Re: ParentScript me and Mouse events
          James Newton, ACP Level 3
          Several methods are possible. Here are a couple:

          1) Use "the mouseUpScript" and "the mouseDownScript" to send #mouseUp and #mouseDown events to your parent script, or ta a global pointer to an instance of the parent script. This will not work with #mouseLeave events

          2) Create a behavior which you drop on the sprites which need to send #mouseUp and #mouseLeave events to the parent script, and set the parent script as the ancestor to the behavior instances.
          • 2. Re: ParentScript me and Mouse events
            Level 7
            thanx openspark

            Is it possible for u to provide me a sample code for option 2.

            thanx
            ahmed


            • 3. ParentScript me and Mouse events
              James Newton, ACP Level 3
              -- In a Movie Script

              global gMouseManager

              on prepareMovie()
              gMouseManager = script("Mouse Manager").new()
              end


              -- In a Parent Script named "Mouse Manager"

              on new(me)
              return me
              end

              on mouseUp(me)
              vSprite = sprite(me.spriteNum)
              alert "#mouseUp received by "&vSprite -- or something more useful
              end

              on mouseEnter(me)
              vSprite = sprite(me.spriteNum)
              alert "#mouseEnter received by "&vSprite -- or something more useful
              end


              -- In a Behavior that you attach to a number of sprites
              global gMouseManager
              property ancestor

              on beginSprite(me)
              ancestor = gMouseManager
              end
              • 4. Re: ParentScript me and Mouse events
                Lukewig Level 1
                Hi

                Director will send mouseEvents to sprites and these mouseEvents then get passed on to all the objects in the scriptInstanceList of the sprite. So the simple answer to your question is change your parent script to a behavior and drag it on to a sprite at Authorime, or - at runtime - add the instances of your parent script to the sprite's scriptInstaneList: eg

                on new (me)
                sprite(1).scriptInstanceList.append(me)
                return me
                end

                Another approach (as James mentioned) is to set your parent scripts as an ancestor to a behaviour. In this case, any mouseEvents not handled by the behaviour will be passed on to the instances of your script. For example, you parent script might be like this

                on new (me)
                sendSprite(1, #SetAncestor, me)
                return me
                end

                Then you have a behaviour on the sprites like this

                property Ancestor
                on SetAncestor (me, obj)
                Ancestor = obj
                end


                Another approach is to have your parent scripts add themselves as 'listeners'. For example, you parent script might be like this

                on new (me)
                sendSprite(1, #AddListener, me)
                return me
                end

                Then you have a behaviour on the sprites like this

                property Listeners

                on AddListner (me, obj)
                if myListeners.ilk <> #list then myListeners = []
                myListeners.append(obj)
                end

                on mouseDown (me)
                call (#mouseDown, myListener)
                end

                -- Luke
                • 5. Re: ParentScript me and Mouse events
                  Level 7

                  thanx Luke

                  very loud and clear

                  ahmed


                  • 6. Re: ParentScript me and Mouse events
                    Level 7

                    thanx openspark
                    Its pretty clear now.
                    ahmed


                    • 7. Re: ParentScript me and Mouse events
                      Level 7
                      hello everyone

                      I have the following parent script and behaviours.
                      What they shud do is when I click a button give its name.
                      But I find that what comes up depends on the first of the two lines in the
                      New me handler. For instance if sprite (3) is the first line all the buttons
                      will give the name of the sprite(3). when I move the secondline up ie:
                      sprite (2).scriptInstanceList.append(me), all the buttons will give name of
                      sprite(2).

                      When clicked buttons shud give its name.

                      Any help will be appreciated.


                      ---PARENT SCRIPT--theoriginal-

                      on new (me)


                      sprite(3).scriptInstanceList.append(me)

                      sprite(2).scriptInstanceList.append(me)


                      return me

                      end

                      on mouseUp (me)

                      xxx = sprite(me.spriteNum).member.Name

                      alert"#you clicked"&xxx

                      end

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

                      --behaviour--

                      on beginSprite (me)

                      myObj = Script("theoriginal").new()


                      end


                      • 8. Re: ParentScript me and Mouse events
                        Level 7
                        Try doing it a little differently by sending a variable with the
                        spriteNum to the parent script when you call it... like this example. It
                        does notrequire you to hard code the sprite number in the parent, so you
                        can drag it onto whatever sprites you want, in whatever channels and it
                        will always work without having to change anything:

                        ---parent script "theoriginal"----

                        on new me,vSpriteNum

                        sprite(vSpriteNum).scriptInstanceList.append(me)

                        return me

                        end

                        on mouseUp (me)

                        xxx = sprite(me.spriteNum).member.Name

                        alert"#you clicked"&&xxx

                        end

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

                        ---sprite script on a sprite whose member MUST HAVE A NAME

                        on beginSprite (me)

                        myObj = Script("theoriginal").new(me.spriteNum)

                        end

                        ------------------
                        • 9. Re: ParentScript me and Mouse events
                          Level 7

                          thanx Mike
                          I wish there was a book on lingo that explain these OOP aspects.

                          ahmed


                          • 10. Re: ParentScript me and Mouse events
                            Level 7
                            Hello mike

                            the way u described it, each sprite wud be creating a new object, which
                            means each sprite is starting over.
                            That way, Im not able to share with others a variable used by any sprite.
                            Fore instance if I put something into a list by clicking a sprite Im not
                            able to delete that list by using another sprite.
                            Is there a way accompolishing this by using my script posted earlier.

                            thanx
                            ahmed