A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: using textformat class dynamically

  1. #1
    Junior Member
    Join Date
    Nov 2009
    Posts
    13

    Question using textformat class dynamically

    hi! this is my first post. I've recently started to learn/use AS 3.0 and am now exploring the use of external custom classes.

    ok my problem:

    I have an fla with a text field in place. I want to write an AS 3.0 class in an external .as file which sets a text format, and apply that format to the text field in the fla file - how do i so this??

    thanks for any help!!

  2. #2
    Junior Member
    Join Date
    Jan 2009
    Posts
    11
    Unless I'm misunderstanding, it should be something like this:
    Code:
    var tf:TextFormat = yourTextField.getTextFormat();
    //Make changes to tf
    yourTextField.setTextFormat(tf); //Formats the already-present text using your modified TextFormat instance
    yourTextField.defaultTextFormat = tf; //Uses your modified TextFormat instance from now on

  3. #3
    Junior Member
    Join Date
    Nov 2009
    Posts
    13
    thanks Scott64,

    let me be more specific, i have an fla with a text field on stage called loginTxt1. In the actions on a frame i have the follwoing code
    Code:
    stop();
    var loginTxt1:TextField;
    var formatText:TextFormatClass = new TextFormatClass();
    formatText.setHeadingFormat1(loginTxt1);
    in the .as file i have the following code:

    Code:
    package com.name.classes.textClasses
    {
    	import flash.text.TextFormat;
    	import flash.text.TextField;
    	import flash.display.MovieClip;
    	
    	public class TextFormatClass extends MovieClip
    	{
    		var headingFormat1:TextFormat = new TextFormat();
    
    		public function TextFormatClass ()
    		{
    			
    		}
    		
    		public function setHeadingFormat1 (t:TextField) :void
    		{
    			
    			headingFormat1.font = "Arial Black";
    			headingFormat1.size = 14;
    			headingFormat1.bold = true;
    			headingFormat1.color = 0x21B27F;
    			trace("hello");
    			t.setTextFormat.headingFormat1;
    							
    		}
    	}
    }
    i want to set several text formats in the as file and assign them to textfields in the fla - but i am stumped as to how!
    my class document path thingy maybe wrong.. im new to all this.
    any help really appreciated!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center