2

我找到了一个用于从动态文本框中搜索和选择特定文本的脚本

但问题是它是 AS2

我通过只学习 AS3 开始 Flash,所以我不知道如何将 AS2 转换为 AS3 请有人帮助我:)

finder.onRelease = function() {
       Selection.setFocus("_root.textInstance");
       var inputterString:String = _root.inputter
       var inputLength:Number = inputterString.length;
       textStart = textVar.indexOf(inputter, 0);
       if (inputLength>0) {
             textEnd = textStart+inputLength;
       } else {
             textEnd = 0;
       }
       if (textStart>=0) {
             Selection.setSelection(textStart, textEnd);
       } else {
             Selection.setSelection(0, 0);
       }
       _root.textEnd = textEnd;
};

findNext.onRelease = function() {
       Selection.setFocus("_root.textInstance");
       var inputterString:String = _root.inputter;
       var inputLength:Number = inputterString.length;
       textStart = textVar.indexOf(inputter, _root.textEnd);
       if (inputLength>0) {
             textEnd = textStart+inputLength;
       } else {
             textEnd = 0;
       }
       if (textStart>=0) {
             Selection.setSelection(textStart, textEnd);
       } else {
             Selection.setSelection(0, 0);
       }
       _root.textEnd = textEnd;
}
4

2 回答 2

0

它并没有你想象的那么糟糕,但是 finder 和 findNext 按钮是什么?这些是可以创建的回调

finder.addEventListener(MouseEvent.MOUSE_UP, finderCallback);

// somewhere else in the code

private function finderCallback(e:MouseEvent):void {
   // code here

   // anything like _root.<varName> references something on the main file, 
   // so this just has to be something you can access in the funciton
}
于 2012-11-29T21:29:53.980 回答
0

好的,应该是这样的。我对 root.textInstance 和按钮做了一些假设。

import flash.events.MouseEvent;

function onFinderClicked(event:MouseEvent):void{
    stage.focus = root.textInstance;
    root.textInstance.selectable = true;
     var inputterString:String = root.inputter
     var inputLength:Number = inputterString.length;
     textStart = textVar.indexOf(inputter, 0);
     if (inputLength>0) {
         textEnd = textStart+inputLength;
     } else {
         textEnd = 0;
     }
     if (textStart>=0) {
         root.textInstance.setSelection(textStart, textEnd);
     } else {
         root.textInstance.setSelection(0, 0);
     }
     root.textEnd = textEnd;
};


function onFindNextClicked(event:MouseEvent):void{
    stage.focus = root.textInstance;
    root.textInstance.selectable = true;
    var inputterString:String = root.inputter;
    var inputLength:Number = inputterString.length;
    textStart = textVar.indexOf(inputter, root.textEnd);
    if (inputLength>0) {
         textEnd = textStart+inputLength;
    } else {
         textEnd = 0;
    }
    if (textStart>=0) {
         root.textInstance.setSelection(textStart, textEnd);
    } else {
         root.textInstance.setSelection(0, 0);
    }
    root.textEnd = textEnd;
}

finder.addEventListener(MouseEvent.CLICK, onFinderClicked);
findNext.addEventListener(MouseEvent.CLICK, onFindNextClicked);
于 2012-11-29T22:14:25.977 回答