我正在尝试阅读并解析XML
文件,但Builder会不断抛出Error #2124: Loader file is an unknown type.
以下是我执行操作的代码
<?xml version = "1.0" encoding = "utf-8"?>
<s:WindowedApplication xmlns:fx = "http://ns.adobe.com/mxml/2009"
xmlns:s = "library://ns.adobe.com/flex/spark"
xmlns:mx = "library://ns.adobe.com/flex/mx"
width = "1920" height = "1080"
preinitialize="Awake(event)"
applicationActivate="FS(event)"
x = "0" y = "0">
<fx:Script>
<![CDATA[
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.errors.IOError;
import flash.events.IOErrorEvent;
import flash.events.ErrorEvent;
private var tempStr:String;
private var eventTitle:Array;
private var data:XML = new XML();
private var titleArray:Array;
private function Awake(reference:Event):void
{
var str:String = "content.xml"
Start(str);
}
private function FS(ref_fs:Event):void
{
stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
}
private function Start(address:String):void
{
var xmlLoader:Loader = new Loader;
xmlLoader.addEventListener(ErrorEvent.ERROR, OpenError);
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, OpenError);
xmlLoader.addEventListener(Event.COMPLETE, DoXML);
xmlLoader.load(new URLRequest(address));
}
private function DoXML(ref_xml:Event):void
{
data = new XML(ref_xml.target.data);
var rawData:String = data;
titleArray = new Array;
var size:int = 0;
data = data.children()[1];
size = data.children().length();
for(var loop:uint = 0; loop < size; loop++)
{
titleArray[loop] = data..ICE[loop].BAS[0];
}
eventTitle = new Array;
eventTitle = titleArray;
Finalise(eventTitle);
}
private function Finalise(tempArray:Array):void
{
tempStr = String(tempArray[0]);
bas.text = tempStr;
}
private function OpenError(ref_err:IOErrorEvent):void
{
trace(ref_err.text);
}
]]>
</fx:Script>
<fx:Style source = "Player.css"/>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:SWFLoader id = "SwfPlayerContainer" x = "320" y = "180" width = "1280" height = "720"/>
<s:TextInput id="bas" x="507" y="128" enabled="false"/>
答案 0 :(得分:0)
var xmlLoader:URLLoader = new URLLoader;
它应该是URLLoader。这就是为什么它需要不同的文件格式,文件是XML
。