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 に答える