Actionscript 3.0 Embed Font - Text Not Appearing - actionscript-3

I am creating dynamic TextFields in actionscript 3.0. Like many others, my text disappears when I set .embedFonts = true;
ArialSlim is embedded and exported for actionscript. I have successfully tested with trace(Font.enumerateFonts());
Interestingly enough, when I comment out the embed line (as shown below), the font works properly.
Alternatively, .setTextFormat(); also works properly without the .embedFonts line.
So my questions is, why? Will I run into any issues in this case?
var divArray = new Array();
var x_Lbl_Array:Array = new Array();
var entries:int = 10;
var labelFormat:TextFormat = new TextFormat();
var arial:Font = new ArialSlim();
labelFormat.font = arial.fontName;
labelFormat.size = 10;
var xVar:int = 0;
for(var loop:int = 0; loop < entries; loop++){
x_Lbl_Array[loop] = new TextField();
//x_Lbl_Array[loop].embedFonts = true;
x_Lbl_Array[loop].antiAliasType = AntiAliasType.NORMAL;
x_Lbl_Array[loop].defaultTextFormat = labelFormat;
x_Lbl_Array[loop].x = xVar;
x_Lbl_Array[loop].y = 165;
x_Lbl_Array[loop].text = "test";
mc.addChild(x_Lbl_Array[loop]);
xVar++;
}
Edit:
I just ran this code from frame 1 with .embedFonts = true; and it worked...
Maybe I should mention that I'm having trouble running this code in a method inside an instantiated actionscript class. The class is located in an external .as file. Does this help answer my question?

I tried your code and it worked for me (with the embedded font)
check if you have all the characters included.
You can either set the character range, or create a textfield that has all the characters.

It turns out that I at some point clicked "TLF (DF4)" in the outline format options for my embedded font. When I corrected this, and chose "Classic (DF3)," it fixed my problem.
I guess what I find to be really weird is that the font was showing properly without .embedFonts being set to true
Thank you, Daniel. I appreciate the help.

Related

AS3: finding an object by it Instance name in a dynamic added child

I am doing an Adobe AIR Kiosk app but I am having a little problem.
First step is to generate a webcam container:
var bandwidth:int = 0;
var quality:int = 100;
var camera:Camera = Camera.getCamera();
camera.setQuality(bandwidth, quality);
camera.setMode(885,575,30,true);
var video:Video = new Video(885,575);
video.attachCamera(camera);
video.name = "camara";
webcam.addChild(video);
It works ok, the problem is that I want to apply to it a custom filter
It works ok if I write it this way:
MovieClip(parent).contenedor_postal.postal.webcam.filters = [filter];
But I want to affect only the child inside the clip "webcam" without affecting other MC's, so I write it like this:
MovieClip(parent).contenedor_postal.postal.webcam.camara.filters = [filter];
and does not work. I used to program in AS2, so maybe the trick is very simple but I can't find anything that works. Thanks in advance!
If the video has a name property "camara" then this should work:
MovieClip(parent).contenedor_postal.postal.webcam.getChildByName("camara").filters = [filter];

Embedded fonts not appearing in actionscript created textfields

