How to Convert TextField to Bitmap using Flash and AS3

Posted by druva | Flash, Flex, as3, utils | Wednesday 3 February 2010 10:15 pm

Convert TextField to Bitmap

package {
	import flash.display.*;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFieldAutoSize;

	public class BitmapUtils extends Sprite {
		public function BitmapUtils() {
			addChild(tf2bm('Druva'));
		}
		public function tf2bm(str:String) {
			var fmt:TextFormat;
			var bmd:BitmapData;
			var bm:Bitmap;
			var tf:TextField;

			fmt = new TextFormat();
			fmt.font='Verdana';
			fmt.size=30;

			tf = new TextField();
			tf.text=str;
			tf.setTextFormat(fmt);
			tf.autoSize=TextFieldAutoSize.LEFT;
			bmd=new BitmapData(tf.width,tf.height,true,0);
			bmd.draw(tf);
			bm=new Bitmap(bmd);
			bm.smoothing=true;
			return bm
		}
	}
}
 

Create Text Effects in Flash and AS3 (Actionscript 3.0)

Posted by druva | Flash, as3, utils | Thursday 7 January 2010 3:45 pm

Just playing with Text and this is my first version of text effects

This movie requires Flash Player 9

sample 0.1

 

CS4 caretIndex(point position) in textField using action script

Posted by druva | Flash, as3, utils | Wednesday 30 December 2009 6:26 am

The caretIndex means the index of the point(caret) position.


import fl.controls.TextInput;
import fl.controls.Label;

var textfield:TextField = new TextField();
textfield.x = textfield.y = 100;
textfield.width = textfield.height = 100;
textfield.text = "blog.totusinfo.com";

addChild(textfield);
textfield.addEventListener(MouseEvent.CLICK, caretindex);

function caretindex(event:MouseEvent):void {

	var textfield:TextField = TextField(event.target);

	var myLabel:Label = new Label();
	myLabel.text = "Caret Index";
	myLabel.x = 10;
	myLabel.y = 10;
	addChild(myLabel);

	var textInput:TextInput = new TextInput();
	textInput.x = 75;
	textInput.y = 10;
	textInput.text = String(textfield.caretIndex);
	addChild(textInput);

}
 

Flash as3 TextField alpha Tweening

Posted by druva | Flash, as2, as3, utils | Monday 21 December 2009 10:15 am
var tf:TextField = new TextField();
tf.text = "Hello Hello";
tf.width = 650;

var format1:TextFormat = new TextFormat();
format1.color = 0xFF0000;
format1.size = 80;

tf.setTextFormat(format1);

addChild(tf);
tf.alpha = .1;

import flash.display.BlendMode;
tf.blendMode = BlendMode.LAYER;

import fl.transitions.Tween;
import fl.transitions.easing.*;
new Tween(tf, "alpha", Elastic.easeOut, 0, 1, 200, false);
 

Rotating device fonts using flash actionscript

Posted by Vineela | Flash, as3, utils | Monday 30 November 2009 6:38 am

package druva{
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;

public class textEffect extends Sprite {

	public function textEffect () {

		for (var i:int = 2; i <= 12; i++) {
			var txt:TextField = new TextField();
			txt.selectable = false;
			txt.width = 400;
			txt.text = "blog.totusinfo.com";
			txt.setTextFormat(new TextFormat("Georgia", 2*i,(2 + 0.35*i) * 0xCCCC00,false,true ));

			txt.x = 4.5*(i*(i+1)/2);
			txt.y = 3*(i*(i+2)/2);
			txt.rotationZ = 20;
			addChild(txt);
		}

	}
}
}

This movie requires Flash Player 9

 

Why to use sharpness for textFields in Flash AS3 (Actionscript)

Posted by druva | as3, utils | Friday 27 February 2009 4:04 am
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

var labelText:String = 'This is brown fox';

function TextFieldExample() {
 configureLabel(numberText1, -400);
 configureLabel(numberText2, -300);
 configureLabel(numberText3, -200);
 configureLabel(numberText4, -100);
 configureLabel(numberText5, 100);
 configureLabel(numberText6, 200);
 configureLabel(numberText7, 300);
 configureLabel(numberText8, 400);
 configureLabel(numberText9, -100);
}

var _arial_str:String;
var myFont:Font = new Font1();
function configureLabel(targ, shrp:Number):void {
 targ.footer_number.autoSize = TextFieldAutoSize.LEFT;
 targ.footer_number.background = false;
 targ.footer_number.border = false;
 targ.footer_number.sharpness = shrp;

 var format:TextFormat = new TextFormat();
 format.font = myFont.fontName;
 format.color = 0xFFFFFF;
 format.size = 30;
 targ.footer_number.defaultTextFormat = format;
 targ.footer_number.text = labelText;
 targ.sharpnessValue.text = 'Sharpness ' + String(shrp);
}
TextFieldExample();
sslider.addEventListener(Event.CHANGE, on_sliderChange);
function on_sliderChange(e:Event){
 configureLabel(numberText9, sslider.value);
}
 

restricting which characters a TextInput can accept using flash actionscript

Posted by Vineela | Flash, as3, utils | Sunday 28 December 2008 9:33 am

import fl.controls.TextInput;

function textValid(  ) {
  var field:TextInput = new TextInput(  );
  field.restrict = 'a-z';
  addChild(field);
}

textValid();
 

How to know Frame Rate of the stage using cs4 action script

Posted by druva | Flash, as3, utils | Thursday 25 December 2008 4:32 am

The below code show how to know the frame rate of the stageusing action script.


var t:TextField = new TextField();
t.text = stage.frameRate.toString();
addChild(t);
 

calling javascript functions using action script

Posted by Vineela | Flash, as3, utils | Tuesday 11 November 2008 4:41 am

import flash.display.Sprite;
import flash.text.*;
function callJavascript(){
	var textfield:TextField = new TextField();

	textfield.htmlText = "<a href=\"javascript:void(alert('Refer blog.totusinfo.com for flash examples'));\">Totusinfo</a>";
    addChild(textfield);

}
callJavascript();
 

get System Resoultion using action script

Posted by Vineela | Uncategorized | Tuesday 28 October 2008 11:03 am

See the below example to know your system resolution

package druva.vini {
  import flash.system.Capabilities;
  import flash.net.*;
  import flash.display.*;
  import flash.text.TextField;

  public class SystemCap extends Sprite {

    public function SystemCap(){
        var resX:int = flash.system.Capabilities.screenResolutionX;
        var resY:int = flash.system.Capabilities.screenResolutionY;

		var field:TextField = new TextField();
			field.border = true;
			field.text = 'resX ' + resX + '\nresY ' + resY;
			field.background = true;
			addChild(field);
    }
  }
}

(more…)