Add text to already existing text without replacing it in Actionscript 3 - actionscript-3

Trying to make a calculator in Actionscript 3 where i click on the number buttons to add numbers to a textfield. However i am unable to add new numbers to the textfield without replacing the already existing number in the textfield.
Any ideas?

to add the test to an AS3 TextField you need the appendText() method

Related

How to change the color of a rectangle border in actionscript 3

I am currently following an online programming class at my school. We are studying Flash and therefore actionscript 3 and I am having difficulty in one of my projects.
I want to easily be able to change the border color of my button when the user clicks on it but I can't seem to find how. Until now, I used to change the entire button's color, but I want to try a new effect. To change the entire color I used this code :
var ctAvance:ColorTransform = btnAvance.transform.colorTransform;
ctAvance.color = 0x00CCCC;
btnAvance.transform.colorTransform=ctAvance;
Thanks a lot in advance!
its a possible duplicate of this question
its impossible in that way (using ColorTransform) however:
you have another option, if your btnAvance is a Movieclip or something else, convert*1 it to a Button instead, then inside your object, you have 4 frames in the names of Up Over Down Hit, under Over frame press F6 (insert keyframe) and simply change your button border color
Edit:
*1 : you must convert it in library, not only your instance in stage, find your btnAvance in library list, rightclick on it then select properties and change its type.

Undo/redo adding objects

I have a custom banner maker program in which the following can be done:
Different banner shapes can be selected (Buttons clicked to place the corresponding movieclip onto the stage)
Different banner colors can be selected by using a ColorTransform that is linked to buttons i.e. a red button turns the banner red
Textfields can be added to the stage, dragged and dropped using startDrag and stopDrag, and the text color can be changed with a ColorPicker as well as being able to change the font size and font itself
Pre-loaded images can be selected from a panel and added to the banner (Buttons that are clicked to add a corresponding movieclip to the stage)
Images can be uploaded directly onto the stage and can be resized
I need to figure out a way of being able to essentially add undo and redo features to do things like remove an image/textbox that was placed, change the banner color back to whatever color it was previously, reset the position of an object that was dragged from its default position etc.
I'm not sure how to best go about this using AS3?
Not hard. Use removeChild(instance name of Child here) to remove an object from the stage.
Atriace's idea is sensible. You didn't say if you'll want to remember the positions of things after you stop running your program. Or is it only while you're running?
If the latter I'd create an array for each banner or textfield, and store in that array the current values of the properties you want to record. So, for instance:
var A:Array = new Array
A.push(textfield1.text)
will put your current text in textfield1 into the first index position in array A. You can call that little bit of code when you initially add the text (on a button click or whatever). Later, if you want that text back you'd do it like
textfield1.text = A[0]
assuming that your old text was in the first index position in the array.
If you want to remember values between runs of the program use a SharedObject to write the value to disk. Too much to write about that here -- look it up!

Updating Flash text via ActionScript

I want to have a score in the bottom corner of my game. I made a new layer called Score, dragged out a text area, converted it to a symbol and named it Score. Then I set its instance name to Score.
The main class of my flash game is called Main.as. However, I can't seem to access the Score text area I made within the code. I get this error:
1046: Type was not found or was not a compile-time constant: Score.
What did I miss? How can I update the text areas text from within my code?
Edit: Forgot to mention I clicked the "Export for ActionScript" box when I converted it to a symbol. And it's of type MovieClip, if that matters.
When you export a symbol for ActionScript 3, Flash make a class for it with the given name (that is the same name you used both for class definition and instance).
You get this error because you're using the same name for class and instace.
You should check on them and use different names.
I usually name my instances ending with _mc
e.g. In your case you should have Score as the class and name your instance score_mc (or just score with lowercase S.
The layer name makes no difference. You need to set the instance name of your dynamic text field, not the clip containing it. There is also no need to convert it to a MovieClip. Create text field on your stage, make sure its not static, give it an instance name that you can use to access it.
Example, I made my text fields name scoreText_txt
//inside main.as
scoreText_txt.text="new text";
If you want to put your text filed inside a MovieClip you would need to give both the clip and your text field a name. You would then access it using .
MyMovieClip.MyText.text="new text"
Don't export for ActionScript unless you intend to create additional logic for the text field (because it will have its own class) or want to add it to the stage dynamically (via addChild()).
With the instance name being Score, give this a go:
Score.text = "822";
I suggest using lowercase instance names to differentiate from CamelCase used for classes. The above would read to more experienced developers as updating a static property text within a class Score.

Actionscript 3 loading Chinese symbols into TextField using Actionscript

I am having trouble loading Chinese Symbols into a TextField from another TextField.
I have a dynamic drop down box that loads its text from a string within the actionscript code, however the actionscript code cannot contain chinese symbols.
I thought the easiest way around this problem would be to load the text from another TextField, however it seems to appear blank, failing to load the text.
example
base1_mc.header1.textbox_txt.text=q1.text;
base1_mc.header1.textbox_txt.text = dynamic drop down textbox.
q1.text = chinese symbols inside TextField on the stage.
I thought this would have been a simple problem, however it doesnt appear to be so.
If I try to load it using this
base1_mc.header1.textbox_txt.text=q1;
it loads some text declaring a new and empty function.
Can anyone help me out here?
Try to turn off embedFonts for TextField. I.E.:
textbox_txt.embedFonts = false.

Is there a way to add text to sprite or movieclip not using TextField class?

Is there a way to add text programmatically in as3 to a Sprite or a MovieClip without using the class TextField
TextField inherits from InteractiveObject which is kind of heavy for what I want to do: just display text (i.e. I don't want to interact with the text).
Note: I'm aware that there is a property selectable to make the textfield not selectable. This is not the point.
Thank you
There are two ways that come to mind. The first being this whereby a string is written to bitmap data: How to draw a string on BitmapData
Second, you could try this fast font rendering library (although I have not tried it myself) lab.polygonal.de/2009/12/15/font-rendering-with-the-fp10-drawing-api/
Both these solutions seem to bypass the need for creating a textfield (except the first where it gets used to create but then is discarded).