我尝试完成第8课Adobe Flash Professional的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:
但是需要得到这个swf:
谢谢
Juozas Vitkus
答案 0 :(得分:0)
好像你需要使用多行文本域
只需添加t.multiline=true;