add value to current value of text input in flash AS3? - actionscript-3

I'm trying to add value to the current value of an input text field in AS3.
EXAMPLE: I have a few buttons and each button has a value, when i click on each button, the value of that button gets copied/inserted into a text input field on the stage.
further explanation:
button 1 value is (BALL)
button 2 value is (Book)
button 3 value is (Pen)
button 4 value is (cup)
etc etc ....
I have an empty input field on the stage called rest_Text.text.
so when I click on any of the buttons above, the value of that button gets copied inot the rest_Text.text...
and the final result would be something like this in the rest_Text.text:
BALL, Book, Pen
my current code is this:
function clipClick(e:Event):void {
MovieClip(root).main.loginHolder.rest_Text.text = e.target.clickTitle;
}
the code above will delete the current value and replaces it with a new one! but i need to add each value to the current one without deleting the old value.
any help would be appreciated.
Thanks in advance.

You can concatenate strings using the addition operator (+). For example:
trace(btn1.clickTitle + btn2.clickTitle + btn3.clickTitle);
//traces "BALLBookPen"
Adding on to an existing string is done with addition assignment (+=). Since you want a comma and space between each string, this is how you'd rewrite your function:
function clipClick(e:Event):void {
MovieClip(root).main.loginHolder.rest_Text.text += ", " + e.target.clickTitle;
}

Related

Check String equality of Slide textbox

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

How to check in sikuli that image is exist in screen or not and perform if else condition on that result

I am trying to automate a desktop application in sikuli. What i am doing copying data from from existing user and creating new user using some of that data. In form there are two check boxes. If that check boxes is ticked for existing user, then while creating new user i need to check the text box. for that am taking checked text box image and giving in if condition. If checked text box image is there in that page i will carry value 1 to a variable else value will be 0. according to that value am performing check uncheck function in new user creation page. But the issue what i am facing is, am not able to check if the image exist in that page or not in sikuli. Please anybody help me. my code is giving below
int bomanager=0;
int boswitchboard=0;
System.out.println("boswitchboard value before assign it to 1" + bomanager);
if (screen.exists("images/backofficeswitchboardwithtick.png") != null)
{
boswitchboard=1;
System.out.println("boswitchboard value after assign"+boswitchboard);
}
System.out.println("bomanager value before assign it to 1" + bomanager);
if(screen.exists("images/backofficemanagerwithtick.png") != null)
{
bomanager=1;
System.out.println("bomanager value after assign it to 1"+bomanager);
}
then using this value need to perform below function.
System.out.println("Before condition" + bomanager);
if (bomanager ==0){
screen.click("images/backofficemanagerwithtick.png");
}
screen.setAutoWaitTimeout(10);
System.out.println("Before condition" + boswitchboard);
if(boswitchboard==0){
System.out.println("Inside To tick Condition" + boswitchboard);
System.out.println("Ticking the SwitchBorad when itsnot already ticked");
screen.click("images/backofficeswitchboardwithtick.png");
}
I'm asssuming you're looking to use "if exists" method here
if exists(img, timeout):
click(img)
else:
....
with the method exists() I usually use:
if(exists("yourUrlImage")!=null):
(do something when exists)
else:
(do another thing when not exists)
Because that will return a "match" object.
Hope this helps

Creating a user generated list in flash

I'm trying to create a flash application that will keep track of user generated values. The app should basically allow the user to input the name of the item and it's cost. The total costs should then be added up to show a total value to the user. I can probably figure out how to add the values together, but I'm not really sure how to allow the user to create a list and then allow the user to save it. Can anyone point me towards a tutorial or point me in the right direction?
I am using variables to add user inputed numbers to come up with a total. The first problem is that actionscript 3.0 does not allow variables for texts. I just converted it to 2.0 to fix this. The second problem, is when I test the app and put in my values and click submit, I get NaN in the total values field. Is there a reason why it wouldn't add the values?
Here is the code I used for the submit button:
on (release) {
total = Number(rent) + Number(food) + Number(travel) + Number(entertainment) + Number(bills);
}
Am I missing anything?
Can I give the input text instance names and then give them variables? How are some ways to go about this?
Thanks for the help!
Have an object array, say for example
var stack:Array = new Array();
Then push the item name and it's cost to that array when user inputs, like
stack.push({item:AAA, cost:xx});
So that you can generate the list whenever you want with that array.
You have to see how this works in code. A list in actionscript could be stored inside an array, vector, dictionary or even an Object.
Var myList:Array = [];
myList.push({name: "item 1", cost: 5 });
myList.push({name: "item 2", cost: 7.5 });
If you want to grab the 'product' of "item 1" from the list, you have to create a function for that, lets call it getProductByName
function getProductByName(name:String):Object
{
for each(var product:Object in myList)
{
if (product.name === name) return product;
}
return null; // no match found
}
You can call that function like this:
var product = getProductByName("item 1");
trace(product.cost); // 5
And you can alter the product, so lets make it more expensive
product.cost += 1;
trace(product.cost); // 6
Have fun! If you are using classes, you would create one for the product, with public name and cost, and in that case you'de better use a vector, to ensure working with the right type.
This is what fixed the issue for me in action script 3.0:
myButton.addEventListener(MouseEvent.CLICK, addThem);
function addThem(e:MouseEvent)
{
totalField.text = String ( Number(field1.text) + Number(field2.text) + ....);
}
I also had to name the instances appropriately.

How to lock a character in an input field

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);

Want to get cursor position within textInput

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.