File version: 6

File is zlib compressed. Ratio: 72%

File size: 25374 (Depacked)

Frame rate: 50.000000

Frame count: 5

Movie width: 400.00

Movie height: 200.00


Back to examples

#
# getTextSnapShot() example for Swftools http://www.swftools.org/ #
#
# Text selection with the mouse
#
#

.flash filename=textsnap.swf version=6 bbox=400x200 background=salmon

.font vera filename=../font/Vera.ttf

        .text line1 font=vera text="bla bla bla bla bla bla bla bla bla" color=blue size=25%
        .text line2 font=vera text="abcdefghijklmnopqrtuvwxyz" color=blue size=25%
        .text line3 font=vera text="The quick brown fox jumps over the lazy dog" color=blue size=25% 

        .frame 1

            # to test pdf2swf files, replace the following sprite with
            # .swf MyMC filename="testfile.swf"

            .sprite MyMC
                .put line1 x=10 y=50
                .put line2 x=10 y=80
                .put line3 x=10 y=110
            .end

            .put MyMC

        .frame 2

        .frame 3

        .frame 4

        .action:
            MyMC.gotoAndStop(2);
            str = MyMC.getTextSnapShot();
            str.setSelectColor(0xffff00);
            FirstCaracter = -1;
   
        MyMC.onMouseDown = function() {
           // find which character the mouse pointer is over (if any)
           FirstCaracter = str.hitTestTextNearPos(_xmouse, _ymouse, 0);
           // deselect everything
           str.setSelected(0, str.getCount(), false);
        };

        MyMC.onMouseUp = function() {
           if (FirstCaracter>=0) {
           LastCaracter = str.hitTestTextNearPos(_xmouse, _ymouse, 0);
           if (FirstCaracter != LastCaracter) {
              // select the zone
           if (FirstCaracter < LastCaracter) {
              str.setSelected(FirstCaracter, LastCaracter+1, true);
           } else {
              str.setSelected(LastCaracter,FirstCaracter+1,  true);
           }
           }
           FirstCaracter = -1;
           LastCaracter = -1;
           }
        };

        MyMC.onMouseMove = function() {
           if (FirstCaracter != -1) {
           // deselect everything to update selection
           str.setSelected(0, str.getCount(), false);
           }
           if (FirstCaracter>=0) {
           LastCaracter = str.hitTestTextNearPos(_xmouse, _ymouse, 0);
           if (FirstCaracter < LastCaracter) {
              str.setSelected(FirstCaracter, LastCaracter+1, true);
           } else {
              str.setSelected(LastCaracter,FirstCaracter+1,  true);
           }
              }
        };

        .end

        .frame 5
            .action:
                Stop();
            .end

.end