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

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.

Related

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.

Flash AS3 ComboBox Dropdown Hover Color

Hi everyone I am currently working on designing a flash program using adobe flash cs6 and as3. I cannot for the life of me figure out how to change the dropdown default light blue hover color in a comboBox component. I have changed all the other colors I need but that. Also I was able to change the font color when hovered over using the code below.
This is merely a design constraint and isn't affecting my program in any other way except for uniformity. Any help would be GREATLY appreciated!
import fl.events.*;
import fl.managers.*;
import fl.controls.*;
import fl.controls.listClasses.*;
stop();
var standard = new TextFormat();
standard.color = 0x000000;
StyleManager.setStyle("standard",standard);
var hover_color = new TextFormat();
hover_color.rollOverColor = 0xff0000;
StyleManager.setStyle("hover_color",hover_color);
StyleManager.setComponentStyle(ComboBox,"textFormat",StyleManager.getStyle("standard"));
StyleManager.setComponentStyle(TextInput,"textFormat",StyleManager.getStyle("standard"));
// comboBox labelField
StyleManager.setComponentStyle(CellRenderer,"textFormat",StyleManager.getStyle("standard"));
FGOne_cb.dropdown.addEventListener(ListEvent.ITEM_ROLL_OVER, rollOverListener);
FGOne_cb.dropdown.addEventListener(ListEvent.ITEM_ROLL_OUT, rollOutListener);
function rollOverListener(e:ListEvent)
{
var cr:CellRenderer = e.target.itemToCellRenderer(e.item) as CellRenderer;
cr.setStyle("textFormat",StyleManager.getStyle("hover_color"));
}
function rollOutListener(e:ListEvent)
{
var cr:CellRenderer = e.target.itemToCellRenderer(e.item) as CellRenderer;
cr.setStyle("textFormat",StyleManager.getStyle("standard"));
}
While it looks like you're trying to this by code. In FlashPro, you can style all the component skins by editing their symbols.
They can be found in your library under Component Assets
The specific one you're looking for is likely under Component Assets -> Shared -> focusRectSkin
Or maybe the comboBox_downSkin

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.

embedding a font in a swf using as3

