Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

Applicare un TextFormat ad un campo di testo

This is a discussion on Applicare un TextFormat ad un campo di testo within the Articoli e tutorials forums, part of the Flash CS3 e Actionscript 3.0 category; Ciao a tutti ! Oggi ho deciso di trattare l' argomento TextFormat in quanto ho ricevuto diverse richieste di aiuto riguardanti ...


Go Back   Forum Flash CS3 Flash CS4 > Flash CS3 e Actionscript 3.0 > Articoli e tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  2 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 27-09-07, 06:31
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,486
Rep Power: 6
Flep is on a distinguished road
Applicare un TextFormat ad un campo di testo

Ciao a tutti !
Oggi ho deciso di trattare l' argomento TextFormat in quanto ho ricevuto diverse richieste di aiuto riguardanti come si applica una determinata font ad un campo di testo con Actionscript 3.0 .
Intanto partirei col dire che l' iter è questo:

  1. - creare la font necessaria ed inserirla in un Array

  2. - creare un campo di testo

  3. - creare una istanza di TextFormat

  4. - assegnare il TextFormat al campo di testo

  5. - assegnare il testo al campo di test


detto questo, bando ai blah blah ed entriamo in un esempio concreto...

Creo un FLA che salvo con nome ' main.fla '.
Al suo interno creo una nuova font in libreria come ho fatto vedere in questo tutorial.
Creo la Document Class, un file AS che salvo con nome ' Main.as ', implementata in questo modo:
Code:
package
{
	import flash.display.MovieClip;
	import flash.text.Font;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	public class Main extends MovieClip
	{
		private var field_txt:TextField;
		private var format:TextFormat;
		
		private var fonts_array:Array;
		
		public function Main()
		{
			init();
		}
		
		private function init():void
		{
			Font.registerFont(Monaco);
			
			fonts_array=Font.enumerateFonts(false);
			
			createField();
			createFormat();
			setFormat();
			setText();
		}
		
		private function createField():void
		{
			field_txt=new TextField();
			addChild(field_txt);
			field_txt.x=20;
			field_txt.y=20;
			field_txt.selectable=false;
			field_txt.embedFonts=true;
			field_txt.multiline=true;
			field_txt.width=300;
			field_txt.wordWrap=true;
		}
		
		private function createFormat():void
		{
			format=new TextFormat();
			var font:Font=fonts_array[0];
			format.font=font.fontName;
			format.color=0x333333;
			format.size=14;
		}
		
		private function setFormat():void
		{
			field_txt.defaultTextFormat=format;
		}
		
		private function setText():void
		{
			field_txt.text="Lorem Ipsum is simply dummy text of the printing and typesetting industry"+
			"Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,"+
			" when an unknown printer took a galley of type and scrambled it to make a type specimen book."+
			"It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged."+
			"It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, "+
			"and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
			field_txt.height=field_txt.textHeight+10;
		}
	}
}
ottenendo il seguente risultato:






Analizziamo il codice:

Proprietà

una istanza di TextField
private var field_txt:TextField;
un Array
private var fonts_array:Array;

poi seguendo lo schemino che ho precisato all' inizio,

1- creare la font necesaria ed inserirla in un Array
Font.registerFont(Monaco);
fonts_array=Font.enumerateFonts(false);

2 - creare un campo di testo
chiamo il metodo createField e:
creo il campo
field_txt=new TextField();
addChild(field_txt);
lo posiziono
field_txt.x=20;
field_txt.y=20;
gli dico di non essere selezionabile dal mouse
field_txt.selectable=false;
imposto la proprietà embedFonts a true
field_txt.embedFonts=true;
dico che deve essere multi linea
field_txt.multiline=true;
imposto una larghezza del campo di testo
field_txt.width=300;
imposto la proprietà wordWrap a true
field_txt.wordWrap=true;

3 - creare una istanza di TextFormat
chiamo il metodo createFormat
creo un nuovo TextFormat
format=new TextFormat();
assegno la font a format
var font:Font=fonts_array[0];
format.font=font.fontName;
assegno un colore a format
format.color=0x333333;
assegno una dimensione a format
format.size=14;

4- assegnare il TextFormat al campo di testo
chiamo il metodo setFormat che assegna il textFormat al campo di testo in questo modo
field_txt.defaultTextFormat=format;

5 - assegnare il testo al campo di test
chiamo il metodo setText
assegno il testo
field_txt.text="......";
gli assegno una lunghezza massima al campo di testo
field_txt.height=field_txt.textHeight+10;

Allego i files sorgente:
Attached Files
File Type: zip TextFormat.zip (27.7 KB, 14 views)

__________________

 


I recommend: Essential Actionscript 3.0

- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
- I do not reply technicians pvt messages. Open a thread !

Last edited by Flep; 05-06-08 at 08:07..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
voglio campo di testo con collegamento url simscu Flash CS3 generale 1 01-04-08 09:49
Altezza campo di testo dinamico ulisse46 Actionscript 3.0 base 3 11-03-08 19:23
come applicare uno stop Fringuello Actionscript 3.0 base 2 04-03-08 17:48
Apply a TextFormat to a TextField Flep Tutorials 0 07-11-07 06:56
dialogare con un campo dinamico naruto Actionscript 3.0 base 3 08-08-07 22:21


All times are GMT. The time now is 11:33.


Powered by vBulletin versione 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap


FlepStudio
by Filippo Lughi
P.IVA 03605860406