下面是我的类,它只读取xml文件并以e4x格式提供内容。不幸的是,在构造函数执行并使用期望值设置xmlProperties
属性之后,有些如何变为null。谁知道我做错了什么?
public class WebService
{
private var _propertiesReader:HTTPService;
private var _xmlProperties:XML;
public function WebService()
{
_propertiesReader = new HTTPService();
_propertiesReader.url = "../resources/properties.xml";
_propertiesReader.resultFormat = "e4x";
_propertiesReader.contentType = "application/xml";
_propertiesReader.addEventListener(ResultEvent.RESULT, function(event:ResultEvent):void
{
_xmlProperties = XML(event.result);
});
_propertiesReader.addEventListener(FaultEvent.FAULT, function(event:FaultEvent):void
{
Alert.show("Unable to load properties content: " + event.fault.message + "\nPlease try again later.", "Properties File Load Error");
});
_propertiesReader.send();
}
public function get xmlProperties():XML
{
return _xmlProperties;
}
}
答案 0 :(得分:1)
_xmlProperties
由文件加载调用(通过回调事件)设置。它不是直接在构造函数中设置的。
在检查_xmlProperty
的值之前,您确定要等待完成呼叫并触发回叫事件吗?