Actionscript - TLFTextField с внешними текстовыми файлами, при запуске файла ничего не отображается - PullRequest
0 голосов
/ 25 ноября 2018

Полное раскрытие, это было задание для моего класса.Однако, это уже было включено и оценено.Я действительно просто хочу знать, почему это не работает.

Я выполнил шаги в книге для TLFTextField и внешнего файла.Оно работает.Затем мне нужно было добавить еще 2 TLFTextFields с еще 2 внешними текстовыми файлами.Когда я сейчас запускаю его, окно всплывает, но остается пустым.Даже оригинальный TLFTextField или текстовый файл, который, как я знаю, работал раньше.Я даже не трогал этот код.Там нет ошибок.Я не могу понять, где я ошибся.У моего одноклассника тоже была такая же проблема.

Мой код указан ниже:

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 Ответ

0 голосов
/ 28 ноября 2018

я не дома, атм.Насколько я вижу, код выглядит солидно, но я думаю, что знаю, что там происходит.Попробуйте загрузить файлы в ряд, это означает, что вы сначала загружаете 1 файл, удаляете прослушиватель, а затем загружаете файл 2 и т. Д. Я думаю, что это должно работать.Вполне возможно, что событие EVENT.Complete вызовет всех остальных слушателей.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...