Entries categorized as ‘Flash’
Fonts are a real pain to deal with in flash. To do anything useful with them you have to embed them.
For example, you can’t change a textfields alpha without embedding it, or using some hack like turning it into a bitmap and changing the alpha on that. Look at this previous post for how to embed the fonts for alpha control.
I have ttf fonts working as such:
[Embed(source = "C:/Windows/Fonts/Verdana.ttf", fontName = "verdana")]
public static var verdana:Class;
Font.registerFont(AssetManager.HelveticaULE);
but OTF won’t work in the same manner. I have tried using systemFont as well, but this is also a pain for various reasons.
I am simply trying to convert these OTF fonts to TTF, and can’t find many reliable windows programs. Widows makes everything a pain.
FontForge allows you to convert easily but naturally it is open source and Linux. I am working on installing Cygwin the project that tries to create a Unix like environment on Windows.
http://cygwin.com/
But this is another pain. These days I’ve been wondering how useful a Mac would be at this point.
Categories: Actionscript 3 · Flash · Linux
Assigning dynamic variable names to objects created in a for loop in AS3.
You have to get very creative to search these questions on google because words like “for” and “loop” are so utterly common.
If you have a loop in AS3 creating multiple variables but need them to have unique names (for later modification) you need to create something like an array to store the references.
For example, anything you create in a for loop is a temporary reference. It disappears after the loop is complete, and whatever objects were created stick around in the displayObject.
In my situation I had a loop creating my navigation elements, but needed to position each ones X positions separately.
Anyways, here is one way to reference them:
private var mcArray:Array = new Array(); // DEFINE ARRAY FIRST
private function myfunction():void{
for (var i:int=0; i<2; i++) { // THE FOR LOOP
var movieClip:MovieClip = new MovieClip(); // TEMPORARY VARIABLE
addChild(movieClip);
mcArray[i] = movieClip; // here is where we add the movieClip references to the array for later use
}
}
Now, to use those references:
mcArray[0].METHOD_HERE;
or
for (var i:int=0; i<2; i++) {
mcArray[i].do_something = something;
}
To be absolutely clear, the above example creates two MovieClips according to the loop (while i < 2), and places each MovieClip in the mcArray array at index i (which we have defined as the integer counting the loop).
Now if I wanted to access something in those MovieClips I could use the mcArray to do so.
mcArray[0].graphics.beginFill(0x555555,1);
mcArray[0].graphics.drawRect(0,0,900,300);
mcArray[0].graphics.endFill();
or loop through the array and so something (like applying an animation to each and every mc in the Array
simple as that.
www.anuvawines.com
Categories: Actionscript 3 · Flash
Tagged: Actionscript 3, Array, AS3, Dynamic Variable, MovieClip
Did updating to SVN Tweener break everything?
I had downloaded Tweener from http://code.google.com/p/tweener/ a few months ago but needed to use it on a few GlowFilters. After doing some research I find out that the SVN trunk has support for GlowFilter and various other special properties.
After updating Tweener the rest of my Tweens broke. I started getting these errors:
## [Tweener] Error: The property ‘_blur_blurX’ doesn’t seem to be a normal object property of [object MovieClip] or a registered special property.
I looked into caurina.transitions.properties.FilterShortcuts and saw that they were labeled _Blur_blurX (capitalized letter) but that didn’t solve the problem.
I finally stumbled upon a forum post saying you must manually initialize the shortcuts so they are registered as specialproperties.
Basically, import whatever properties branch you need, like
import caurina.transitions.properties.FilterShortcuts
Then, before you use Tweener:
FilterShortcuts.init();
Done. It all works as it used to.
Tweener.addTween( mc, {delay:1, time:2, _blur_blurX:3 } );
Categories: Actionscript 3 · Flash
Tagged: Actionscript 3, SVN Tweener
This post details how to embed fonts with only AS3.
Took a good 2 hours to come across the right information. Hopefully somebody else can benefit from this as well.
It looks like if you ever need to change the alpha on a TextField you need to embed the font. Here are the basics.
/// EMBED FONT ///
[Embed(source = "path_to_font", fontName= "myFont")]
public static var myFont:Class;
Font.registerFont(path_to_font_class);
/// CREATE TFORMAT ///
var format:TextFormat = new TextFormat();
format.font="myFont"
/// CREATE TFIELD ///
var tf:TextField = new TextField();
tf.embedFonts = true;
tf.defaultTextFormat = format;
Now you are finally good to go. tf.alpha=0, and sure enough, it works.
Categories: Actionscript 3 · Flash
Tagged: Actionscript 3, AS3, Flash