Design a Text Input by using components in flash and its InstanceName is listChat. In that text input I added a text by Dynamically. While I am adding text it displays with null.
For Example I added "apple" it Displays like nullapple
How to remove that null?
You can use the String's replace method.
If you want to remove only the first encounter of 'null' you can use this:
listChat.text = listChat.text.replace("null", "");
If you want to remove all encounters of 'null' this will do it:
var stripNullPattern:RegExp = /null/gi;
listChat.text = listChat.text.replace(stripNullPattern, "");
If you only want to remove null if it's in the first four characters use something like this:
if(listChat.text.substring(0, 4) == "null")
{
listChat.text = listChat.text.replace("null", "");
}
Check the AS3 reference for more info:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/String.html#replace()
Related
I'm using SlidesApp.getActivePresentation.getSlides[0].getPageElements()[0].asShape().getText().asString() to get the text of the title of the slide. However, when I try to check the text in an equality statement like SlidesApp.getActivePresentation.getSlides[0].getPageElements()[0].asShape().getText().asString() == "XYZ Company" it returns false. What do I need to do to accurately check that a given Slide page element textbox contains certain text?
Alternative Solution:
You can also try using the JavaScript String includes() method as it will only check if a string includes the word you're looking for & it will disregard any new lines or spaces on the string. See this sample below:
function test() {
var slide = SlidesApp.getActivePresentation().getSlides()[0].getPageElements()[0].asShape().getText().asString();
Logger.log(slide.includes("XYZ Company"));
}
Sample:
It seems the type of textbox was adding a trailing line break, so s.getPageElements()[0].asShape().getText().asString().trim() == "XYZ Company" evaluates true
I'm trying to find a way to append text (appendText) at a certain TextField line number.
I found a way to return the first character of a line:
tf.text.charAt(tf.getLineOffset(10)); //selects line 10
But I haven't found a way to append text. Any help would be appreciated!
This should do the trick (put the supplied text at the start of the supplied line), though there may be a more efficient way of doing it.
function prependToLine(textField:TextField, line:int, text:String):void {
var lineOffset:int = textField.getLineOffset(line-1);
textField.text = textField.text.substring(0,lineOffset) + text + textField.text.substr(lineOffset);
}
I have an input text field in Flash and I want to keep a dollar sign at all times in front of it.
Normally I would just left align the input field and have a "$" next to it so it's uneditable, but in this instance the text field has to be center aligned.
I thought to just include a function to add "$" in front of all the text every time the field loses focus - but realised that would be a problem if there was already a $ sign in front and it just kept adding them.
Also - once I've done this, is there a way to grab the value from that input field excluding the "$"? Eg: some sort of splice that splices the first character and just grabs the rest of it.
To keep the $:
tf.addEventListener( Event.CHANGE, onTextChange );
function onTextChange( e:Event ):void
{
if ( tf.text.charAt(0) != "$" )
tf.text = "$" + tf.text;
}
And to get the text without the first character:
var yourText :String = tf.text.substring(1, tf.text.length);
In action script var x:String="123abc" I have to check any character, for that string.
i.e. here "abc" is that string so I give an alert that this string should contain only numbers.
How can I do that?
Do you mean to say that you would like to dispatch an alert if a string contains letters
var testVar:String = '123abc';
var pattern:RegExp = /[a-zA-Z]/g;
if( testVar.search(pattern) == -1 )
{
//all good there's no letters in here
}
else
{
//Alert, alert, letter detected!
}
the "pattern" variable is a RegularExpression that's adaptable. Here I'm only checking for letters... If you need more control, get more info about RegularExpressions or come back here with the specific filter you'd like to implement.
I think you are looking for Regular Expression support in AS3.
If the user is inputting text via a TextField then you can set the restrict property to limit the characters that can be entered into the textfield:
textFieldInstance.restrict = "0-9";
TextField.restrict documentation:
http://livedocs.adobe.com/flex/3/langref/flash/text/TextField.html#restrict
I am using textInput within grid using rendrer. I am populating a suggestion box just below the text input field on the basis of typed character and index of text input.Problem is that if i shrink grid column then suggestion box is not populating at the right place so I want global position of cursor in the text input field .
Something like that:
var inputTxt : TextInput = new TextInput;
var x : Number = inputTxt.cursorManager.currentCursorXOffset;
var y : Number = inputTxt.cursorManager.currentCursorYOffset;
Try using 'global coordinate'.
This might resolve your problem.