将 as2 转换为 as3



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

但问题是它是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;
}

它并不像你想象的那么糟糕,但是什么是查找器和查找下一个按钮? 这些是可以由以下人员创建的回调

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
}

好的,应该是这样。 我对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);

最新更新