Actionscript - 带有外部文本文件的 TLFTextField,文件运行时不显示任何内容
Actionscript - TLFTextField with External Text Files, Nothing Displays When File Runs
完全公开,这是我 class 的作业。但是,这已经上交并评分。我真的只想知道为什么它不起作用。
对于 TLFTextField 和外部文件,我遵循了书中的步骤。有用。然后我需要再添加 2 个 TLFTextFields 和 2 个外部文本文件。当我现在 运行 它时, window 弹出但是是空白的。甚至我知道以前工作过的原始 TLFTextField 或文本文件显示也没有。我什至没有碰那个代码。没有错误。我不知道我哪里出错了。我的 class 朋友也有同样的问题。
我的代码如下:
import fl.text.TLFTextField;
import fl.controls.UIScrollBar;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.text.TextFormat;
import flash.events.KeyboardEvent;
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 = 0x003300;
tf.font = "Arial";
tf.size = 14;
t.setTextFormat(tf);
}
var cat:TLFTextField = new TLFTextField();
var cf:TextFormat = new TextFormat();
cat.width = 500;
cat.height = 600;
cat.background = true;
cat.paddingTop = 20;
cat.paddingLeft = 20;
cat.paddingRight = 20;
addChild(cat);
var catLoad:URLLoader = new URLLoader();
catLoad.addEventListener(Event.COMPLETE, catLoaded);
catLoad.load(new URLRequest("cat.txt"));
function catLoaded(e:Event):void
{
var txt:String = URLLoader(e.target).data as String;
cat.text = txt;
cf.color = 0xFCE5CD;
cf.font = "Arial";
cf.size = 16;
cat.setTextFormat(cf);
}
var doctor:TLFTextField = new TLFTextField();
var df:TextFormat = new TextFormat();
doctor.width = 500;
doctor.height = 600;
doctor.background = true;
doctor.paddingTop = 20;
doctor.paddingLeft = 20;
doctor.paddingRight = 20;
addChild(doctor);
var doctorLoad:URLLoader = new URLLoader();
doctorLoad.addEventListener(Event.COMPLETE, doctorLoaded);
doctorLoad.load(new URLRequest("doctor.txt"));
function doctorLoaded(e:Event):void
{
var txt:String = URLLoader(e.target).data as String;
doctor.text = txt;
df.color = 0x68E9E5;
df.font = "Arial";
df.size = 16;
doctor.setTextFormat(df);
}
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);
cf.font = e.target.selectedItem.label;
cat.setTextFormat(cf);
df.font = e.target.selectedItem.label;
doctor.setTextFormat(df);
}
function setFontSize(e:Event):void
{
tf.size = e.target.value;
t.setTextFormat(tf);
cf.size = e.target.value;
cat.setTextFormat(cf);
df.size = e.target.value;
doctor.setTextFormat(df);
}
function setColor(e:Event):void
{
tf.color = e.target.selectedColor;
t.setTextFormat(tf);
cf.color = e.target.selectedColor;
cat.setTextFormat(tf);
df.color = e.target.selectedColor;
doctor.setTextFormat(tf);
}
function setColumns(e:Event):void
{
t.columnCount = e.target.value;
cat.columnCount = e.target.value;
doctor.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;
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;
}
var catScroller:UIScrollBar = new UIScrollBar();
catScroller.move(cat.x + cat.width, cat.y);
catScroller.height = cat.height;
catScroller.scrollTarget = cat;
addChild(catScroller);
catScroller.visible = false;
formatClip;
formatClip.addEventListener(MouseEvent.CLICK, setCatScrollbar);
function setCatScrollbar(e:Event):void
{
if(cat.textHeight > scroller.height)
{
catScroller.visible = true;
}
else
{
catScroller.visible = false;
}
cat.scrollV = 1;
}
var doctorScroller:UIScrollBar = new UIScrollBar();
doctorScroller.move(doctor.x + doctor.width, doctor.y);
doctorScroller.height = doctor.height;
doctorScroller.scrollTarget = doctor;
addChild(scroller);
doctorScroller.visible = false;
formatClip;
formatClip.addEventListener(MouseEvent.CLICK, setDoctorScrollbar);
function setDoctorScrollbar(e:Event):void
{
if(doctor.textHeight > scroller.height)
{
doctorScroller.visible = true;
}
else
{
doctorScroller.visible = false;
}
doctor.scrollV = 1;
}
我不在家取款机。据我所知,代码看起来很可靠,但我想我知道那里发生了什么。尝试连续加载文件,这意味着您首先加载 1 个文件,删除侦听器,然后加载文件 2,依此类推……我认为这应该可行。事件 EVENT.Complete 可能会触发所有其他侦听器。
完全公开,这是我 class 的作业。但是,这已经上交并评分。我真的只想知道为什么它不起作用。
对于 TLFTextField 和外部文件,我遵循了书中的步骤。有用。然后我需要再添加 2 个 TLFTextFields 和 2 个外部文本文件。当我现在 运行 它时, window 弹出但是是空白的。甚至我知道以前工作过的原始 TLFTextField 或文本文件显示也没有。我什至没有碰那个代码。没有错误。我不知道我哪里出错了。我的 class 朋友也有同样的问题。
我的代码如下:
import fl.text.TLFTextField;
import fl.controls.UIScrollBar;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.text.TextFormat;
import flash.events.KeyboardEvent;
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 = 0x003300;
tf.font = "Arial";
tf.size = 14;
t.setTextFormat(tf);
}
var cat:TLFTextField = new TLFTextField();
var cf:TextFormat = new TextFormat();
cat.width = 500;
cat.height = 600;
cat.background = true;
cat.paddingTop = 20;
cat.paddingLeft = 20;
cat.paddingRight = 20;
addChild(cat);
var catLoad:URLLoader = new URLLoader();
catLoad.addEventListener(Event.COMPLETE, catLoaded);
catLoad.load(new URLRequest("cat.txt"));
function catLoaded(e:Event):void
{
var txt:String = URLLoader(e.target).data as String;
cat.text = txt;
cf.color = 0xFCE5CD;
cf.font = "Arial";
cf.size = 16;
cat.setTextFormat(cf);
}
var doctor:TLFTextField = new TLFTextField();
var df:TextFormat = new TextFormat();
doctor.width = 500;
doctor.height = 600;
doctor.background = true;
doctor.paddingTop = 20;
doctor.paddingLeft = 20;
doctor.paddingRight = 20;
addChild(doctor);
var doctorLoad:URLLoader = new URLLoader();
doctorLoad.addEventListener(Event.COMPLETE, doctorLoaded);
doctorLoad.load(new URLRequest("doctor.txt"));
function doctorLoaded(e:Event):void
{
var txt:String = URLLoader(e.target).data as String;
doctor.text = txt;
df.color = 0x68E9E5;
df.font = "Arial";
df.size = 16;
doctor.setTextFormat(df);
}
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);
cf.font = e.target.selectedItem.label;
cat.setTextFormat(cf);
df.font = e.target.selectedItem.label;
doctor.setTextFormat(df);
}
function setFontSize(e:Event):void
{
tf.size = e.target.value;
t.setTextFormat(tf);
cf.size = e.target.value;
cat.setTextFormat(cf);
df.size = e.target.value;
doctor.setTextFormat(df);
}
function setColor(e:Event):void
{
tf.color = e.target.selectedColor;
t.setTextFormat(tf);
cf.color = e.target.selectedColor;
cat.setTextFormat(tf);
df.color = e.target.selectedColor;
doctor.setTextFormat(tf);
}
function setColumns(e:Event):void
{
t.columnCount = e.target.value;
cat.columnCount = e.target.value;
doctor.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;
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;
}
var catScroller:UIScrollBar = new UIScrollBar();
catScroller.move(cat.x + cat.width, cat.y);
catScroller.height = cat.height;
catScroller.scrollTarget = cat;
addChild(catScroller);
catScroller.visible = false;
formatClip;
formatClip.addEventListener(MouseEvent.CLICK, setCatScrollbar);
function setCatScrollbar(e:Event):void
{
if(cat.textHeight > scroller.height)
{
catScroller.visible = true;
}
else
{
catScroller.visible = false;
}
cat.scrollV = 1;
}
var doctorScroller:UIScrollBar = new UIScrollBar();
doctorScroller.move(doctor.x + doctor.width, doctor.y);
doctorScroller.height = doctor.height;
doctorScroller.scrollTarget = doctor;
addChild(scroller);
doctorScroller.visible = false;
formatClip;
formatClip.addEventListener(MouseEvent.CLICK, setDoctorScrollbar);
function setDoctorScrollbar(e:Event):void
{
if(doctor.textHeight > scroller.height)
{
doctorScroller.visible = true;
}
else
{
doctorScroller.visible = false;
}
doctor.scrollV = 1;
}
我不在家取款机。据我所知,代码看起来很可靠,但我想我知道那里发生了什么。尝试连续加载文件,这意味着您首先加载 1 个文件,删除侦听器,然后加载文件 2,依此类推……我认为这应该可行。事件 EVENT.Complete 可能会触发所有其他侦听器。