ActionScript 3 - How do I pass content of TextArea to SharedObject? - actionscript-3

I am trying to save the content (input by the user) of a TextArea field to a local SharedObject when the user clicks on a submit button. I am an absolute beginner with AS3, so I am probably asking a really stupid question but...where am I going wrong? At present this creates the file but it contains "answertext answer[ans_field]" and not the text entered into the field!
Any help would be much appreciated.
Here's my code:
import fl.controls.TextArea;
import flash.net.SharedObject;
var ans_field: TextArea = new TextArea();
var MySO:SharedObject = SharedObject.getLocal("answertext");
sub_btn.addEventListener(MouseEvent.CLICK, f3_MouseClickHandler);
function f3_MouseClickHandler(event: MouseEvent): void {
MySO.data.answer = "[ans_field]"
MySO.flush();
}

You're after:
MySO.data.answer = ans_field.text;
Read more about TextField and its text property.

Related

Multiple TextField's in Animate CC? Can't add second TextField

I have a very simple apps with LocalConnection between them. One button in client and one Dynamic Text on server. When I pushing my button on client then text in server are changing, everything works good. But if I add static text in server then my dynamic text stop working (not changing). How is it possible? Checked its 5 times, just adding static text ruined my app.
Sry, for my English, Im not fluent speaker.
p.s Woorking in Animate CC
p.p.s. feels that is very simple solution here but checked it in google and didnt found any answers :(
SERVER
import flash.net.LocalConnection;
var conn:LocalConnection = new LocalConnection();
conn.client = this;
conn.connect("data");
function recieve_data(unfO:String):void {
unfOne.text = unfO;
}
CLIENT
import flash.net.LocalConnection;
import flash.events.MouseEvent;
var conn:LocalConnection = new LocalConnection();
var unfOned:int = 0;
unfOne.addEventListener(MouseEvent.CLICK, unfOne_send);
function unfOne_send(e:MouseEvent):void {
unfOned++;
conn.send('data', 'recieve_data', unfOned);
unfOne_caption.text = unfOned.toString();
}
The problem is in Font, by default it was Open Sans and I should change it to arial or do Font Embeding.

How could I animate an instant message conversation in Flash Professional using AS3?

I'm creating a large "movie" using flash professional CC and AS3. In one scene I want my character to be IMing his friend. The scene is already animated and shows the back of his head and the viewer can read his screen.
I want the user to be able to type for my character, so whatever the user types shows up in the bottom of the chat box, and then when the user presses enter the same text appears in a different place on the screen.
Unfortunately I haven't even gotten CLOSE to making that happen. So far I'm stuck on getting the text from the input box to appear in a dynamic textbox elsewhere, so I've been watching tons of tutorials. This code runs without errors but does not output the text like I want.
var outputString = outputBox.text; //get key presses only when textfield is edited
inputBox.addEventListener(KeyboardEvent.KEY_DOWN, handler);
function handler(event:KeyboardEvent) { //13 is enter key
function handler(event:KeyboardEvent) { //13 is enter key
if(event.charCode == 13) {
outputBox.text = "UserName: " + outputString;
}
}
(Please ignore the bad indentation, that's more of an issue with me not understanding how to paste code here haha.)
Anyways does anyone know what's wrong? I have been trying to figure this out for days so if anyone could share some example code for how to get what I described working properly it would be immensely appreciated. All I really need to be able to do is save the user input so I can display it whererever I want. Thanks for reading!
Simple enough. Just set the text value of your output to your input after the keypresses.
import flash.text.TextField;
import flash.events.KeyboardEvent;
var input:TextField = new TextField();
addChild(input);
input.type = "input";
input.text = "Type Here!";
input.addEventListener(KeyboardEvent.KEY_UP, handler);
var output:TextField = new TextField();
addChild(output);
output.text = "other text";
output.alpha = 0.5;
output.y = 25;
function handler(e:KeyboardEvent):void {
output.text = input.text;
}

How to get text input to display text in Flash Actionscript 3

It's been forever since I've done Actionscript and we have a really old one that had to be redone in Actionscript 3.
It has a textinput for a search and a "search" button that will call a webpage when pressed.
My problem is that when I run it, I can enter text into the textinput but you don't see anything that you typed and I can't figure why. I've got the script to get the textinput as a variable and it goes to the test page, but I need to make the text visible in the SWF.
Here's my Actionscript:
import flash.events.MouseEvent;
import flash.net.navigateToURL;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import fl.controls.Label;
import fl.controls.TextInput;
var searchtext = misa_stext.text;
gosearch.addEventListener(MouseEvent.CLICK, onMouseClick);
function onMouseClick(event:MouseEvent):void
{
var searchtext = misa_stext.text;
var request:URLRequest = new URLRequest("http://stackoverflow.com?" + searchtext);
request.method = URLRequestMethod.GET;
var target:String = "_blank";
navigateToURL(request, target);
}
It does what it's supposed to do, I just want the user to see what they typed and I know I'm missing something.
UPDATE:
Here's what the properties panel says:
And what I get when embedding:
But still nothing. :(
If your input does not use system fonts, you must embed the font to support dynamic text.
Press Embed... from the text input properties
Then include character ranges as needed.

Typewriter effect with AS3

I'm trying to create a typewriter effect with AS3.
I read tutorials the hole day, but can't find, what I'm looking for....
Perhaps you can help me. - please
That's what I want:
- a typewriter text effect
- the speed can be set
- no import from an external .as file
- no import from an external .txt file (the text should be defined with a variable)
- if the textfield is full of text, it should be "scroll" down....it should jump down one line, so that theres a new empty line, where the typewriter could write....
could you actionscript gurus help me?
I always worked with as2 and it's very hard for me to get a solution in as3.. :(
thanks a lot!
Ok that sounds simple what you have is good.
firtst create the textfield that will display the final text. What you did next is adding all charackters at once, but what you want is adding each charackter after a time.
try something like:
import flash.events.TimerEvent;
import flash.text.TextField;
import flash.utils.Timer;
// the textfield guess you will add this on timeline instead of coding it...
var myTextField:TextField = new TextField();
// this is the text that should be displayed tywriterstyle
var typewriterText:String ="Hello World Typewriter";
// Charackter count and timer for timedelay between each upcoming charackter
var counter:int = 0;
var delayTimer: Timer = new Timer(300);
// starts Timer
delayTimer.addEventListener(TimerEvent.TIMER, addCharackter);
delayTimer.start();
private function addCharackter( E:Event = null ):void{
// get a single Charackter out of the String
var charackterToAdd:String = typewriterText.charAt(counter);
// add the charackter to the Textfield
myTextField.text.append(charackterToAdd);
counter++;
// if you reached the end of the String stop Timer
if(counter == typewriterText.length){
delayTimer.stop();
}
}
For text animation you can use flupie.
I think it's a better way to do.
See also this and this.
If you are a watch&learn guy this would be much convenient to you.

How do I change the width of a TextField without stretching the text?

I used to know how to do this, so, I KNOW it's possible, but I can't figure it out again. I'm altering the width of my TextField by setting the width property but that warps the text. I want to alter the width of the text field WITHOUT altering the way the font looks (obviously). I believe it has something to do with autoText or some such idiocy (why would I EVER want to warp my text?!) but I just can't recall.
myField.width = 100; // if the original width was 50 this simply stretches the field to 100, rather than adding 50 pixels into which characters can be drawn.
TIA
In the IDE, you need to
a) Double-click on the text-field. This takes you into the editing mode for the text field. Then resize it.
or
b) select the text tool and then resize it.
Resizing it using the transform tool will increase the width as if it were a shape (which is PRETTY useful in some animations, so it isn't really that idiotic)
I am guessing your problem is TextField.defaultTextFormat.
just setup a TextFormat object then on your text field setup the default text format and it should keep the text format no matter what you do to it.
You see when you change pretty much anything about a text field the text formatting gets reset and you have to reapply it. However if you setup the default text format it will take care of that automatically.
Here is a dirty little prototype.
package src
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.text.TextFormat;
public class Main extends Sprite
{
private var tx:TextField;
private var txf:TextFormat;
public function Main()
{
addEventListener(Event.ADDED_TO_STAGE, initMain);
}
private function initMain(e:Event):void
{
removeEventListener(Event.ADDED_TO_STAGE, initMain);
// setup a text format so you can keep your text the same all the time.
txf = new TextFormat('Arial', 12, 0x000000);
tx = new TextField();
tx.width = 50;
tx.text = "I want this text not to wrap so it will be resized at runtime."
// Turned this on for testing purposes only.
tx.wordWrap = true;
tx.defaultTextFormat = txf; // This line is the x factor most likely.
tx.x = 100;
tx.y = 100;
addChild(tx);
stage.addEventListener(MouseEvent.CLICK, toggleTextFieldSize, false, 0 ,true);
}
private function toggleTextFieldSize(e:MouseEvent):void
{
if (tx.width == 50)
{
tx.width = 400;
}
else
{
tx.width = 50;
}
}
}
}
Hope this is what you were looking for.
you are in the IDE right?
try doubleclicking the textfield and then use the box on the right side of the textfield to resize the whole thing without strechting the text.
** edit **
here is a code example of how resizing a TextField works:
http://wonderfl.net/c/qbDv
but this only works with dynamic TextFields. TF created with code are either DYNAMIC or INPUT but inside the IDE you can create TF that are STATIC and those can't be resized via ActionScript. So you have to change the TextField's type or create the TF via script.
Another solution would be to use a wrapper for the text field, like a Group element, and just increase its width.
You could also use a textformat and assign the left and right margin
myTextFormat.leftMargin = some number
and
myTextFormat.rightMargin = same number
as left margin.