I would like to preface this wall of text by saying, I am very new at this. I may be missing something obvious.
I'm working in Flash CS5 with Actionscript 3. I'm trying to use actionscript to create a textfield, and populate it with text. I've embedded my font in my project using the "Font Embedding" window. However, when the code to create the textfield is run, if "embedFont = true;", the font is invisible. The cursor still changes when hovering over it, so I know it's there. Or at least its text box is, I guess. Dynamic textfields with embedded text which are already on the stage seem to be unaffected.
I've tried changing the embedded fonts outline format, neither work. I've tried directly embedding the font with the "embed" tag via actionscript, but it doesn't seem to work with CS5, or I don't know what I'm doing. As you can see in the code provided, I've tried "registering" the font, with no success. I've tried using:
var font:Font = new screenfont(); //"screenfont" is the name from Embedding Fonts
var format:TextFormat = new TextFormat();
format.font = screenfont.fontName;
No dice.
I've followed some different tutorials about embedding, and come across a wealth of conflicted, confusing information. I've read a few different posts pertaining to this subject, but haven't found any viable solutions as of yet.
Here's a simple version of my code, where "screenfont" is the name I specified in the Embedding Fonts window:
Font.registerFont(screenfont);
//TextFormat
var listformat:TextFormat = new TextFormat();
listformat.align = TextFormatAlign.LEFT;
listformat.size = 20.8;
listformat.color = 0x0DAC54;
listformat.font="Fixedsys Excelsior 3.01";
//TextField
var photolist:TextField = new TextField();
photolist.x = photos_x;
photolist.y = tempY;
photolist.width = photos_wdth;
photolist.height = photos_hght;
photolist.text = photoname;
photolist.embedFonts = true; //<--- This freakin' guy!
photolist.antiAliasType = AntiAliasType.ADVANCED;
photolist.defaultTextFormat=listformat;
photolist.selectable = false;
photolist.wordWrap = true;
mediapage.photos.addChild(photolist);
I hope this provides a clear picture.
So, how exactly is embedding accomplished in CS5?
You should set the text as the last thing you do. So this line photolist.text = photoname; should be after everything else.
var photolist:TextField = new TextField();
photolist.x = photos_x;
photolist.y = tempY;
photolist.width = photos_wdth;
photolist.height = photos_hght;
photolist.embedFonts = true;
photolist.antiAliasType = AntiAliasType.ADVANCED;
photolist.defaultTextFormat=listformat;
photolist.selectable = false;
photolist.wordWrap = true;
photolist.text = photoname;//<-- set text only after applying all formatting and embedding
mediapage.photos.addChild(photolist);

flash as3 and external text config file

My goal was to have an external text file config for a client. I didnt want to go through a crazy xml thing, I just wanted it to be simple to change.
I started with a urlLoader, and was able to dynamically generate an object no problem. This is the function which parses and sets the properties of the object.
function onLoaded(e:Event):void//initializes the config
{
var myString = String(e.target.data);
//trace(e.target.data);
//trace(myString);
var propsArray:Array = myString.split("\n");
for (var i = 0; i < propsArray.length; i++){
var thisLine:Array = propsArray[i].split("=");
var thisPropName:String = thisLine[0];
thisPropName = thisPropName.replace(rex,'');
var thisPropValue:String = thisLine[1];
thisPropValue = thisPropValue.replace(rex,'');
trace("thePropName is: " + thisPropName);
trace("thePropValue is: " + thisPropValue);
config[thisPropName] = thisPropValue;
}
}
The text file would just look something like:
gateway = "http://thePathto/theFile.php
toast = sonofabitch
timer = 5000
xSpeed = 5.0
That way, I could just put a little bit of as3 code in, type what things I wanted configured, then all I would have to do was type config.timer and
var myTimer:Timer = new Timer(Number(config.timer));
I think the problem is load order and scope. The config.timer is not created yet, so the timer is unable to access the value of the config.timer.
I'd look at using XML in future projects of this nature, however to answer your question:
I think the problem is load order and scope. The config.timer is not created yet, so the timer is unable to access the value of the config.timer.
Correct, you will need to initialize your Timer within the onLoaded() method, as the data will be received asynchronously and is not available until this happens.
ok not long ago i had created a download manager that uses this exact concept.
The link below will take you straight to the website where you can download the full swf including my source files. also this website is a good place for resources
http://ffiles.com/flash/web_applications_and_data/dynamic_download_manager_3529.html
Below is my loader:
addEventListener(Event.ENTER_FRAME, update);
var myLoader:URLLoader = new URLLoader();
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
myLoader.load(new URLRequest("settings.txt"));
myLoader.addEventListener(Event.COMPLETE, onDataLoad);
function onDataLoad(evt:Event)
{
box1.text = evt.target.data.Id_1;
box2.text = evt.target.data.Id_2;
box3.text = evt.target.data.Id_3;
box4.text = evt.target.data.Id_4;
box5.text = evt.target.data.Id_5;
}
Add some dynamic text boxes to stage and name them "box1, box2 ect..."
Now creat your text file:
Id_1=this is what ever you want
&Id_2=this is what ever you want
&Id_3=this is what ever you want
&Id_4=this is what ever you want
&Id_5=this is what ever you want
Hope this helps.

AS3: Embedding characters

