我有类似的东西
1.mxml
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init()">
<mx:Script source="_Public.as"/>
</mx:Application>
_public.as
[Bindable]
public var config:XML;
public function init():void
{
var request:URLRequest = new URLRequest("config/config.xml");
try {
loader.load(request);
} catch (error:Error) {
trace("Unable to load requested document.");
}
loader.addEventListener(Event.COMPLETE,init_continue);
}
public function init_continue(event:Event):void {
config = new XML(loader.data);
}
配置已填满,我可以使用它。之后,我按下1.mxml
中的按钮,然后创建2.mxml popup
(没有初始化)。
config.xml中
<data>
<LOGIN_BUTTON>Inloggen</LOGIN_BUTTON>
</data>
现在我想访问config.LOGIN_BUTTON
。但是配置并没有给我任何东西。
是否可以获得配置“访问”?
答案 0 :(得分:1)
首先,始终先添加一个侦听器,然后再发出load(),如下所示:
loader.addEventListener(Event.COMPLETE, init_continue);
try {
loader.load(request);
} catch (error:Error) {
trace("Unable to load requested document.");
}
否则,加载可能很快就足以跳过你的监听器。那么,对你的问题。我不确定“访问”config.LOGIN_BUTTON是什么意思。但是如果成功加载了xml数据,那么XML结构应该可以作为config.LOGIN_BUTTON
访问,即后者应该返回一个XMLList对象。我担心我需要更清楚地解释你想要达到的目标,以提供更好的答案。
修改:根据您的跟进,我认为最好为标签设置一个单独的变量,如下所示:
[Bindable]
private var buttonLabel:String;
....
public function init_continue(event:Event):void {
config = new XML(loader.data);
buttonLabel = config.BUTTON_LABEL;
}
然后在2.mxml:
<mx:FormItem label="{buttonLabel}" required="true"
我不确定变量绑定是否在XML结构中起作用。
答案 1 :(得分:0)
您可以使用
访问它Application.application.config.LOGIN_BUTTON