6 Replies Latest reply on Dec 8, 2006 8:33 PM by Newsgroup_User

    text placement

    Level 7
      Not sure if my subject line is accurate but here's what I want to do.

      I have a text sprite that displays some external text. I want the text
      to be centred in a defined area. At the moment, if the text is one line,

      it displays OK. But if it flows onto 2 lines, it isn't centred right.

      So, is the following possible (and if so how):
      * Use Lingo to align my text sprite. So whenthe text is inderted, that
      sprite will align to an invisible shape area.?
      * Determine if the text flows onto 2 lines - so can move the text
      sprite's vertical location by the required amount.
      * Determine if the text is is 1 line and insert a RETURN in the text if
      it is, to ensure I always have 2 lines. (Not sure if this will give the
      result I'm after).

      Thanks.

        • 1. Re: text placement
          Level 7
          > So, is the following possible (and if so how):
          > * Use Lingo to align my text sprite. So whenthe text is inderted, that
          > sprite will align to an invisible shape area.?

          tTextMember.alignment = #center

          > * Determine if the text flows onto 2 lines - so can move the text
          > sprite's vertical location by the required amount.

          put tTextMember.line.count

          > * Determine if the text is is 1 line and insert a RETURN in the text if
          > it is, to ensure I always have 2 lines.

          If tTextMember.line.count = 1 then
          tText = tTextMember.text
          tTextMember.text = tText & RETURN
          end if
          • 2. Re: text placement
            duckets Level 1
            quote:

            Originally posted by: Newsgroup User
            > put tTextMember.line.count



            The above code only counts lines by looking for return characters. If you have a long line with no return characters, it could wrap onto multiple lines, while director still considers the 'line count' to be one. As posted in a similar thread recently, the following lines will give you the vertical position of the first and last characters, from which you can determine if they are on the same visible line, or if it has wrapped onto another line:

            firstCharV = textMem.charPosToLoc(1).locV
            lastCharV = textMem.charPosToLoc(textMem.char.count).locV

            hope this helps!

            - Ben
            • 3. Re: text placement
              Level 7
              Thanks Ben and Sean. I got distracted on something else and have just got back to
              this problem.

              Yes, I found that the linecount wasn't working for me. I'll try the first and last
              character check. Otherwise, maybe the alignment one.

              Thanks.

              • 4. Re: text placement
                Level 7
                Hi Sean and Ben,

                The code given in Sean's reply wasn't quite what I was after. When I was asking
                about alignment, I meant to align one sprite to another using Lingo. The
                'tTextMember.alignment = #center' just relates to character alignment in the text
                member itself. and, the linecount wasn't working for me as a I have a long text
                member wrapping onto multiple lines.

                However, I worked out a way to get the result I'm after. I start with tha locV of
                my text sprite as it should be if it was one line. Then I use the following:

                on beginSprite me
                textMem = sprite(me.spriteNum).member
                firstCharV = textMem.charPosToLoc(1).locV
                lastCharV = textMem.charPosToLoc(textMem.char.count).locV

                if firstCharV <> lastCharV then
                difference = lastCharV - firstCharV
                sprite(me.spriteNum).locV = sprite(me.spriteNum).locV - difference/2
                end if
                end

                Thanks guys for getting me here.








                • 5. Re: text placement
                  Level 7
                  Hi Sean and Ben,

                  The code given in Sean's reply wasn't quite what I was after. When I was asking
                  about alignment, I meant to align one sprite to another using Lingo. The
                  'tTextMember.alignment = #center' just relates to character alignment in the text
                  member itself. and, the linecount wasn't working for me as a I have a long text
                  member wrapping onto multiple lines.

                  However, I worked out a way to get the result I'm after. I start with tha locV of
                  my text sprite as it should be if it was one line. Then I use the following:

                  on beginSprite me
                  textMem = sprite(me.spriteNum).member
                  firstCharV = textMem.charPosToLoc(1).locV
                  lastCharV = textMem.charPosToLoc(textMem.char.count).locV

                  if firstCharV <> lastCharV then
                  difference = lastCharV - firstCharV
                  sprite(me.spriteNum).locV = sprite(me.spriteNum).locV - difference/2
                  end if
                  end

                  Thanks guys for getting me here.








                  • 6. Re: text placement
                    Level 7
                    Hi Sean and Ben,

                    The code given in Sean's reply wasn't quite what I was after. When I was asking
                    about alignment, I meant to align one sprite to another using Lingo. The
                    'tTextMember.alignment = #center' just relates to character alignment in the text
                    member itself. and, the linecount wasn't working for me as a I have a long text
                    member wrapping onto multiple lines.

                    However, I worked out a way to get the result I'm after. I start with tha locV of
                    my text sprite as it should be if it was one line. Then I use the following:

                    on beginSprite me
                    textMem = sprite(me.spriteNum).member
                    firstCharV = textMem.charPosToLoc(1).locV
                    lastCharV = textMem.charPosToLoc(textMem.char.count).locV

                    if firstCharV <> lastCharV then
                    difference = lastCharV - firstCharV
                    sprite(me.spriteNum).locV = sprite(me.spriteNum).locV - difference/2
                    end if
                    end

                    Thanks guys for getting me here.