2010年11月12日 星期五

[AS3] 在文字欄位中點擊滑鼠,垂直捲動文字 - TextField.scrollV屬性

點擊一次捲動兩行 --->  myTextField.scrollV +=2;
點擊後滑鼠取得文字欄位為焦點,可用滾輪捲動文字行


package 
{
 //
 import flash.display.Sprite;
 import flash.text.*;
 import flash.events.MouseEvent;
 //
 public class TextField_TextScrollExample_1 extends Sprite
 {
  //
  private var myTextField:TextField = new TextField  ;
  private var myText:String = "Hello world and welcome to the show. It's really nice to meet you.Take your coat off and stay a while. OK, show is over. Hope you had fun. You can go home now. Don't forget to tip your waiter. There are mints in the bowl by the door. Thank you. Please come again.";
  //
  public function TextField_TextScrollExample_1()
  {
   //
   myTextField.text = myText;
   //
   myTextField.x = 150;
   myTextField.y = 100;
   myTextField.width = 150;
   myTextField.height = 100;
   myTextField.multiline = true;
   myTextField.wordWrap = true;
   myTextField.background = true;
   myTextField.border = true;
   //
   var format:TextFormat = new TextFormat  ;
   format.font = "Times New Rpman";
   format.color = 0x000088;
   format.size = 20;
   //
   myTextField.defaultTextFormat = format;
   //setTextFormat-將format參數所指定的文字格式,套用至文字欄位中的指定文字
   //setTextFormat(format:flash.text:TextFormat, beginIndex:int = -1, endIndex:int = -1):void
   //參考http://help.adobe.com/zh_TW/Flash/CS5/AS3LR/flash/text/TextField.html#setTextFormat()
   myTextField.setTextFormat(format);
   //
   addChild(myTextField);
   //
   myTextField.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownScroll);
  }
  //
  public function mouseDownScroll(event:MouseEvent):void
  {
   //scrollV-文字欄位中文字的垂直位置
   //如果顯示的第一行是文字欄位中的第一個字行,scrollV 便會設定為1
   //參考http://help.adobe.com/zh_TW/Flash/CS5/AS3LR/flash/text/TextField.html#scrollV
   //myTextField.scrollV ++; //點擊一次捲動一行
   myTextField.scrollV +=2;  //點擊一次捲動兩行
  }
 }
}



沒有留言: