4 Replies Latest reply on Oct 22, 2008 4:49 PM by James Newton, ACP

    LDM scoping headaches…

    Applied CD Level 1
      I need a function that will calculate the bounding rect of all sprites and the stage in an LDM and report that rect to the parent movie. That rect is then used to establish scroll limits for scroll bars in the parent movie which I have working with fixed numbers, now I’d like it to dynamically adjust based on the LDM content.

      Here’s part of the parent movie behavior attached to the LDM sprites:

      on beginSprite me
      pSprite = sprite(me.spriteNum)
      pSprite.movie.sprite(1).scriptInstanceList[1]=[:]
      pSprite.movie.sprite(1).scriptInstanceList[1][#ldmMovie] = pSprite.movie
      pSprite.movie.sprite(1).scriptInstanceList[1][#parentMovie] = _movie.stage.movie
      pSprite.movie.sprite(1).scriptInstanceList[1][#parentSprite] = pSprite
      mySpriteRect = pSprite.movie.getSpriteRect()
      -- snip lots of other code
      end

      And this is a movie script in the LDM cast:

      on getLdmProp aProp
      return sprite(1).scriptInstanceList[1][aProp]
      end
      -----------------------
      on getSpriteRect
      spriteRect = rect(0,0,getLdmProp(#ldmMovie).stage.rect[3]-getLdmProp(#ldmMovie).stage.rect[1],getLdmPr op(#ldmMovie).stage.rect[4]-getLdmProp(#ldmMovie).stage.rect[2])
      repeat with myChannel = 2 to getLdmProp(#ldmMovie).lastChannel
      spriteRect = spriteRect.union(getLdmProp(#ldmMovie).sprite(myChannel).rect)
      end repeat
      return spriteRect
      end

      Apparently getLdmProp(#ldmMovie).sprite(myChannel).rect isn’t structured correctly, I get error saying it’s not a rect. Anyone see what’s wrong? Thanks
        • 1. Re: LDM scoping headaches…
          Production Monkey Level 3
          When the DOM was added to D10, they did an incomplete job. There are runtime identification problems when accessing native director objects inside LDMs and MIAWs.

          Your code looks fine to me although I did not test it.

          I believe the following will hack around this bug. Also un-tested.

          on getSpriteRect
          StageRect = getLdmProp(#ldmMovie).stage.rect -- this makes things more readable/understandable
          spriteRect = rect(0,0,StageRect[3]-StageRect[1],StageRect[4]-StageRect[2])

          repeat with myChannel = 2 to getLdmProp(#ldmMovie).lastChannel
          RectOb = getLdmProp(#ldmMovie).sprite(myChannel).rect
          TmpRect = rect(RectOb[1],RectOb[2],RectOb[3],RectOb[4])
          spriteRect = spriteRect.union(TmpRect)
          end repeat

          return spriteRect
          end
          • 2. Re: LDM scoping headaches…
            James Newton, ACP Level 3
            An LDM doesn't really have a stage.rect as such. If you are scrolling the contents of your LDM, then I assume that you are setting its #crop property to TRUE. In this case, you can consider that its width and height of the "stage" of the LDM is the same as that of the host sprite. As for the bounding rect of its elements, will this work for you:


            • 3. Re: LDM scoping headaches…
              Applied CD Level 1
              Thanks all. Production Monkey was right in that the LDM seems to return rect objects, not simple rectangles. This is true both in the LDM scope and the value returned to the parent. The attached code works and has been tested but note that I’ve changed some variable names for readability.

              James, yeah the LDMs are set to crop and the scroll bars actually shuffle the sprites within the LDM, the stage of the LDM essentially being the view port in the parent. I couldn’t come up with a better way to scroll mixed sprite types within a window. Works well for at least 100 vector items which is about all I need. I considered using MIAWs but that introduced more problems than LDM’s. Thanks for the code, I’ll check it against what I’m using now for speed.
              • 4. Re: LDM scoping headaches…
                James Newton, ACP Level 3
                It sounds as if you are doing something like this: /scrollBar/... with the difference that I am using a simple filmloop, where you are using an externally-stored LDM.