Hi All,
I’m working on a class that I want to use to input special characters into a text field. But I’m not sure how to go about this so suggestions are welcome.
I have an fla with different input text fields. My users do not know ALT-codes so They must be able to input special characters easy. I would like to import this class to simplify inserting special characters.
This is how it should work:
- the cursor is in a text field
- the user rolls over a button(?) and the select character menu pops up
- the user clicks a button with the character in the popup
- the character is input into the text field at the cursor position
- the popup menu closes
For this I have wrote a class “InsertCharacter.as” and a test fla: test.fla
All the files are in the attached InsertCharacters.zip:
InsertCharacters.zip (945.0 KB)
I would like to have the rollover-button inside the class too, just place it on the stage and have it insert characters into the text field where the cursor is.
Can you give me a hint on how to approach this ?
The InsertCharacter.as code I wrote up is this:
[code]package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.geom.Rectangle;
import flash.events.*;
import fl.controls.*;
import flash.text.TextFormat;
public class InsertCharacter extends MovieClip{
public function InsertCharacter() {
//Array of characters
var arrCharacters:Array = ["m²","à","á","ä","ç","è","é","ë","ñ","ò","ó","ô","ù","ú","ü","À","Á","Â","Ã","Ä","Å","Ç","È","É","Ê","Ë","Ì","Í","Ò","Ó","Ö","Ø","Ü"]
//buttongrid
var btnButton:Button;
//
var intLabelIndex:int = 0;
//size of buttons
var intButtonWidth:int = 40;
var intButtonHeight:int = 30;
//initial X and Y position of first button
var intStartX:int = 10;
var intStartY:int = 10;
//spacing between buttons
var intSpacing:int = 5;
//number of rows and columns
var intRows:int = 6;
var intColumns:int = 6;
//textformat for buttons
var tfButton:TextFormat = new TextFormat();
tfButton.size = 18;
tfButton.bold = true;
//Draw a background for the buttons
var intBackgroundWidth:int
var intBackgroundHeight:int
intBackgroundWidth = 2 * intStartX + intColumns*(intButtonWidth + intSpacing) - intSpacing;
intBackgroundHeight = 2 * intStartY + intRows*(intButtonHeight + intSpacing) - intSpacing;
var rctBackground:Sprite = new Sprite; // initializing the variable
rctBackground.graphics.beginFill(0xEEEEEE); // colour
rctBackground.graphics.drawRect(0, 0, intBackgroundWidth,intBackgroundHeight); // (x, y, width, height)
rctBackground.graphics.endFill();
addChild(rctBackground); // adds the background to the stage
//Create the grid of buttons
for (var i:int = 0; i < intRows; i++){
for (var k:int = 0; k < intColumns; k++){
if(arrCharacters[intLabelIndex] != null){
btnButton = new Button();
btnButton.x = intStartX + (k*(intButtonWidth + intSpacing));
btnButton.y = intStartY + (i*(intButtonHeight + intSpacing));
btnButton.name = arrCharacters[intLabelIndex];
btnButton.width = intButtonWidth;
btnButton.height = intButtonHeight;
btnButton.label = arrCharacters[intLabelIndex];
btnButton.setStyle("textFormat", tfButton);
intLabelIndex++ ;
addChild(btnButton);
btnButton.addEventListener(MouseEvent.CLICK, fncReturnCharacter);
} //end if
} //end for
} //end for
} //end public funtion InsertCharacter
private function fncReturnCharacter(e:Event){
//return character
trace (e.target.name)
}
} //end public class InsertCharacter
} //end package[/code]