I'm trying to create dynamic textfield with font embedding. Embeding is dynamic like this:
public class TextFormats extends TextFormat {
private var TF:TextFormat = new TextFormat();
[Embed(source = "/fonts/tahoma.ttf", fontWeight = "normal", fontFamily = "tahomaNormal")]
var fontTahoma:Class;
private var fTahoma:Font;
public function TextFormats():void {
fTahoma = new fontTahoma();
}
public function format(fmb:String):TextFormat {
TF.letterSpacing = -1;
TF.font = fTahoma.fontName;
switch(fmb) {
case "combolist_label":
TF.color = 0x383838;
TF.size = 13;
TF.letterSpacing = 0;
break;
}
return TF;
}
}
When I compile it in flash CS4, embeded text appears on stage fine! But, when I tried to compile it with flash CS5, the text do not appear and no error warnings.
What is the reason? Should I use another methods for font embeding?!
There are a few articles published about the big difference in font embedding that is new in CS5. I think this one is quite good:
Having trouble with embedded fonts and HTML text in Flash CS5?
The manner in which fonts are embedded is an improvement in CS5 -- but it means that all your CS5 dynamic text fields break when you open the FLA for editing in CS5! Which sucks! (Everything still works fine as deployed in SWFs.)
If you open the CS4 FLA in CS5, you basically need to rebuild the dynamic text fields and reapply the embedding.
There is code here:
import flash.text.*;
var font:Font1=new Font1();
var txt_fmt:TextFormat=new TextFormat();
txt_fmt.font=font.fontName;
txt_fmt.size=24
var txt:TextField=new TextField();
txt.autoSize=TextFieldAutoSize.LEFT;
txt.defaultTextFormat=txt_fmt;
txt.embedFonts=true
txt.text="Designscripting.com"
txt.selectable=false
addChild(txt);
Related
So I have a SWF embedded in my AS3 project, but when I try to do anything with it, it says it's null.
The code looks like this:
[Embed(source = "../lib/Introduction.swf", mimeType = "application/octet-stream")]
public var introClass:Class;
(after a bunch of irrelevant stuff...)
var intro:MovieClip = new introClass() as MovieClip;
intro.play();
(The error message it gives me is a standard #1009 error.)
I've tried a bunch of stuff including using Loaders, not using MovieClip, etc, but at best, only the audio (not the video) of the SWF loads up, and at worst, the entire application crashes when the SWF tries to load. How do I get the SWF to be recognized?
(I'm using FlashDevelop if that helps.)
You can do this:
[Embed(source="asset.swf", symbol="symbol")]
private var symbolClass:Class;
var symbol:MovieClip = new symbolClass();
If you want to embed a symbol from an art SWF.
Instead if you want to import animations this is the solution:
[Embed(source="/loading.swf", mimeType="application/octet-stream")]
public var LoadingAnimation : Class;
// allows us to import SWFs to use as animations
var context : LoaderContext = new LoaderContext (false,
ApplicationDomain.currentDomain);
context.allowCodeImport = true;
var loader : Loader = new Loader ();
loader.loadBytes (new LoadingAnimation (), context);
I'm using Flash Pro, CS6 on the Mac.
I've got this class
package classes
{
public class AssetEmbeds_1x
{
//kid
[Embed(source = '../graphics/Player_Graphics.swf')]
public static const playerG:Class;
}
}
Which is a swf which contains an exported (on 1st frame) movieclip called kidCharacter. I'm trying to access that kidCharacter movieclip from another class, and I'm not able to do that.
I've tried this...
var textureClass:Class = AssetEmbeds_1x;
var newClass = textureClass['playerG'];
myGraphic = newClass['kidCharacter'];
But it's not working, myGraphic (which is a movieclip) is always null. I'm not sure if it's even embedding anything.
Try this:
var player:MovieClip = new AssetsEmbeds_1x.playerG();
var kid:MovieClip = player.root.kidCharacter;
I create an AS3 TextField set to Input mode dynamically through code, but when the user tries to input some special characters (eg. á à é è í ì ó ò ú ù ç) they simply do not appear on the TextInput.
Copying and pasting them to the textfield works, but I'd prefer if the user could directly type them.
Here's a quick test demonstrating this:
package
{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
public class TextInput extends Sprite
{
public function TextInput()
{
super();
var t:TextField = new TextField;
t.type = TextFieldType.INPUT;
addChild(t);
}
}
}
This creates a textfield where the user can type, but I can't type special characters like à.
Many thanks.
If you can paste it into the Input field, you should be able to type it.
If you start a new Flash document, using the same font as you are above create an Input textfield on the stage with the following settings:
Embed the normal glyphs
Embed the extended latin glyphs
And this should work, as:
Now if all this works, it might have something to do with the way the class is written.
Writing classes that embeds fonts is frankly a pain. Make sure you embed the font in the library and export it for action script:
Following that, you need to use the following code:
// The name of the font class
var _font:Calibri = new Calibri();
var _textFormat:TextFormat = new TextFormat();
_textFormat.font = _font.fontName;
_textFormat.size = 16;
// For some weird reason the ordering here is important. I remember mucking around with this for ages for an old project. EmbedFonts must come last
var _textField:TextField = new TextField();
_textField.defaultTextFormat = _textFormat;
_textField.type = TextFieldType.INPUT;
_textField.embedFonts = true;
addChild(_textField);
And that should have it all working:
** EDIT **
To those using FlashDevelop, etc you can use the following method:
public class Main extends MovieClip {
[Embed(source='assets/HOBOSTD.OTF', fontName='_hobo', embedAsCFF="false")] public static const HOBO:Class;
public function Main() {
var _font:Font = new HOBO() as Font;
var _textFormat:TextFormat = new TextFormat();
_textFormat.font = _font.fontName;
_textFormat.size = 22;
var _textField:TextField = new TextField();
_textField.embedFonts = true;
_textField.defaultTextFormat = _textFormat;
_textField.autoSize = TextFieldAutoSize.LEFT;
_textField.antiAliasType = AntiAliasType.ADVANCED;
_textField.type = TextFieldType.INPUT;
addChild(_textField);
}
}
And you will get the following:
Now note, the font file must be either relative to your project, or the source can point to the C:\windows\font folder if you choose. In the above example, I copied the font to my assets folder.
I'm developing an Blackberry Playbock app with ActionScript 3.0. I'm very very new with this.
I have the following project structure (I'm using Adobe Flash Builder "Burrito"):
project
|
src
|
assets
|
images
On image folder I have several PNGs images that I want to load programmatically.
How can I do that?
And
What GUI component I must use to show an image?
This example loads one image and uses buttons to change it:
// create a Loader object to hold things that you will load
var myLoader:Loader = new Loader();
// position the Loader
myLoader.x = 250;
myLoader.y = 0;
// put something into the Loader
myLoader.load(new URLRequest("tree.jpg"));
// make the Loader visible
addChild(myLoader);
// button listeners
top_btn.addEventListener(MouseEvent.CLICK, loadPhoto);
last_btn.addEventListener(MouseEvent.CLICK, unloadAny);
// button functions
function loadPhoto(e:MouseEvent):void {
myLoader.load(new URLRequest("sailboat.jpg"));
addChild(myLoader);
}
// this function empties the Loader object
function unloadAny(e:MouseEvent):void {
removeChild(myLoader);
}
Use the Loader class.
if u want to show multiple image using for loop then follow this code:
var IMAGE_URL:String = new String("image/");
for(var i=1;i<=13;i++){
addChild(imageLoder(i,i*25));
}
private function imageLoder(ranvalue:int,cor:int):Loader{
var ldr:Loader = new Loader();
ldr.load(new URLRequest(IMAGE_URL+ranvalue+".jpg"));
var xcord=5;
var ycord=5;
ldr.x = cor;
ldr.y = ycord+20;
return ldr;
}
Is text anti-aliasing controlled by code, or is it embedded? What I want to do is take a swf file that someone else has made, find all of the text in the swf file and change all of the anti-aliasing modes from animation to readability. Does it work that way in as3? I honestly haven't tried any anti-aliasing in code yet.
you can set the antiAliasType of a textfield to 'advanced', which gives you fine control over sharpness and thickness. however, the fonts must be embedded (inclusive: the textfield must have embedFonts set to true, the TextFormat objects must have font properties exactly equal to the fontName of the embedded font, and the fonts must be already compiled). so technically 'is it possible?' - yes. is it likely to work the way you want it to? no, unless you plan on working with a swiff that you know is using embedded fonts already. then you'll need to grab all the textfields from the loaded swiff (you could use something like this: http://upshots.org/?p=107, then use array.filter to get back only TextField objects), then apply your logic.
EDIT: adding code sample
// assuming you're using the DisplayList class linked above
var request:URLRequest = new URLRequest("textfields.swf");
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler, false, 0, true);
loader.load(request);
function completeHandler(event:Event):void{
var content:DisplayObjectContainer = event.target.loader.content as DisplayObjectContainer;
addChild(content);
var children:Array = new DisplayList(content);
children = children.filter(function(item:Object, index:int, array:Array):Boolean {
return item is TextField;
});
children.forEach(function(item:Object, index:int, array:Array):void {
var textfield:TextField = item as TextField;
textfield.antiAliasType = AntiAliasType.ADVANCED;
textfield.sharpness = 100;
textfield.thickness = 100;
});
}
just ran a quick test - works as described.