I having some trouble with TextFields and caracter embedding. As I have understood, the way to embed character in Flash, is to have a TextField in a movieclip that is exported to actionscript via some classname. Then have the TextField embed the characters.
But when i try to use that TextField in my project, I cannot auto resize the field any longer!? Is there a better way to embed charactes? or am I missing some unknow attribute? (and yes i have tried TextField.autoSize = "left" (or "center" or "right")).
The TextField is configured like this in Flash CS4:
Properties:
http://screencast.com/t/0VB6KnNO6G
Library implementation:
http://screencast.com/t/w3yQLqit0veI
And I embed the MovieClip containing the TextField like this:
protected var tabname:MovieClip = new Text(); // The property on the object
Adding the text and setting its Settings:
var txt:TextField = tabname.txt;
if( !contains(tabname) )
{
addChild(tabname);
var format:TextFormat = new TextFormat();
format.bold = true;
format.font = "Arial";
format.size = 12;
format.align = "left";
var dropShadow = new DropShadowFilter(0);
dropShadow.color = 0xFFFFFF;
dropShadow.strength = 2;
dropShadow.blurX = dropShadow.blurY = 5;
dropShadow.alpha = .7;
txt.type = TextFieldType.DYNAMIC;
txt.multiline = tabname.wordWrap = false;
txt.autoSize = TextFieldAutoSize.LEFT;
txt.defaultTextFormat = format;
txt.filters = [dropShadow];
txt.mouseEnabled = false;
txt.x = 10;
}
txt.text = value;
txt.y = Math.ceil((tabmask.height - txt.height) /2);
To embed fonts, don't rely on wrapping them in MovieClips in the library. They should be embedded correctly as Fonts. I have included some basic steps below for embedding fonts, then an example for your particular situation:
1 - Make the textfield Dynamic and click the Embed.. button
2 - Name the font with something meaningful (like the fonts name) and tick the character sets you will be using (usually I select caps, lowercase, numbers and punctuation). Also note the Style is 'Bold', you will need to embed a font set for each style. So if you want to use Bold and Regular, you need to embed 2 fonts.
3 - If you plan on adding textfields dynamically through ActionScript, goto the ActionScript tab and add a class for it (again, use a meaningful name)
4 - Finally click ok, and away you go. I have setup an example, using these steps, and the auto size method, you can see the results below
In Flash, you can click the [Embed...] button below the TextField's character properties. In the window that you get then, you can specify which characters you want embedded in your textfield.
There's a lot more to say about font embedding but this is the simple story. Flash CS5 added TLF TextFields but I don't think you were referring to those, right?
The autoSize property really has nothing to do with font embedding but I guess your TextField is not Dynamic when you cannot auto resize it?
Are you using CS5 or CS4 or earlier by the way?

flex: Create a screenshot of UI element

I want to make a screenshot of custom as3 ui element (which was extended from Canvas), and then upload the image on the server.
Could you help me with a small example of this?
I am trying to do the following:
// This is UI component extended from Canvas
var chessBoard:ChessBoard = new ChessBoard();
// I displayed pieces on the board, but didn't add it to the stage (I just need a
// a screenshot, not need them on the canvas)
chessBoard.displayPosition(DataStorage.getInstance().getStoredPosition(0));
var img:ImageSnapshot = ImageSnapshot.captureImage(chessBoard, 300, new PNGEncoder());
var obj:Object = new Object();
obj.complexity = complexity.value;
obj.img = img;
httpService.send(obj);
and getting this error:
ArgumentError: Error #2015: Invalid
BitmapData. at
flash.display::BitmapData() at
mx.graphics::ImageSnapshot$/captureBitmapData()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\graphics\ImageSnapshot.as:186]
at
mx.graphics::ImageSnapshot$/captureImage()[C:\autobuild\3.2.0\frameworks\projects\framework\src\mx\graphics\ImageSnapshot.as:282]
at
ui::SendForm/send()[/Users/oleg/Documents/chess_problems/problemme/src/ui/SendForm.mxml:53]
at
> ui::SendForm/___SendForm_Button1_click()[/Users/oleg/Documents/chess_problems/problemme/src/ui/SendForm.mxml:16]
This error was caused by missing width and height of the Canvas. I set them and it helped to create bitmap data this way:
var bitmapData:BitmapData = new BitmapData(chessBoard.width,chessBoard.height);
var encoder:PNGEncoder = new PNGEncoder();
var data:ByteArray = encoder.encode(bitmapData);
I wonder how do I send the image to the server via httpService? Is there a way. Also is data = image file?
Here is a post on someone who has done this exact thing in AS3:
Dynamically Create an Image in Flash and Save it to the Desktop or Server
It is possible, and although I have never done it, this may be useful to you: http://www.flash-db.com/Tutorials/snapshot/