7 Replies Latest reply on Dec 29, 2011 9:16 AM by Production Monkey

    Moving Lines Up Or Down In A TXT Field...

    GRAMOPHONE Level 1

      I'm wondering if there's a way to move lines UP or Down by clicking on it.

      I was testing this, but it doesn't work

       

       

      put

      member(the mouseMember).line[the mouseLine] after member("MyTXT")

       

      put

      member(the mouseMember).line[the mouseLine] before member("MyTXT")

       

      Please, if anyone has a script or know how this can be accomplished, I'll really

      appreciate your help...

       

      Thanks

       

       

       

        • 1. Re: Moving Lines Up Or Down In A TXT Field...
          josh_chunick Level 1

          What version of Director are you using?... and I'm not clear by your example code and description exactly what functionality you are looking for in moving a line of text that's been clicked on. Is there a program or pre-existing function of a windows/mac component that allows you to perform such an action which you are trying to emulate?

          • 2. Re: Moving Lines Up Or Down In A TXT Field...
            GRAMOPHONE Level 1

            I'm using Director MX2004.

            Let try to explain what I'm looking for.

            Imagine you have a txt field with th following lines:

             

            John Scott

            Mary E Smith

            Paul Kirkham

            Andrew Roy

            Peter Gordon

             

            Now, let's say I want to move Peter Gordon on top of Andrew Roy.

            I would like to have two buttons: one with arrow down and one with arrow up so first I click on the line I

            want to move UP or DOWN and then click on the corresponding arrow.

            • 3. Re: Moving Lines Up Or Down In A TXT Field...
              josh_chunick Level 1

              -- attach this behaviour to your field member (it has to be a Director field member, NOT a text member or flash component)

              property spriteNum

              property sp, mem

              property selectedLine

               

              on beginSprite me

                sp = sprite(spriteNum)

                mem = sp.member

                selectedLine  = 0

              end

               

              on mouseDown me

                selectedLine = _mouse.mouseLine

                ln2 = selectedLine - 1

                if ln2 = 0 then

                  ln2 = 1

                  charPos1 = 0

                else

                  charPos1 = mem.line[1..ln2].length + 1

                end if

                charPos2 = charPos1 + mem.line[selectedLine].length

                mem.selection = [charPos1, charPos2]

              end

               

              on moveSelectedLine me, val

                if selectedLine = 0 then exit

                selText = mem.line[selectedLine]

                lnCount = mem.line.count

                newLine = max(1, min(lnCount, selectedLine + val))

                sel = mem.selection

                selOffset = mem.line[newLine].length + 1

                dir = (newLine - selectedLine)

                sel = sel + ([selOffset, selOffset] * dir)

                mem.line[selectedLine].delete()

                if newLine = lnCount then

                  mem.line[newLine] = selText

                else

                  mem.line[newLine] = selText & RETURN & mem.line[newLine]

                end if

                mem.selection = sel

                selectedLine = newLine

              end

               

              -- on your up/down arrow buttons attach these code behaviours:

              -- for the up arrow button

              on mouseUp me

                sendAllSprites(#moveSelectedLine, -1)

              end

               

              -- for the down arrow button

              on mouseUp me

                sendAllSprites(#moveSelectedLine, 1)

              end

               

              Note: you will have to click on a line to select it first. I believe this satisfies everything you laid out.

              • 4. Re: Moving Lines Up Or Down In A TXT Field...
                GRAMOPHONE Level 1

                Hi Josh,

                I was going to cry of happiness when I saw your reply, and when I tested it... I cried...

                It gives the following error:

                 

                Script error: Object expected

                charPos1 = mem.line[1..ln2].length +1

                 

                • 5. Re: Moving Lines Up Or Down In A TXT Field...
                  josh_chunick Level 1

                  the script must be attached to a field member, NOT a text member or a flash component. I had to write it for you so it's been tested, and the instructions I provided to you should be quite straightforward. Please go over them again and give it another try. If you're still having difficulty getting it to work then I'll try to post the file somewhere so you can download and have a look.

                  GRAMOPHONE wrote:

                   

                  Hi Josh,

                  I was going to cry of happiness when I saw your reply, and when I tested it... I cried...

                  It gives the following error:

                   

                  Script error: Object expected

                  charPos1 = mem.line[1..ln2].length +1

                   

                   

                  • 6. Re: Moving Lines Up Or Down In A TXT Field...
                    GRAMOPHONE Level 1

                    Josh, I really appreciate your help... I'm using a field member. I'm using Director MX2004. Could this be the problem?

                    It keeps giving me the same error...

                     

                    Thanks again for your help.

                    • 7. Re: Moving Lines Up Or Down In A TXT Field...
                      Production Monkey Level 3

                      The default Tools Palette contains a Flash TextInput. If your are using that widget to insert a text field then you have to switch it to "Classic" mode first. Or, you can use the menu:  Insert->Control->Field.