我不能在ActionScript 3中更改按钮内动态文本的内容

问题描述:

我从AS3开始,遇到问题。我有一个按钮,并在按钮内有一个动态文本字段。该按钮位于动画片段内,其实例名称为News,按钮的实例名称为collegamento,动态文本的实例名称为Testo。因此,了解这个我triyng改变使用文本的内容:我不能在ActionScript 3中更改按钮内动态文本的内容

News.collegamento.Testo.htmlText="text here"; 

但是Flash是给我这个错误:

ReferenceError: Error #1069: Property Testo not found on flash.display.SimpleButton and there is no default value. at app_fla::MainTimeline/parseXML()[app_fla.MainTimeline::frame1:21] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/onComplete()

如何解决它的任何想法?谢谢!

恐怕您无法更改SimpleButton中动态文本字段的文本值。您必须改为使用MovieClip。原因是SimpleButton不是从Sprite继承而是从DisplayObject继承的。

编辑: 其实我没有发现有黑客攻击的方式来做到这一点:

var upState:DisplayObjectContainer = myBtn.upState as DisplayObjectContainer; 
var myTxt:TextField = upState.getChildAt(1) as TextField; 
myTxt.text = "hack"; 

每个国家做到这一点我想