forked from: flash on 2012-11-21
♥0 |
Line 89 |
Modified 2012-11-21 08:25:21 |
MIT License
archived:2017-03-30 08:28:52
ActionScript3 source code
/**
* Copyright hemingway ( http://wonderfl.net/user/hemingway )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/fTyt
*/
// forked from DakeNemui's flash on 2012-11-21
package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
public class FlashTest extends Sprite {
public function FlashTest() {
// write as3 code here..
//INPUT will be filtered with the string FILTER
//Wanted to do it the C/C++ way but I figured out that OUTPUT[k] = INPUT[i] didn't work
var INPUT:String = "";
var FILTER:String = "";
//Declarations,definitions
var fTEXT:TextFormat = new TextFormat("Tahoma",12,false);
var TEXT_1:TextField = new TextField();
var TEXT_2:TextField = new TextField();
var TEXT_3:TextField = new TextField();
TEXT_1.defaultTextFormat = fTEXT;
TEXT_2.defaultTextFormat = fTEXT;
TEXT_3.defaultTextFormat = fTEXT;
//Input text to be filtered here and press enter to filter
TEXT_1.text = "Input text here...";
TEXT_1.type = TextFieldType.INPUT;
TEXT_1.border = true;
TEXT_1.width = 300;
TEXT_1.height = 20;
TEXT_1.x = 70;
TEXT_1.y = 10;
//The result will appear here
TEXT_2.text = "OUTPUT";
TEXT_2.selectable = false;
TEXT_2.border = true;
TEXT_2.width = 300;
TEXT_2.height = 20;
TEXT_2.x = 70;
TEXT_2.y = 40;
//The setting of the filter, ex. INPUT : TEST with FILTER : T gives an OUTPUT of : ES
TEXT_3.text = "Input filter here...";
TEXT_3.type = TextFieldType.INPUT;
TEXT_3.border = true;
TEXT_3.width = 300;
TEXT_3.height = 20;
TEXT_3.x = 70;
TEXT_3.y = 70
addChild(TEXT_1);
addChild(TEXT_2);
addChild(TEXT_3);
TEXT_1.addEventListener(KeyboardEvent.KEY_UP,submit);
TEXT_1.addEventListener(MouseEvent.CLICK,select);
TEXT_3.addEventListener(MouseEvent.CLICK,select);
//On Enter filter
function submit(event:KeyboardEvent):void
{
if ( event.keyCode == 13 )
{
INPUT = TEXT_1.text;
FILTER = TEXT_3.text;
TEXT_2.text = filter(TEXT_1,TEXT_3);
}
}
//On the first click to the input/filter the whole text is selected and the listener is
//then removed
function select(event:MouseEvent):void
{
if ( event.target == TEXT_1 )
{
TEXT_1.setSelection(0,TEXT_1.length);
TEXT_1.removeEventListener(MouseEvent.CLICK,select);
}
else if ( event.target == TEXT_3 )
{
TEXT_3.setSelection(0,TEXT_3.length);
TEXT_3.removeEventListener(MouseEvent.CLICK,select);
}
}
function filter(Input:TextField , Filter:TextField):String
{
//clear the last result
var Result:TextField = new TextField();
var OUTPUT:String = "";
var INPUT:String = Input.text;
var FILTER:String = Filter.text;
var add_char:Boolean = true;
for ( var i:int = 0 ; i < INPUT.length ; i++ )
{
for ( var j:int = 0 ; j < FILTER.length ; j++ )
{
if ( INPUT.charAt(i) == FILTER.charAt(j) )
add_char = false;
}
if ( add_char == true )
Result.appendText(INPUT.charAt(i));
else
add_char = true;
}
OUTPUT = Result.text;
return OUTPUT;
}
//Does the same as the function above but doesn't receive any arguments
//it takes the global? Variables, works only for them which is not what I find good
//in some cases...
/* function filter():void
{
//clear the last result
TEXT_2.text = "";
var add_char:Boolean = true;
for ( var i:int = 0 ; i < INPUT.length ; i++ )
{
for ( var j:int = 0 ; j < FILTER.length ; j++ )
{
if ( INPUT.charAt(i) == FILTER.charAt(j) )
add_char = false;
}
if ( add_char == true )
TEXT_2.appendText(INPUT.charAt(i));
else
add_char = true;
}
}
*/
}
}
}