简体   繁体   English

在AS3中的类中显示SWF中的文本(Flash)

[英]Show a text in the SWF from a class in AS3 (flash)

i have a dynamic text on my scene called testtext, in the accions i can show a text simple by testtext.text = "my content"; 我在场景中有一个动态文本,称为testtext,在某些情况下,我可以通过testtext.text =“ my content”显示简单的文本;

But now i want to do this from a class, if i copy directly the instruccion like i do normaly it doest work. 但是现在我想从一堂课上做这件事,如果我像我通常那样直接复制instruuccion,那是行不通的。 What i need to do? 我需要做什么? Thanks! 谢谢!

your class is self contained and not aware of the outside world. 您的班级是独立的,不了解外界。 You will need to create a function that you can feed it the textfield name so it can then target it. 您将需要创建一个函数,可以向其提供文本字段名称,以便随后将其定位。

so from inside your class create a public function like this: 因此,请在您的类内部创建一个如下的公共函数:

public var myTextField:TextField;

public function setTextTarget(tf:TextField):void
{
   myTextField = tf;
}

public function updateText(msg:String):void
{
  myTextField.text = msg;
}
private function randomFunction():void
{
  // update the textfield from an internal function
  myTextField.text = "text here"
}

So in your FLA file where you have imported your class it will look something like this: 因此,在您导入了类的FLA文件中,它看起来像这样:

var myClass:ClassName = new ClassName;
myClass.setTextTarget(TextFieldName);
myClass.updateText("text here");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM