Flash / Flex / ActionScript/TextField/Effects

Материал из Web эксперт
Перейти к: навигация, поиск

a list of bulleted text

 
package{
  import flash.display.Sprite;
  import flash.text.*;
  public class Main extends Sprite{
    public function Main(){
        var tContent:TextField = new TextField();
        tContent.multiline = true;
        tContent.border = true;
        tContent.wordWrap = true;
        tContent.text = "a\nb\nc\nd";
        var tfFormatter:TextFormat = new TextFormat();
        tfFormatter.bullet = true;
        tContent.setTextFormat(tfFormatter);
        addChild(tContent);
    }
  }
}



Applying Advanced Anti-Aliasing

 
package {
  import flash.display.Sprite;
  import flash.text.TextField;
  public class Main extends Sprite {
    public function Main(  ) {
      var field:TextField = new TextField(  );
      field.antiAliasType = flash.text.AntiAliasType.ADVANCED;
      addChild(field);
    }
  }
}



ClickableText

 
Handling the MouseEvent.CLICK event
package {
  import flash.display.*;
  import flash.text.*;
  import flash.events.*;
  public class Main extends Sprite {
    public function Main (  ) {
      var theTextField:TextField = new TextField(  );
      theTextField.text       = "Click here";
      theTextField.autoSize   = TextFieldAutoSize.LEFT;
      theTextField.border     = true;
      theTextField.background = true;
      theTextField.selectable = false;
      addChild(theTextField);
      theTextField.addEventListener(MouseEvent.CLICK, clickListener);
    }
    private function clickListener (e:MouseEvent):void {
      trace("Mouse was clicked");
    }
  }
}



Make whole TextField italic

 
package{
  import flash.display.Sprite;
  import flash.text.*;  
  public class Main extends Sprite{
    public function Main(){
        var tfStyle:TextFormat = new TextFormat();
        tfStyle.font = "Verdana";
        tfStyle.bold = true;
        tfStyle.italic = true;
        tfStyle.size = 12;
        var tContent:TextField = new TextField();
        tContent.setTextFormat(tfStyle);
        addChild(tContent);
    }
  }
}



Rasterizing, then dissolving a TextField

 
package {
  import flash.display.*;
  import flash.utils.*;
  import flash.events.*;
  import flash.geom.*;
  import flash.text.*;
  public class DissolveText extends Sprite {
    private var randomSeed:int = Math.floor(Math.random(  ) * int.MAX_VALUE);
    private var destPoint:Point = new Point(0, 0);
    private var numberOfPixels:int = 10;
    private var destColor:uint = 0xFF000000;
    private var bitmapData:BitmapData;
    private var t:Timer;
    public function DissolveText (  ) {
      var txt:TextField = new TextField(  );
      txt.text = "Essential ActionScript 3.0";
      txt.autoSize = TextFieldAutoSize.LEFT;
      txt.textColor = 0xFFFFFF;
      bitmapData = new BitmapData(txt.width, txt.height, false, destColor);
      bitmapData.draw(txt);
      var bitmap:Bitmap = new Bitmap(bitmapData);
      addChild(bitmap);
      t = new Timer(10);
      t.addEventListener(TimerEvent.TIMER, timerListener);
      t.start(  );
    }
    private function timerListener (e:TimerEvent):void {
      dissolve(  );
    }
    public function dissolve(  ):void {
      randomSeed = bitmapData.pixelDissolve(bitmapData,
                                            bitmapData.rect,
                                            destPoint,
                                            randomSeed,
                                            numberOfPixels,
                                            destColor);
      var coloredRegion:Rectangle =
                bitmapData.getColorBoundsRect(0xFFFFFFFF, destColor, false);
      if (coloredRegion.width == 0 && coloredRegion.height == 0 ) {
        t.stop(  );
      }
    }
  }
}



Set Text box grid fit type to pixel

 
package {
  import flash.display.Sprite;
  import flash.text.TextField;
  public class Main extends Sprite {
    public function Main(  ) {
      var field:TextField = new TextField(  );
      field.gridFitType = GridTypeFit.PIXEL;
      addChild(field);
    }
  }
}



the text appears fully opaque, even though the text field"s alpha percentage is set to 20%:

 
package{
  import flash.display.Sprite;
  import flash.text.*;
  public class Main extends Sprite{
    public function Main(){
        var t:TextField = new TextField(  );
        t.text = "Hello world";
        t.alpha = .2;
        addChild(t);
    }
  }
}