如何在动态文本字段中显示变量?

时间:2016-04-13 23:41:29

标签: actionscript-3 variables

我在屏幕上有一个输入文本字段,我将其设置为用户输入的文本保存为变量,稍后在动态文本框中显示。它有点像一个高分的系统,但有多个变量。

以下是设置变量的帧动作(至少我认为是)

button.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void
{
    var data:String = username.text + " " + date.text + " " + company.text;
    var file:FileReference = new FileReference();
    file.save(data, username.text + " " + date.text + " " + company.text + ".txt");
}

button.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextFrame_8);

function fl_ClickToGoToNextFrame_8(event:MouseEvent):void
{
    nextFrame();
}

var nameperson = username.text;
var dateperson = date.text;
var companyperson = company.text;

我正在尝试在另一个框架中显示变量的操作:

var nScore:Number = 0;

for(var i:Number = 0; i < aQuestions.length; i++) 
{
     if(aUserAnswers[i].toUpperCase() == aCorrectAnswers[i].toUpperCase()) 
     {
          nScore++;
     }
     if(i == aQuestions.length - 1) 
     {
          score_txt.text = nScore.toString();
     }
}

endresult_name.text = nameperson;
endresult_date.text = dateperson;

1 个答案:

答案 0 :(得分:1)

我认为问题在于,当你到达第一帧时,你会直接设置这些变量(文本输入在那一点是空的)。您需要在用户填写完毕并点击按钮后设置它们:

var nameperson:String;
var dateperson:String;
var companyperson:String;

function fl_MouseClickHandler(event:MouseEvent):void
{
    var data:String = username.text + " " + date.text + " " + company.text;
    var file:FileReference = new FileReference();
    file.save(data, username.text + " " + date.text + " " + company.text + ".txt");

    nameperson = username.text;
    dateperson = date.text;
    companyperson = company.text;
}