7 Replies Latest reply on Mar 29, 2007 8:05 PM by Newsgroup_User

    scriptInstanceList and object instance

    Level 7
      hello everyone

      Im having 2 problems with my code

      1 - when I add a parent script to the scriptinstance list of a sprite I
      find that the list does not show the instance of the behaviour attached to
      the sprite. therefore the behaviour is not working.

      The other problem is
      2 - I am creating an instance of a parent script in a beginSprite event. But
      when I type "put myObj" (where myObj is the variable holding the instance)
      in the message window it gives a VOID, which means the object is not
      available to the sprites.

      any help would be appreciated.

      ahmed
      ahmed


        • 1. Re: scriptInstanceList and object instance
          Level 7
          posting some code would help a lot


          --
          Craig Wollman
          Lingo Specialist
          Word of Mouth Productions
          212-928-9581

          www.wordofmouthpros.com
          "FotoArt" <FotoArt@theMaldives.com> wrote in message
          news:eu86gg$8f5$1@forums.macromedia.com...
          > hello everyone
          >
          > Im having 2 problems with my code
          >
          > 1 - when I add a parent script to the scriptinstance list of a sprite I
          > find that the list does not show the instance of the behaviour attached to
          > the sprite. therefore the behaviour is not working.
          >
          > The other problem is
          > 2 - I am creating an instance of a parent script in a beginSprite event.
          > But when I type "put myObj" (where myObj is the variable holding the
          > instance) in the message window it gives a VOID, which means the object is
          > not available to the sprites.
          >
          > any help would be appreciated.
          >
          > ahmed
          > ahmed
          >


          • 2. Re: scriptInstanceList and object instance
            Lukewig Level 1
            Hi,

            1. Objects go into the scriptinstancelist (instance objects, script objects etc) -- not script cast members. Scripts cast members can be attached to a sprite's scriptList, along with starting parameters. When you drag a behaviour (a kind of script castmember) on to a sprite, the script is added to the 'scriptlist'. You can also add parent scripts (you cannot drag them on to the sprite though, you have to use the setScriptList() lingo function). Scripts in the script list are automatically instantiated when the sprite is created. Its hard to tell from your description whether you are trying to add instances to the scriptinstancelist or scripts to the scriptlist.

            2. Assuming your code looks like this

            -- this is a script (eg a behaviour) on the sprite

            on beginSprite (me)
            myObj = script("Some Parent Script").new()
            put myObj
            end

            If this is what you are doing (and as Craig said - posting some code helps), and you are getting VOID immediately after instantiating your script, then one of the following might be causing the problem:

            a) Your parent script has an "on new" method that does not return a reference to the object. Eg

            on new (me)
            return me -- need to return 'me'
            end

            b) You have a movie script somewhere that defines an "on new" function. Movie script functions are 'global' and this will over-ride the built in new() function\.

            If myObj contains a reference to the object immediately after calling new(), but is void elsewhere in the script, then you will need to declare myObj to be a property.


            -- Luke



            • 3. Re: scriptInstanceList and object instance
              Level 7
              hello,

              I have 3 scripts, (they are very awkward)
              one parent,
              one movie
              and a behaviour

              myObj is Void and when I clicked a sprite its says handler not defined

              I have tried creating the myObj instance in a beginsprite handler attached
              to a sprite on the first frame.
              when that happens mouse clicks are ignored.

              =================parent SCR===========================================

              property myChannelList

              on new me
              findChannels
              addToScriptInstanceList
              return me
              end


              on mButtonClicked (me, btnName)
              alert (#"u clicked "& btnName)
              end



              on findChannels
              myChannelList = []
              repeat with i = 1 to the lastChannel
              if channel(i).name = "goForward" or channel(i).name = "goBackward" then
              myChannelList.add(i)
              end if
              end repeat
              end


              on addToScriptInstanceList me
              repeat with j in myChannelList
              sprite(j).scriptInstanceList.append(me)
              end repeat
              end

              =========Mpvie Scr========================
              property myObj
              on startMovie
              myObj = Script("myScript").new()
              put myObj
              end

              ========behaviour on two sprites===========
              on mouseUp(me)
              btnName = sprite(me.spriteNum).member.name
              call(#mButtonClicked, me, btnName )
              end
              ============================================
              any guidance will be appreciated
              thanx
              ahmed


              • 4. Re: scriptInstanceList and object instance
                Level 7
                I'm not entirely sure what's going on, but I don't think you can use
                properties in a movie script. Change the myObj declaration to a global
                and see if it works a little better.
                • 5. Re: scriptInstanceList and object instance
                  Level 7
                  hello everyone

                  Im trying to create a parent script containing two lists. So that I can
                  manage/share/access the lists via two sprites on the stage - a back button
                  and a forward button.

                  Hope someone could give me some ideas on this.
                  I have few problems like attaching the scriptInstanceList and passing
                  messages from mouse events to the Pscript.

                  Any help would be appreciated.
                  thanx
                  ahmed





                  • 6. scriptInstanceList and object instance
                    Lukewig Level 1
                    Hi,

                    Theres a couple of problems I can see:

                    1. The movie script.
                    Movie scripts can have properties. However, you don't want to declare it in your script. Director has some strange idiosyncratic ways of handling scope with movie script properties (which is the reason you get 'void' when you put myObject). If you delete the 'property myObject', your movie script will be fine. Note - you do not need to store a reference to the object you create in the movie script because an instance gets stored in the sprite scriptInstanceList. As long as you keep an instance to an object somewhere, the object will live.

                    2. The behaviour
                    The lingo line "call(#mButtonClicked, me, btnName )" will probably error since 'me' is an instance of the behaviour and the behaviour has no mButtonClicked method. Try changing it to

                    sendSprite(me.spriteNum, #mButtonClicked, btnName)

                    This sends the #mButtonMethod to all instances attached to the sprite. Alternatively, you could call the scriptInstanceList of the sprite (same effect) like this

                    call(#mButtonClicked, sprite(me.spriteNum).scriptInstanceList, btnName )


                    3. The Parent Script.
                    Should work - but as a rule, you should specify the scripts you are sending messages to. So, instead of writing this:

                    on new me
                    findChannels
                    addToScriptInstanceList
                    return me
                    end

                    consider writing

                    on new me
                    me.findChannels()
                    me.addToScriptInstanceList()
                    return me
                    end


                    Incidentally, it seems like a long convoluted approach. IS there any reason you just don't use a single behaviour?

                    -- Luke
                    • 7. Re: scriptInstanceList and object instance
                      Level 7
                      >
                      > Theres a couple of problems I can see:
                      >
                      In an attempt to keep grammar alive...

                      "There are a couple of problems..."

                      It might not be Lingo related other than the fact that it's the syntax of
                      speech.

                      Craig