as3 change font size as stage size changes - actionscript-3

As it reads I want to change the font size as the stage size changes.
I have private var myFormat:TextFormat = new TextFormat();
And then when the object gets made it writes the following
_buttonText.wordWrap = true;
myFormat.size = 15;
myFormat.align = TextFormatAlign.CENTER;
_buttonText.textColor = 0x222428;
myFormat.bold = 'true';
_buttonText.defaultTextFormat = myFormat;
_buttonText.text = text;
Then in my on enter frame I want to resize the text, I have tried a couple things but nothing seems to work, currently it looks like this.
myFormat.size = stage.stageWidth / 136.53;
Thanks for any help

A TextFormat object has no effect unless applied to a TextField. Besides if the font size should be linked to the stage size then a factor size of some kind should be applied as well. At the end it looks like this:
myFormat.size = 15 * fontSizeFactor;
//_buttonText.defaultTextFormat = myFormat;this is irrelevant if size should be dynamic.
//instead text should be set then TextFormat should be set again.
_buttonText.text = text;
_buttonText.setTextFormat(myFormat);//this is dynamic
now on enter frame:
myFormat.size = 15 * fontSizeFactor;
_buttonText.setTextFormat(myFormat);//apply the format again or else nothing will happen

Related

Loading images using the URLRequest

recently started to learn ActionScript 3 and already have questions.
question remains the same: I'm uploading a picture using the object Loader.load (URLRequest). Loaded and displayed a picture normally. But it is impossible to read the values of attributes of the image height and width, instead issued zero. That is, do this:
var loader:Loader=new Loader();
var urlR:URLRequest=new URLRequest("Image.jpg");
public function main()
{
loader.load(urlR);
var h:Number = loader.height;// here instead of the width of the image of h is set to 0
// And if you do like this:
DrawText(loader.height.toString(10), 50, 50); // Function which draws the text as defined below
// 256 is displayed, as necessary
}
private function DrawText(text:String, x:int, y:int):void
{
var txt:TextField = new TextField();
txt.autoSize = TextFieldAutoSize.LEFT;
txt.background = true;
txt.border = true;
txt.backgroundColor = 0xff000000;
var tFor:TextFormat = new TextFormat();
tFor.font = "Charlemagne Std";
tFor.color = 0xff00ff00;
tFor.size = 20;
txt.x = x;
txt.y = y;
txt.text = text;
txt.setTextFormat(tFor);
addChild(txt);
}
Maybe attribute values must be obtained through the special features, but in the book K.Muka "ActionScript 3 for fash" says that it is necessary to do so. Please help me to solve this. Thanks in advance.
Well it's simple.
Flash is focused on the Internet, hence such problems.
If you wrote loader.load (urlR); it does not mean loaded. Accordingly, prior to the event confirming the end of loading, in loadare Null
if, instead of certain functions would be more code that would perhaps tripped your approach.
Yeah plus still highly dependent on the size of the file that you read.
Well, in general it all lyrics. Listen event on loader.contentLoaderInfo.addEventListener (Event.INIT, _onEvent), onEvent and read properties.
You need to wait for your image to load to be able to get values out of it.
Attach an eventListener to your URLLoader.
var urlR:URLRequest = new URLRequest("Image.jpg");
loader.load(urlR);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
function loader_complete(e:Event): void {
// Here you can get the height and width values etc.
var target_mc:Loader = evt.currentTarget.loader as Loader;
// target_mc.height , target_mc.width
}
Loader

AS3 InputTextField Component size change

I want to use text input component and I drag it on the stage, I give it a instance name. Now from code I'm trying to change the size of it by instance name , because I expand a little bit and the text size remain like it was.
Here is my code:
userLog.size = 30;
I receive this error:
1119:Access of possibly undefined property size through a reference with static type fl.controls:TextInput.
Thank you!
You can do:
userLog.width = 30;
Or even:
userLog.width = userLog.textWidth ;
Or even more:
userLog.addEventListener(Event.CHANGE,onChange);
function onChange(e:Event):void{
var new_width:Number;
if(userLog.textWidth<100){
new_width = 100;
} else {
new_width = userLog.textWidth;
}
userLog.width = new_width;
}
UPDATE. In case you want to change TextInput's font size , use TextFormat:
var format:TextFormat = new TextFormat();
format.size = 24;
userLog.setStyle("textFormat", format);

AS3 flash CC I want to set the width of the parent Movieclip of a Textfield

