2

I found a script for searching and selecting a specific text from a dynamic text box

But the problem is it is AS2

I started Flash by only studying AS3 so i have no idea on how to convert AS2 to AS3 Pls someone help me :)

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;
}
FAllen
  • 21
  • 1
  • 4

2 Answers2

0

It's not as bad as you might think, but what are finder and findNext - buttons? These are callbacks which can be created by

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
}
Gone3d
  • 1,189
  • 1
  • 8
  • 20
  • not even... Selection.setFocus is gone, _root in gone... this code needs a lot more changes than that. – Jason Reeves Nov 29 '12 at 21:59
  • as I mentioned - _root is referencing the global vars in the main app - he'll have to look through the code to find out what they are. setFocus can be handled again something like addEventListener(FocusEvent.FOCUS_IN, focusCallback); Once he gets the callbacks running, the rest should start to fall into place – Gone3d Nov 29 '12 at 22:16
  • yeah I wasn't trying to be short, just figured since he said he knows nothing of as2 he would need more help than that. – Jason Reeves Nov 29 '12 at 22:28
  • no problem - I'm right in the middle of working on some old AS2 and it's driving me nuts. I so much prefer AS3 – Gone3d Nov 29 '12 at 22:44
  • I tried these methods still cant make it work in AS3.... But i am going to publish it with AS2 then i will just load that swf in AS3... Got no other choice :D – FAllen Dec 01 '12 at 20:44
0

OK, this should be it. I made some assumptions about root.textInstance and the buttons.

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);
Jason Reeves
  • 1,716
  • 1
  • 10
  • 13
  • I'd avoid using root if possible and just figuring out what it is you need and make it available in the class - especially if a new implementation is going to have different classes and instances – Gone3d Nov 29 '12 at 22:45
  • or be able to cast it would be better also, but were flying blind – Jason Reeves Nov 29 '12 at 22:47
  • casting is ok - but given the example, I was letting him figure out what went where since it all can so easily be contained in one class and not have to worry about the root or main .as file – Gone3d Nov 30 '12 at 01:15
  • I tried these methods still cant make it work in AS3.... But i am going to publish it with AS2 then i will just load that swf in AS3... Got no other choice... Btw thanks so much for trying to help me :) – FAllen Dec 01 '12 at 20:46
  • its probably root. Was this code on the main document? or buried in some other class? We can help you get it going if you tell us where it was. – Jason Reeves Dec 02 '12 at 04:53
  • This is the main document Here is the link for the fla http://www.mediafire.com/?erpwj4cvaotb134 well i use CS5.5 Thanks in Advance :) – FAllen Dec 02 '12 at 09:51