I have a project using flash (and AIR for android and eventuall iOS) for translating some phrases. Although most fonts are fine there are some that I have to load after the user has chosen the languages. Over a year ago I generated a couple of swf files (Bengali and Urdu) and put them on my web server. The flash application then loads them when required and everything is OK...
However as I am nearing implementing the project I thought I should generate the swf files for the other languages that are in the pipeline and for some reason I can't manage it! Needless to say I have misplaced (tidied) the original AS3 source for the two fonts I have done.
package
{
import flash.display.Sprite;
import flash.events.Event;
public class ArabicF extends Sprite
{
[Embed(source = "trado.ttf",
fontName = "ArabicX",
fontFamily = "ArabicY",
fontWeight = "normal",
fontStyle = "normal",
mimeType = "application/x-font",
advancedAntiAliasing="true",
embedAsCFF="true")]
public static const ArabicZ:Class;
}
}
This has expanded from a much simpler form as I added things to get it to work and I must have tried all permutations of true and false. I load the swf ok but then can't extract the class. With the two fonts I embedded before the swf class and the parameter all have the same name and they work fine (i.e.
Urdu.swf
then later:
var FontClass:Class = evt.target.applicationDomain.getDefinition("Urdu") as Class;
and then
Font.registerFont(FontClass.Urdu);
in the calling .as application with the above Arabic.swf I try
trace("1 Arabic "+evt.target.applicationDomain.hasDefinition("ArabicF"));
trace("2 Arabic "+evt.target.applicationDomain.hasDefinition("Arabic"));
trace("3 ArabicX "+evt.target.applicationDomain.hasDefinition("ArabicX"));
trace("4 ArabicY "+evt.target.applicationDomain.hasDefinition("ArabicY"));
trace("5 ArabicZ "+evt.target.applicationDomain.hasDefinition("ArabicZ"));
but all return false
PS also tried generating the Arabic.swf using fontswf.bat which again seems to make a very similar swf file which is loaded but I can't extract the class from it
PPS I'm using flashdevelop and the font swf are set up as AS3 standard project compiler options.
I don't use Flash Develop, but perhaps I can offer some perspective from my implementation.
If I wanted to embed Arial, the embedding swf would "Export for ActionScript" the embedded font. In its document class, use registerFont() as below:
Font.registerFont(Arial);
Like every other swf, you'd use a Loader to import it into your runtime, and at that point, the font will be available to your global table. You can query the complete list of registered fonts using enumerateFonts().
var fontList:Array = Font.enumerateFonts();
for (var i:int = 0; i < fontList.length; i++) {
trace(fontList[i].fontName);
}
Assuming we've got a TextField called "txt", you can then implement that font with setTextFormat() like so:
var format:TextFormat = new TextFormat();
format.font = "Arial";
txt.embedFonts = true;
txt.antiAliasType = AntiAliasType.ADVANCED;
txt.setTextFormat(format);
txt.defaultTextFormat = format;
A disclaimer from Adobe on the use of these last two settings:
"When you apply a TextFormat object to a text field using the
TextField.defaultTextFormat property or the TextField.setTextFormat()
method, only its defined properties are applied. Use the
TextField.defaultTextFormat property to apply formatting BEFORE you
add text to the TextField, and the setTextFormat() method to add
formatting AFTER you add text to the TextField."
As I said before, my workflow doesn't utilize Flash Develop, but rather Flash IDE to embed the fonts into the swfs. Your results may vary, but be aware you must set embedFonts to true, or it won't respond to your embedded font. I've lost hair on that issue before.
Hope that helps. Cheers,
OK In case someone else runs into similar problems this is stage one of the answer (really the answer to my original question) still have to sort out how to get the font to be used in the flash.font.engine apparatus!
The critical parts are:
Point #1. the embedded font swf must have a name that doesn't clash with ANY name registered in the calling script. Bizzare and (as far as I could search) undocumented. i.e. I have a list of languages uploaded via xml services to an xml object and that includes for instance 'English' however the font loading doesn't work until I make the loadable font file into 'EnglishF.swf' The obvious choice of just 'English.swf' fails. So my embedded font source is now called EnglishF.swf and reads:
package
{
import flash.display.Sprite;
import flash.text.Font;
import flash.system.Security;
Security.allowDomain("*");
/**
* ...
* #author patrick
*/
public class EnglishF extends Sprite
{
[Embed(source = "Kingthings Exeter.ttf",
fontName = "EnglishF",
fontFamily = "EnglishF",
fontWeight = "normal",
fontStyle = "normal",
mimeType = "application/x-font",
advancedAntiAliasing="true",
embedAsCFF="true")]
public static var myFont:Class;
}
}
and the using script goes:
private function fontLoaded(evt:Event):void {
var FontClass:Class
if (evt.target.applicationDomain.hasDefinition(font1Name)) FontClass = evt.target.applicationDomain.getDefinition(font1Name) as Class;
else if (evt.target.applicationDomain.hasDefinition(font2Name)) FontClass = evt.target.applicationDomain.getDefinition(font2Name) as Class;
try {
Font.registerFont(FontClass.myFont);
trace("successfully loaded " + FontClass);
} catch (err:Error) {
trace("couldn't register font "+FontClass.myFont+" =>"+err);
}
}
The line in the embedded script about security is because of point #2: the registerFont doesn't work across domains. In fact the Security.allowDomain() didn't work and to debug this I have had to copy/paste the swf files on the PC and change the loader.load(URLRequest()) accordingly
There is still an issue that although the font is registered and claims to be compatible with the flash.text.engine TextElement requirements it still fails to be used as in:
_tl = new Array();
var block:TextBlock = new TextBlock();
var font:FontDescription = new FontDescription(fontName);
var formt:ElementFormat = new ElementFormat(font, fontSize);
//following gives 'true EnglishF'
trace(FontDescription.isFontCompatible(fontName,"normal","normal"), formt.fontDescription.fontName);
formt.color = colr;
var span:TextElement = new TextElement(text, formt);
block.content = span;
_tl[0] = null;
_tl[0] = block.createTextLine(null, width);
var tl:TextLine;
// after here justification and addition lines
I will post something if and when I sort out why this doesn't work (Unless some kind person does it for me!)

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.