20 Replies Latest reply on Feb 17, 2009 7:15 PM by Newsgroup_User

    Handler not defined error message

    mikem75 Level 1
      Hello - I'm having difficulty with a custom handler I've created. Everything works well in authoring mode, but as soon as I try to create a projector and run it, I get a "Handler not defined" error message. The handler is used to query an sqlite database. Here's the code which sits in a linked cast movie script


      on startmovie
      set gDBInstance = new(xtra"sqlite")

      on mDBQuery gSqlstring

      gDBInstance.sqlite_open(the moviepath&"halloffame.db")
      gQuery_fetch_data = gDBInstance.sqlite_fetch(gSqlstring)
      gDBInstance.sqlite_close()

      end

      end startmovie

      The handler is called from a frame script as below:

      on enterframe

      gSqlstring = "SELECT file_location FROM mediaitem NATURAL JOIN category WHERE category = 'Equipment' ORDER BY mediaitem.name ASC"
      mDBQuery(gSqlstring)

      end enterframe

      I'm using Director 11 on Windows XP. I do have all of the sqlite xtras in an xtras folder next to the executable. Any thoughts on what I'm doing wrong??

      THX!

      Mike M

        • 1. Re: Handler not defined error message
          Level 7
          Usually when you get that error message, it will also specify the label that
          is not defined. Can you post that?

          --
          Craig
          "mikem75" <webforumsuser@macromedia.com> wrote in message
          news:gn9ig3$3jb$1@forums.macromedia.com...
          > Hello - I'm having difficulty with a custom handler I've created.
          > Everything
          > works well in authoring mode, but as soon as I try to create a projector
          > and
          > run it, I get a "Handler not defined" error message. The handler is used
          > to
          > query an sqlite database. Here's the code which sits in a linked cast
          > movie
          > script
          >
          >
          > on startmovie
          > set gDBInstance = new(xtra"sqlite")
          >
          > on mDBQuery gSqlstring
          >
          > gDBInstance.sqlite_open(the moviepath&"halloffame.db")
          > gQuery_fetch_data = gDBInstance.sqlite_fetch(gSqlstring)
          > gDBInstance.sqlite_close()
          >
          > end
          >
          > end startmovie
          >
          > The handler is called from a frame script as below:
          >
          > on enterframe
          >
          > gSqlstring = "SELECT file_location FROM mediaitem NATURAL JOIN category
          > WHERE category = 'Equipment' ORDER BY mediaitem.name ASC"
          > mDBQuery(gSqlstring)
          >
          > end enterframe
          >
          > I'm using Director 11 on Windows XP. I do have all of the sqlite xtras in
          > an
          > xtras folder next to the executable. Any thoughts on what I'm doing
          > wrong??
          >
          > THX!
          >
          > Mike M
          >
          >
          >


          • 2. Re: Handler not defined error message
            Level 7
            It's probably because you have

            end

            and

            end startMovie

            You only need one end per handler and the handler name is optional so you
            can get rid of either one.

            --
            Craig

            "mikem75" <webforumsuser@macromedia.com> wrote in message
            news:gn9ig3$3jb$1@forums.macromedia.com...
            > Hello - I'm having difficulty with a custom handler I've created.
            > Everything
            > works well in authoring mode, but as soon as I try to create a projector
            > and
            > run it, I get a "Handler not defined" error message. The handler is used
            > to
            > query an sqlite database. Here's the code which sits in a linked cast
            > movie
            > script
            >
            >
            > on startmovie
            > set gDBInstance = new(xtra"sqlite")
            >
            > on mDBQuery gSqlstring
            >
            > gDBInstance.sqlite_open(the moviepath&"halloffame.db")
            > gQuery_fetch_data = gDBInstance.sqlite_fetch(gSqlstring)
            > gDBInstance.sqlite_close()
            >
            > end
            >
            > end startmovie
            >
            > The handler is called from a frame script as below:
            >
            > on enterframe
            >
            > gSqlstring = "SELECT file_location FROM mediaitem NATURAL JOIN category
            > WHERE category = 'Equipment' ORDER BY mediaitem.name ASC"
            > mDBQuery(gSqlstring)
            >
            > end enterframe
            >
            > I'm using Director 11 on Windows XP. I do have all of the sqlite xtras in
            > an
            > xtras folder next to the executable. Any thoughts on what I'm doing
            > wrong??
            >
            > THX!
            >
            > Mike M
            >
            >
            >


            • 3. Re: Handler not defined error message
              Level 7
              Now I see more detail. Your end startMovie was misplaced when you created
              your other handlers. Move that before "on mDBQuery

              Why this doesn't give you an error in authoring is beyond me.


              --
              Craig

              "mikem75" <webforumsuser@macromedia.com> wrote in message
              news:gn9ig3$3jb$1@forums.macromedia.com...
              > Hello - I'm having difficulty with a custom handler I've created.
              > Everything
              > works well in authoring mode, but as soon as I try to create a projector
              > and
              > run it, I get a "Handler not defined" error message. The handler is used
              > to
              > query an sqlite database. Here's the code which sits in a linked cast
              > movie
              > script
              >
              >
              > on startmovie
              > set gDBInstance = new(xtra"sqlite")
              >
              > on mDBQuery gSqlstring
              >
              > gDBInstance.sqlite_open(the moviepath&"halloffame.db")
              > gQuery_fetch_data = gDBInstance.sqlite_fetch(gSqlstring)
              > gDBInstance.sqlite_close()
              >
              > end
              >
              > end startmovie
              >
              > The handler is called from a frame script as below:
              >
              > on enterframe
              >
              > gSqlstring = "SELECT file_location FROM mediaitem NATURAL JOIN category
              > WHERE category = 'Equipment' ORDER BY mediaitem.name ASC"
              > mDBQuery(gSqlstring)
              >
              > end enterframe
              >
              > I'm using Director 11 on Windows XP. I do have all of the sqlite xtras in
              > an
              > xtras folder next to the executable. Any thoughts on what I'm doing
              > wrong??
              >
              > THX!
              >
              > Mike M
              >
              >
              >


              • 4. Re: Handler not defined error message
                Cherax79 Level 1
                Maybe try to move out your handler from the startMovie handler, like this:

                • 5. Re: Handler not defined error message
                  mikem75 Level 1
                  Thanks all - I've tried putting the custom handler inside and outside of the "start movie" handler to no avail. The error message I get is "Handler not defined #mDBQuery Script error. Continue? " and yes/no buttons. Not sure why the "#" is added to the handler name.

                  Do I need to identify mDBQuery as a global variable? I've done that.

                  I had tried to put it inside the start movie handler on the assumption that perhaps it was not defined before I had attemped to use it. I'm trying to call it right away in a score script. I've moved the score script to later in the movie with no luck as well.

                  The score script should "see" the handler defined in the movie script .... not?

                  Mike M
                  • 6. Re: Handler not defined error message
                    Level 7
                    > The score script should "see" the handler defined in the movie script .... not?

                    Yes, unless your behavior script is running in a different window, or
                    your #movie script isn't a #movie script

                    • 7. Re: Handler not defined error message
                      mikem75 Level 1
                      Thanks Sean - Everything is running in the same window and the movie script is indeed a movie script.

                      Now, when I copy the movie script from the external linked cast and put it into the internal cast all is well! No errors and everything works fine .... except I really need it to be in an external cast so it can be called by multiple movies. Could it be the score script can't see the handler defined in a movie script when the movie script is stored in an external linked cast?

                      If that's the case, any other way I could work around that?

                      Mike M
                      • 8. Re: Handler not defined error message
                        Level 7
                        > Now, when I copy the movie script from the external linked cast and put it
                        > into the internal cast all is well!

                        Select the external castLib (make its window active), open the Property
                        Inspector and activate its 'Cast' tab. Change the 'Preload' drop-down
                        from 'When Needed' to 'Before Frame One'
                        • 9. Re: Handler not defined error message
                          mikem75 Level 1
                          Thanks for all the help Sean. I tried to adjust the preload of the external cast as you described, but I still get the same error. Thinking it might be an issue with the sqlite xtra I tried the Arca database xtra as well (both work with sqlite databases). Exactly the same scenario happens. When the movie script is in the internal cast things work fine. Move it to an external, linked cast and "Handler not defined" error comes up again. But it only happens when I create a projector. Everything works fine during authoring. I've confirmed again, that I have the xtra in an xtras folder beside the app. I've tried adding the xtra to the projector as well, but the same thing happens

                          I've taken the project down to bare bones to try and test this. I'm basically initiating the xtra, opening the database, doing a small "SELECT" and then closing the database. It seems as if the score script cannot see the handler if its in a external cast.

                          MIke M
                          • 10. Re: Handler not defined error message
                            Level 7
                            It's nothing to do with the xtra) - the error message tells you it can't
                            find your named handler #mDBQuery much less run any code it contains. If
                            it were an xtra problem then the line:
                            set gDBInstance = new(xtra"sqlite")
                            would also be throwing an error (although, if it's in the same external
                            castLib, it may not be running either).

                            First ensure that the cast is linked at runtime as expected, then make
                            sure the handler is available when required (try various 'preload'
                            options, and check the #handlers property of your named #movie script
                            prior to calling its #mDBQuery method). That is:
                            --
                            on enterframe

                            gSqlstring = "SELECT file_location FROM mediaitem NATURAL JOIN\
                            category WHERE category = 'Equipment' ORDER BY mediaitem.name ASC"
                            -- substitute "movie script name" below with the
                            -- name of your #movie script
                            tScript = script("movie script name")
                            if ilk(tScript, #member) = 0 then
                            alert "Named movie script not found (not linked or loaded?)"
                            -- substitute index for the name or number
                            -- of your linked external castLib
                            alert castLib(index).filename
                            exit
                            end if
                            lHandlers = tScript.handlers()
                            alert string(lHandlers)
                            if lHandlers.getPos(#mDBQuery) then
                            mDBQuery(gSqlstring)
                            else
                            alert "Handler not found in script"
                            end if

                            end enterframe
                            • 11. Re: Handler not defined error message
                              mikem75 Level 1
                              Sean - looks like you are correct. The handler is not being found. Here's the script in my score script: (I rem'd out the 'exit' to run all of the checking lines)

                              on enterframe
                              tScript = script("init")
                              if ilk(tScript, #member) = 0 then
                              alert "Named movie script not found (not linked or loaded?)"
                              alert castLib(2).filename
                              -- exit
                              end if

                              gSqlstring = "SELECT file_location FROM mediaitem NATURAL JOIN category WHERE category = 'Equipment' ORDER BY mediaitem.name ASC"
                              -- mDBQuery(gSqlstring)

                              lHandlers = tScript.handlers()
                              alert string(lHandlers)
                              if lHandlers.getPos(#mDBQuery) then
                              mDBQuery(gSqlstring)
                              else
                              alert "Handler not found in script"
                              end if
                              end

                              In authoring mode I get: (OK buttons in between messages)

                              1. "Named movie script not found (linked or loaded)?
                              2. pathname to my movie script and its name
                              3. #preparemovie, #stopmovie, #mDBQuery

                              When I publish I get:

                              1. "Script cast member not found "init" Script error continue?" yes or no buttons.


                              I've tried all three possibilities on the cast preload option. Each option gives the same results as above. Don't understand why the handler is not being found??

                              Mike M

                              • 12. Re: Handler not defined error message
                                Level 7
                                A simple thought. Are you including the linked cast in your projector, or
                                if you're using a stub projector, is the cast in the same location
                                structurally as it is in authoring mode?


                                --
                                Craig

                                "mikem75" <webforumsuser@macromedia.com> wrote in message
                                news:gnb1a2$qo6$1@forums.macromedia.com...
                                > Sean - looks like you are correct. The handler is not being found.
                                > Here's the
                                > script in my score script: (I rem'd out the 'exit' to run all of the
                                > checking
                                > lines)
                                >
                                > on enterframe
                                > tScript = script("init")
                                > if ilk(tScript, #member) = 0 then
                                > alert "Named movie script not found (not linked or loaded?)"
                                > alert castLib(2).filename
                                > -- exit
                                > end if
                                >
                                > gSqlstring = "SELECT file_location FROM mediaitem NATURAL JOIN category
                                > WHERE category = 'Equipment' ORDER BY mediaitem.name ASC"
                                > -- mDBQuery(gSqlstring)
                                >
                                > lHandlers = tScript.handlers()
                                > alert string(lHandlers)
                                > if lHandlers.getPos(#mDBQuery) then
                                > mDBQuery(gSqlstring)
                                > else
                                > alert "Handler not found in script"
                                > end if
                                > end
                                >
                                > In authoring mode I get: (OK buttons in between messages)
                                >
                                > 1. "Named movie script not found (linked or loaded)?
                                > 2. pathname to my movie script and its name
                                > 3. #preparemovie, #stopmovie, #mDBQuery
                                >
                                > When I publish I get:
                                >
                                > 1. "Script cast member not found "init" Script error continue?" yes or no
                                > buttons.
                                >
                                >
                                > I've tried all three possibilities on the cast preload option. Each
                                > option
                                > gives the same results as above. Don't understand why the handler is not
                                > being
                                > found??
                                >
                                > Mike M
                                >
                                >
                                >


                                • 13. Re: Handler not defined error message
                                  Level 7
                                  You can also try this in your startMovie code

                                  cnt = the number of castLibs
                                  castList = []
                                  repeat with x = 1 to cnt
                                  castList.add (castLib (x).name)
                                  end repeat
                                  alert "Castlist is " & castList

                                  Of course, you probably know what you'll find...that the castLib where that
                                  code is will not be listed.

                                  --
                                  Craig

                                  "mikem75" <webforumsuser@macromedia.com> wrote in message
                                  news:gnb1a2$qo6$1@forums.macromedia.com...
                                  > Sean - looks like you are correct. The handler is not being found.
                                  > Here's the
                                  > script in my score script: (I rem'd out the 'exit' to run all of the
                                  > checking
                                  > lines)
                                  >
                                  > on enterframe
                                  > tScript = script("init")
                                  > if ilk(tScript, #member) = 0 then
                                  > alert "Named movie script not found (not linked or loaded?)"
                                  > alert castLib(2).filename
                                  > -- exit
                                  > end if
                                  >
                                  > gSqlstring = "SELECT file_location FROM mediaitem NATURAL JOIN category
                                  > WHERE category = 'Equipment' ORDER BY mediaitem.name ASC"
                                  > -- mDBQuery(gSqlstring)
                                  >
                                  > lHandlers = tScript.handlers()
                                  > alert string(lHandlers)
                                  > if lHandlers.getPos(#mDBQuery) then
                                  > mDBQuery(gSqlstring)
                                  > else
                                  > alert "Handler not found in script"
                                  > end if
                                  > end
                                  >
                                  > In authoring mode I get: (OK buttons in between messages)
                                  >
                                  > 1. "Named movie script not found (linked or loaded)?
                                  > 2. pathname to my movie script and its name
                                  > 3. #preparemovie, #stopmovie, #mDBQuery
                                  >
                                  > When I publish I get:
                                  >
                                  > 1. "Script cast member not found "init" Script error continue?" yes or no
                                  > buttons.
                                  >
                                  >
                                  > I've tried all three possibilities on the cast preload option. Each
                                  > option
                                  > gives the same results as above. Don't understand why the handler is not
                                  > being
                                  > found??
                                  >
                                  > Mike M
                                  >
                                  >
                                  >


                                  • 14. Re: Handler not defined error message
                                    Production Monkey Level 3
                                    I ran a couple test that were interesting, but first I need to address some bad coding practices.

                                    miken75,

                                    I see no reason to open and close a database with each query. Open it at the beginning of the program and close it at the end.

                                    You should always check for errors with every interaction with a database, including opening it.

                                    In your function "mDBQuery " you pass in a variable called "gSqlstring" and assign the returned data from the query to "gQuery_fetch_data". Neither one of these variables should be a Global. The whole point of the function is to pass in a temporary string and the function Returns query results. Do not use Globals in this situation.

                                    This is a bit nit-picky, but your function names should be verbs - some sort of action. "mDBQuery " is a noun. Something like queryDatabase, doQuery, fetchData, etc. would be better.

                                    A basic re-write of your startup code would be:

                                    global gDB

                                    on prepareMovie
                                    gDB = new(xtra"sqlite")
                                    Okay = gDB.sqlite_open(the moviepath&"halloffame.db")
                                    if Not Okay then
                                    alert("There was an error opening the Database")
                                    end if
                                    end prepareMovie

                                    on queryDB SqlString
                                    return gDB.sqlite_fetch(SqlString)
                                    end queryDB

                                    on stopMovie
                                    gDB.sqlite_close()
                                    end stopMovie
                                    -------------------------------------------------------

                                    Finally, "EnterFrame" is a really poor choice for an event that queries a database. "EnterFrame" is used when you need to do something many times a second, such as an animation. For a singular event like querying a database I suggest "prepareMovie", "startMovie", "beginSprite", "mouseDown", and "mouseUp".

                                    I'm just trying to improve your coding practices. Better code, means less bugs and going home early.

                                    To your problem:

                                    I tried a couple things. I placed some startup code and a function in an internal cast movie script and an "enterframe" behavior that calls the function in an external cast. I saved and published, and the executable comes up and gives the handler not defined error. This error is a Director thing. It has nothing to do with your code.

                                    If, however, you shut Director down and run the executable, then there is no error. This fact implies that when you try to run Director and the executable at the same time, then Director all ready has ownership of the external cast file and the executable therefore can not open it. Although, generally under that kind of circumstance you get an error message indicating that the file is in use by a different program. So, I don't know exactly what is happening here.

                                    I then moved the "startup" code into the external cast with the "enterframe" script and published. No error. Director and the executable run side by side just fine. Weird.

                                    Hope that helps.

                                    Randal.
                                    • 15. Re: Handler not defined error message
                                      mikem75 Level 1
                                      Production Monkey - thanks for the help! That did solve the problem. Director holds ownership of the external cast when its open. When I close Director and run the executable everything seems to be OK.

                                      I appreciate your comments on the coding as well. I will take your advise.

                                      Thank you everyone for your assistance. Its great to have this resource to draw from.

                                      MikeM75
                                      Text
                                      • 16. Re: Handler not defined error message
                                        Level 7
                                        Mike,

                                        It wasn't clear from your last post what solved the problem. I'm curious,
                                        what did you do differently?

                                        Craig


                                        --

                                        "mikem75" <webforumsuser@macromedia.com> wrote in message
                                        news:gndaui$pfs$1@forums.macromedia.com...
                                        > Production Monkey - thanks for the help! That did solve the problem.
                                        > Director
                                        > holds ownership of the external cast when its open. When I close Director
                                        > and
                                        > run the executable everything seems to be OK.
                                        >
                                        > I appreciate your comments on the coding as well. I will take your
                                        > advise.
                                        >
                                        > Thank you everyone for your assistance. Its great to have this resource
                                        > to
                                        > draw from.
                                        >
                                        > MikeM75
                                        > Text
                                        >


                                        • 17. Re: Handler not defined error message
                                          Level 7
                                          > It wasn't clear from your last post what solved the problem. I'm curious,
                                          > what did you do differently?

                                          Closed Director - or the file it had open - which had the external
                                          castLib open
                                          • 18. Re: Handler not defined error message
                                            Level 7
                                            ah, yes. But that's strange unless JUST the external cast was open. I
                                            suppose that must have been it.

                                            But even so Sean, wouldn't he have gotten that typical error message when
                                            the projector is first opened...not a "handler not defined" error but the
                                            file not found error? When I have my .dir file open that my stub accesses,
                                            of course, I get those two error dialogs then the file open dialog so I can
                                            point to a file I want to open. Wouldn't that same thing happen rather than
                                            getting a script error "handler not defined?"



                                            --
                                            Craig

                                            "Sean Wilson" <webforumsuser@macromedia.com> wrote in message
                                            news:gnf16f$r1$2@forums.macromedia.com...
                                            >> It wasn't clear from your last post what solved the problem. I'm
                                            >> curious, what did you do differently?
                                            >
                                            > Closed Director - or the file it had open - which had the external castLib
                                            > open


                                            • 19. Re: Handler not defined error message
                                              Level 7
                                              > ah, yes. But that's strange unless JUST the external cast was open. I
                                              > suppose that must have been it.
                                              >
                                              > But even so Sean, wouldn't he have gotten that typical error message when
                                              > the projector is first opened...not a "handler not defined" error but the
                                              > file not found error? When I have my .dir file open that my stub accesses,
                                              > of course, I get those two error dialogs then the file open dialog so I can
                                              > point to a file I want to open. Wouldn't that same thing happen rather than
                                              > getting a script error "handler not defined?"

                                              I agree, but FWIW that's what I took from his explanation
                                              • 20. Re: Handler not defined error message
                                                Level 7
                                                Yeah, he's probably moved on and not even seeing this

                                                --
                                                Craig

                                                "Sean Wilson" <webforumsuser@macromedia.com> wrote in message
                                                news:gnfp7n$sj7$1@forums.macromedia.com...
                                                >> ah, yes. But that's strange unless JUST the external cast was open. I
                                                >> suppose that must have been it.
                                                >>
                                                >> But even so Sean, wouldn't he have gotten that typical error message when
                                                >> the projector is first opened...not a "handler not defined" error but the
                                                >> file not found error? When I have my .dir file open that my stub
                                                >> accesses, of course, I get those two error dialogs then the file open
                                                >> dialog so I can point to a file I want to open. Wouldn't that same thing
                                                >> happen rather than getting a script error "handler not defined?"
                                                >
                                                > I agree, but FWIW that's what I took from his explanation