2 Replies Latest reply on May 3, 2014 9:57 AM by Rod@FOF

    Problem with Script Using New() to Create a #Vectorshape

    Rod@FOF Level 1



      I am having a problem integrating an existing movie script into a movie I am building and I can't figure out why.


      The single movie script, developed by JC in 2004,  appears below. It works perfectly in a movie all by itself. But I need to integrate it into an existing movie in which other sprites and behaviors must coexist.


      The problem I am seeing is that gMem is created with the new command (can see it in the message window using put gMem), but it will not allow attachment of gMem.regPoint, gMem.centerRegPoint, and so on. These all return errors.


      I would also be open to another solution to the problem. What I need to do is create rectangles that represent a plan view of a rooftop on an underlying grid and then be able to drag and place other images on it (it is for training purposes, not a game).


      I am using MX2004 on a PC. Any help, deeply appreciated.


      Rod Wolford


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

      global gMem, gCount, gNum, gLoc, gCreateVert, gMemNum


      on prepareMovie
        gCreateVert = False
        gMemNum = 5


      on mouseDown
        if not(gCreateVert) then
          gMem = new (#vectorShape, member gMemNum of castLib 1)
          gMemNum = gMemNum + 1
          gMem.regPoint = point(0,0)
          gMem.centerRegPoint = False
          gMem.closed = False
          gMem.antialias = True
          gMem.strokeWidth = 0.25
          gMem.strokeColor = rgb(0,0,0)
          gNum = getFreeChannel()
          channel(gNum).makeScriptedSprite(gMem, point(0,0))
          sprite(gNum).ink = 36
          gCount = 0
          gCreateVert = True
        end if
        if gCreateVert then
          if the doubleClick then
            gCreateVert = False
            gCount = gCount - 1
            gMem.closed = True
            gMem.fillMode = #solid
            gMem.fillColor = rgb(random(256) - 1,random(256) - 1,random(256) - 1)
            gFinished = True
          end if
          gCount = gCount + 1
          gMem.addVertex(gCount, the mouseLoc)
          gCount = gCount + 1
          gMem.addVertex(gCount, the mouseLoc)
          gLoc = the mouseLoc
        end if


      on enterFrame
        if gCreateVert then
          gMem.moveVertex(gCount, the mouseH - gLoc[1], the mouseV - gLoc[2])
          theLoc = (gMem.vertexList)[gCount][1]
          if not(theLoc = the mouseLoc) then
            gMem.moveVertex(gCount, the mouseH - theLoc[1], the mouseV - theLoc[2])
          end if
          gLoc = the mouseLoc
        end if


      on stopMovie
        theCount = castLib(1).member.count
        repeat with i = 1 to theCount
          if member(i).type = #vectorShape then member(i).erase()
        end repeat


      on getFreeChannel
        repeat with i = 1 to the lastChannel
          if sprite(i).member.type = #empty then
            aNum = i
            exit repeat
          end if
        end repeat
        return aNum

        • 1. Re: Problem with Script Using New() to Create a #Vectorshape
          Sean_Wilson Adobe Community Professional

          While I haven't read through all your script, try replacing

          gMem = new (#vectorShape, member gMemNum of castLib 1)


          gMem = _movie.newMember(#vectorShape, member gMemNum of castLib 1)


          It's possible the movie you are trying to integrate this into has a #movie script with a #new handler that should have been typed as a #parent script

          • 2. Re: Problem with Script Using New() to Create a #Vectorshape
            Rod@FOF Level 1



            Thank you. Changing gMem handler from #new to #_movie.newmember did the trick. I still have not found the behavior or movie script that contains the #new handler that created the problem. I was not aware of the #_movie.newmember handler. Seems that because it is specific to a new member added into a movie that it may be more useful than just using #new when adding new members is needed. Is that so? Does it have any downsides?


            Once again, thanks for your answer. By the way, I think the script was originally a J Chunick script.