How to get text input to display text in Flash Actionscript 3 - 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.

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.

Can't have 2 dynamic text fields AS3

This is not a specific situation, this is something that happens a lot to me.
Whenever I have dynamic text (that changes through code, of course) everything works fine.
However, when I add a second Dynamic text, both of them do not show.
An example scenario would be:
textfield1.text="hello";
and on the next frame
textfield2.text="goodbye";
no text would show.
Something is wrong with flash, maybe. The problem starts when I add another textbox to the stage.
I do not want to upgrade to a newer flash, but I could if I have to.
If anybody knows how to fix my problem, please tell me.
I think that embed fonts is optional if you create and add an instance of TextField trough AS3 (excepts if you specify a font that is not present on another computer).
In the example here bellow, the text for textfield1 and textfield2 is always displayed, so I probably misunderstand your question.
Best regards.
Nicolas
PS : the "var timer:Timer" and the callback function are only used to make this example switch an loop from frame 1 to frame 2
Example 1
frame 1:
import flash.utils.Timer;
import flash.events.TimerEvent;
if (! textfield1 && ! textfield2)
{
import flash.text.TextField;
import flash.geom.Point;
var textfield1:TextField = new TextField();
var textfield2:TextField = new TextField();
var tfPosition:Point = new Point(100,50);
}
try{
removeChild(textfield2);
}catch(e:Error){
(trace (" ERROR : textfield2 is not already added"));
}
addChild(textfield1);
textfield1.x = tfPosition.x;
textfield1.y = tfPosition.y;
textfield1.text = "hello";
stop();
function playStop(te:TimerEvent):void{
play();
}
if(!timer){
var timer:Timer=new Timer(1000);
timer.addEventListener(TimerEvent.TIMER,playStop);
timer.start();
}
frame 2 :
removeChild(textfield1);
addChild(textfield2);
textfield2.x = tfPosition.x;
textfield2.y = tfPosition.y;
textfield2.text="goodbye";
stop();
Example 2
If you have two instances of a TextField manually placed on the Timeline, that you select "use device fonts" and the names for the instances are really called "textfield1" on the first frame and "textfield2" on the second frame.
(I've done it by copy and paste in place and didn't get any issue neither).
This works on CS6 too... The text is well displayed
So give us more details please.
Instance of TextField on frame 1 named "textfield1"
code on frame 1 :
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.text.TextField;
textfield1.text = "hello";
stop();
function playStop(te:TimerEvent):void {
play();
}
if (! timer)
{
var timer:Timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER,playStop);
timer.start();
}
Instance of TextField on frame 2 named "textfield2"
code on frame 2 :
textfield2.text="goodbye";
stop();

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

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.

Text Input reading a Color Picker value AS3

So I am trying to code a Text Input to display the decimal color value. I have one color picker and one text input. Here is my code.
//Import
import flash.display.MovieClip;
import fl.controls.TextInput;
import fl.controls.ColorPicker;
import fl.events.ColorPickerEvent;
//Variables
var ColorPickerThing:ColorPicker
this.ColorPickerThing.addEventListener(ColorPickerEvent.CHANGE,ColorCode);
function ColorCode(event:ColorPickerEvent):void {
this.ColorValue.text = this.ColorPickerThing.selectedColor;
}
So in the end I want the decimal value for any color I pick to show up in the text input.
http://i.stack.imgur.com/1P86M.png
So if anyone could help it would be greatly apreciated. :)
I need help as this doesn't work. :/ I was hoping I could make it on my own but sadly my knowledge is limited. So I need help on making it work.
I think the problem is that you haven't properly assigned any instance names and wired them to your variables in your code properly.
Try this code:
//Import
import flash.display.MovieClip;
import fl.controls.TextInput;
import fl.controls.ColorPicker;
import fl.events.ColorPickerEvent;
//Variables
var ColorPickerThing:ColorPicker = my_color_picker;
this.ColorPickerThing.addEventListener(ColorPickerEvent.CHANGE, ColorCode);
function ColorCode(event: ColorPickerEvent):void {
this.my_color_picker_value.text = this.ColorPickerThing.selectedColor.toString();
}
And on your stage, set the instance name of the text field you are using to display the selected color to be 'my_color_picker_value' and set the instance name of the actual color picker component to be 'my_color_picker'.
Using your code as a starting point, I was able to create a working example in Flash CC using the code I've provided to you above. In my example, when you select a color in the color picker component, the decimal value of that color is shown in the text field. Is that what you wanted?

Scrollbar not working with TLF text with dynamic content in ActionScript 3

I'm creating a simple Flash project with Flash CS5 and ActionScript 3.
What I want to do is that I want to dynamically update a TLF text container with given source and destination, something like loadData(text_placeX, "markup.xml"); anywhere that I want.
It's working like a charm, but the problem is I can't use any scroll-bar for my text. I have added a UIScrollBar to text container and it's working with the default text that I've putted into text container, but when I update container with my data it's not working. What am I missing?
Another question is that how I can empty my text container before loading new data in it?
My code is:
import fl.text.TLFTextField;
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
import flash.text.TextFieldAutoSize;
import flashx.textLayout.container.ContainerController;
import flashx.textLayout.elements.TextFlow;
import flashx.textLayout.conversion.TextConverter;
import fl.controls.ScrollBar;
var ldr:URLLoader = new URLLoader();
var flow:TextFlow = new TextFlow();
function loadData(text_place, fileURL:String):void {
text_place.border = true;
ldr.dataFormat = URLLoaderDataFormat.TEXT;
ldr.addEventListener(Event.COMPLETE, function(evt:Event){ ldr_complete(text_place) }, false, 0, true);
ldr.load(new URLRequest(fileURL));
ldr.addEventListener(IOErrorEvent.IO_ERROR, loadError);
}
function ldr_complete(text_place:TLFTextField):void {
ldr.removeEventListener(Event.COMPLETE, ldr_complete);
ldr.removeEventListener(IOErrorEvent.IO_ERROR, loadError);
initText(text_place, ldr.data);
}
function loadError(e:IOErrorEvent):void {
trace("Error loading an external file. The server may be busy. Try refreshing the page.");
}
function initText(text_place:TLFTextField, fileContent):void {
flow = TextConverter.importToFlow(fileContent, TextConverter.TEXT_FIELD_HTML_FORMAT);
flow.flowComposer.addController(new ContainerController(text_place, text_place.width, text_place.height));
flow.flowComposer.updateAllControllers();
}
UPDATE: When I skip using of initText function contents and instead I use text_place.tlfMarkup = fileContent; it works; but my option on TextFlow is missing. And also I was missing "update scrollbar" after putting content in text-field.
I think this line may be the problem:
ldr.addEventListener(Event.COMPLETE, function(evt:Event){ ldr_complete(text_place) }, false, 0, true);
You have an anonymous function here (function(evt:Event){...) which passes the object text_place to the function ldr_complete(). However, you do not have access to text_place, since it is a variable declared within a different scope. If you make the function into a named one, you will not assume that you have that access. E.g.,
function loadCompleteHnd(evt:Event):void{
[...]
}
However, you still have to gain access to the object in text_place. So, you can make text_place a class-level (global) variable, and set that variable whenever. But that may run the risk of creating a race condition -- if you have a slow load, you might be trying change that object from two places at once.
Another option is to create an entirely new Event which extends the Event.COMPLETE setup. At that point, you can create another parameter for the Event.COMPLETE listener to use. This is complicated, and a bit of a learning curve, but it makes events more versatile.
In either case, you may want to set up a flag that tells you whether something else is editing the same object. It's not foolproof, but it can save some headaches.