将as2转换为as3

时间:2012-11-29 20:01:35

标签: actionscript-3 flash actionscript-2 flash-cs5.5

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

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

2 个答案:

答案 0 :(得分: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
}

答案 1 :(得分: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);