2014-04-20 44 views
0

我试图完成第8课Adobe 3.0专业版的ActionScript 3.0 CS5,但已经发现一些困难:我输入了书中所示的所有代码,但 没有得到结果,我认为问题是我使用Adobe Flash CS 6, ,因为部分文件在CS 6中未正确打开。下面是第8课 的代码以及我需要做什么来完成本课程?如何完成课程?

import fl.text.TLFTextField; 
import fl.controls.UIScrollBar; 
var t:TLFTextField = new TLFTextField(); 
var tf:TextFormat = new TextFormat(); 
t.width = 500; 
t.height = 600; 
t.background = true; 
t.paddingTop = 20; 
t.paddingLeft = 20; 
t.paddingRight = 20; 
addChild(t); 
var textLoad:URLLoader = new URLLoader(); 
textLoad.addEventListener(Event.COMPLETE, textLoaded); 
textLoad.load(new URLRequest("sample.txt")); 
function textLoaded(e:Event):void 
{ 
    var txt:String = URLLoader(e.target).data as String; 
    t.text = txt; 
    tf.color = 0x336633; 
    tf.font = "Arial"; 
    tf.size = 14; 
    t.setTextFormat(tf); 
} 
var formatClip:Formatter = new Formatter(); 
var showFormat:Boolean = true; 
stage.addEventListener(KeyboardEvent.KEY_DOWN, showFormatter); 
function showFormatter(e:KeyboardEvent):void 
{ 
    if (e.keyCode == 70) 
    { 
     if (showFormat) 
     { 
      addChild(formatClip); 
      formatClip.x = t.width; 
      formatClip.addEventListener(MouseEvent.MOUSE_DOWN, drag); 
      showFormat = false; 
     } 
     else 
     { 
      formatClip.removeEventListener(MouseEvent.MOUSE_DOWN, drag); 
      removeChild(formatClip); 
      showFormat = true; 
     } 
    } 
} 
function drag(e:Event):void 
{ 
    formatClip.startDrag(); 
    formatClip.addEventListener(MouseEvent.MOUSE_UP, noDrag); 
} 
function noDrag(e:Event):void 
{ 
    formatClip.stopDrag(); 
} 
formatClip.fontList.addEventListener(Event.CHANGE, setFont); 
formatClip.fontSizer.addEventListener(Event.CHANGE, setFontSize); 
formatClip.colorPicker.addEventListener(Event.CHANGE, setColor); 
formatClip.columnNum.addEventListener(Event.CHANGE, setColumns); 
function setFont(e:Event):void 
{ 
    tf.font = e.target.selectedItem.label; 
    t.setTextFormat(tf); 
} 

function setFontSize(e:Event):void 
{ 
    tf.size = e.target.value; 
    t.setTextFormat(tf); 
} 

function setColor(e:Event):void 
{ 
    tf.color = e.target.selectedColor; 
    t.setTextFormat(tf); 
} 
function setColumns(e:Event):void 
{ 
    t.columnCount = e.target.value; 
} 
var scroller:UIScrollBar = new UIScrollBar(); 
scroller.move(t.x + t.width, t.y); 
scroller.height = t.height; 
scroller.scrollTarget = t; 
addChild(scroller); 
scroller.visible = false; 
formatClip.addEventListener(MouseEvent.CLICK, setScrollbar); 
function setScrollbar(e:Event):void 
{ 
    if (t.textHeight > scroller.height) 
    { 
     scroller.visible = true; 
    } 
    else 
    { 
     scroller.visible = false; 
    } 
    t.scrollV = 1; 
} 

我得到这个SWF:

enter image description here

但需要得到这个SWF: enter image description here 谢谢 约扎斯Vitkus

+0

第8课?书?你在说什么?! –

回答

0

好像你需要使用多行文本框

只需加上t.multiline=true;

相关问题