2 Replies Latest reply on Sep 11, 2006 2:46 PM by mjacoby

    Attach behavior to object

    mjacoby
      I'm trying to clone a sprite using OOP and can't find a way to attach a behavior to the newly created sprite using lingo.

      Is this possible? What I want is to capture mouse clicks on the new sprite after it's created.

      What am I missing? Code below . . .

      ******************************************************

      The behavior on the original sprite:

      property pPressed,pClickDiff,pMemberName,pMemberlength,pArrangeWindowNum, pStartRect
      global gSpriteListNum
      -- Property holds the "name" of the chunk
      on getPropertyDescriptionList(me)
      list = [:]
      addProp list, #pMemberName, [comment: "The name of the sprite:",\
      #format: #string, #default: VOID]
      addProp list, #pMemberlength, [comment: "The length of the section:",\
      #format: #integer, #default: VOID]
      return list
      put list
      end


      on mouseDown me
      -- Increase sprite number for next available sprite location
      gSpriteListNum = gSpriteListNum + 1
      -- Create new instance name
      newName = pMemberName & "_" & gSpriteListNum
      -- Instantiate new object
      newName = new (script "cloneChord", pMemberName)
      -- Call the clone method
      newName.cloneMe(pMemberName, pMemberlength, me.spriteNum)

      end

      *********************************************************
      This is the parent script to create new sprite:

      global gSpriteListNum, gChordPropList
      property memName,

      -- Instantiates a new object
      on new me, memName
      return me
      end

      on cloneMe me, myName, pMyLength, origNum

      put "This is the parent: " & myName
      location = sprite(origNum).loc
      -- clone new model, setting it's properties
      sprite(gSpriteListNum).puppet = true -- got to do this first
      sprite(gSpriteListNum).member = member(myName) -- take it's member name
      sprite(gSpriteListNum).color = sprite(origNum).color -- same bat color for now
      sprite(gSpriteListNum).moveableSprite = True -- make this one moveable
      sprite(gSpriteListNum).ink = 1 -- set it so it is transparent
      sprite(gSpriteListNum).loc = _mouse.mouseLoc -- set it to the mouse's location
      --Follow the mouse (with a 10 pixel offset)
      repeat while _mouse.mouseDown
      sprite(gSpriteListNum).loc = the mouseLoc -10
      _movie.upDateStage()
      end repeat
      -- When it's released check whether it's in a
      if _mouse.mouseUp then

      checkMyLoc(myName,pMyLength)
      end if
      end

      -- Check if new sprite is within another sprite on stage
      on checkMyLoc(chordName, barLength)
      global gSpriteListNum, gChordPropList
      if sprite(gSpriteListNum).within(sprite("A")) then
      gChordPropList.Add([gSpriteListNum, chordName, barLength])
      put "This is the gChordPropList: " & gChordPropList
      _sound.beep(1)
      end if
      end

      ****************************************************************
      Help?