I have dynamically created a bunch of textfields, the number of which depends on xml input. The textfields need to be button-enabled, so I thought the easiest solution is to put them in a movieclip and buttonMode that movieclip.
The hierarchy looks like this: main (extends MovieClip) -> klankoefening (a MovieClip) -> Textfieldparent (a MovieClip) -> Textfield
I have a variable maxw which contains the biggest textfield's width and I want all my Textfieldparents to have this width.
I'm trying to do it like this:
//generate textfields
keuzes = new XMLList(lijstOpties.categorie.(#cat == catname));
var nrs:int = keuzes.keuze.length(); //aantal keuzemogelijkheden
var maxw:int = 0; //grootste breedte tf, nodig voor bepalen breedte knoppen
for (var nr:int = 0; nr < nrs; nr++) {
var tf:TextField = createTextfield(werkfmt);
tf.text = keuzes.keuze[nr].toString();
tf.autoSize = "center";
tf.background = true;
tf.backgroundColor = 0xffcc33;
tf.border = true;
tf.borderColor = 0x000000;
tf.name = "keuzetf";
tf.selectable = false;
tf.x = 0;
tf.y = 0;
if (tf.width > maxw) {maxw = tf.width;}
var tfcontainer:MovieClip = new MovieClip();
tfcontainer.buttonMode = true;
tfcontainer.name = keuzes.keuze[nr].toString();
tfcontainer.addChild(tf);
klankoefening.addChildAt(tfcontainer,nr);
}
for (var an:int = 0; an < 3; an++) {
var mcs:MovieClip = klankoefening.getChildAt(an) as MovieClip;
mcs.width = maxw;
trace ("mcs " + mcs.width);
var mtf:TextField = mcs.getChildAt(0) as TextField;
trace ("mtf " + mtf.text);
}
the trace results are
mcs 32.05
mcs 33
mcs 21.25
Which I find odd, because I stated in my second loop that the width for all Textfieldparents should be set to maxw. What is happening?
Consider drawing an underlaying Rectangle of desired width and height. You can use mcs.graphics to do that. The trick is, width of a DisplayObjectContainer is a calculated property, and changing it will likely result in changing scale. Say, a MC has two shapes as chilren, one at (1000,0) and another at (0,0), and both have width of 10 - the resultant width of that MC will be 1010. So, instead of changing width, simulate its change by drawing a rectangle on the MC.
mcs.graphics.clear();
mcs.graphics.lineStyle(0,0,0);
mcs.graphics.beginFill(0x808080,0); // bogus filled rect, to capture events
mcs.graphics.drawRect(0,0,maxw,maxh); // height is needed too
mcs.graphics.endFill();
After thinking a bit more about your problem, I think your issue is that the buttons you're adding the text to have a width entirely defined by the TextField, and because you're set the text to autoSize, it's snapping back to it's original width.
What you will need to do to make the width more indicative of what you need, and allow for easy clicking on the buttons is to create a transparent rectangle in the tfContainer mc, set the width of the tfContainer, and then add the text to the button.

TextField Antialiasing in Flash CS3 / FP10 causing text to flicker and "bloom"?

I have run into a small graphics glitch in Flash. It seems to be both in FP9 - Exported via Flash CS3, and FP10 - Exported via the Flex 4 beta SDK.
The glitch / problem manifests itself as embedded text at a small point size "blooming" under certian conditions. It basically looks like the antialiasing becomes fatter at some level of text brightness. I have made a small test case below. (Obviously) You will need to embed the Arial font in your compiled SWF for the below code to work.
var myText:TextField = new TextField();
myText.embedFonts = true;
myText.antiAliasType = AntiAliasType.ADVANCED;
myText.autoSize = TextFieldAutoSize.LEFT;
var myFormat:TextFormat = myText.getTextFormat();
myFormat.size = 8;
myFormat.font = 'Arial';
myFormat.color = 0x663300;
myText.defaultTextFormat = myFormat;
myText.text = 'Bloom Example';
addChild(myText);
var composit:ColorTransform = new ColorTransform();
var timestamp:Number = getTimer();
function enterFrame (event:Event):void{
var n:Number = (getTimer() - timestamp) / 1000.0;
composit.redMultiplier = 1-n;
composit.greenMultiplier = 1-n;
composit.blueMultiplier = 1-n;
composit.redOffset = 250 * n;
composit.greenOffset = 250 * n;
composit.blueOffset = 0;
myText.transform.colorTransform = composit;
if ( n >= 1 ) removeEventListener(Event.ENTER_FRAME, enterFrame);
};
addEventListener(Event.ENTER_FRAME, enterFrame);
You can see an example of the problem by rolling over the graphical element here: http://bandcamp.fieldsofnoise.org/dump/bloom.swf
It's not really an option to change to AntiAliasType.NORMAL as it makes the text way less readable at this point size.
Any help finding an appropriate resolution to this problem would be appreciated.
I think when you change the brightness then you're maxing out the values for all pixels the font is rendered with including the anti-aliasing pixels. Have you tried changing the color rather than increasing the brightness? Or even applying a simple tint?

Set text outlining / border in Actionscript 3.0

How can I set the properties for the text outline / border for each character in a line of text in AS3 ?
I don't think you can. What you can do is use a blur filter to mimic the appearance of an outline. Just paste this into an empty AS3 movie:
var txt:TextField = new TextField();
this.addChild(txt);
txt.appendText('Lorem ipsum');
txt.autoSize = TextFieldAutoSize.LEFT;
txt.antiAliasType = flash.text.AntiAliasType.NORMAL;
txt.selectable = false;
var txtFormat:TextFormat = new TextFormat();
txtFormat.size = 40;
txtFormat.font = 'Helvetica';
txt.setTextFormat(txtFormat);
txt.defaultTextFormat = txtFormat;
var outline:GlowFilter = new GlowFilter();
outline.blurX = outline.blurY = 1;
outline.color = 0xFF0000;
outline.quality = BitmapFilterQuality.HIGH;
outline.strength = 100;
var filterArray:Array = new Array();
filterArray.push(outline);
txt.filters = filterArray;
Try playing with the strength, blurX, blurY and quality properties, in order to obtain different appearances. I think that's about the closest you can get to a text outline.
PS: font embedding would greatly improve the quality of the effect, as well as making the antialias work properly.
i am not shore i understand but you can use same kind of
filter on the testbox and by doing so you can get a same kind of a border
in each one of your letters