ActionScript 2.0 for 3.0
The ActionScript 2.0 / 1.0
language is limited because it has a few classes, assuming that it was only created to handle some Flash actions, and is not event-oriented, making it difficult to handle errors. We can practically say that, in relation to ActionScript 3.0
, it looks just like the name.
Errors occur because many actions you performed in AS2 are not anything like AS3, so when you convert your project to a different version, the conflict will actually happen. Not to mention that version 2.0 of the language has not been supported since 2006, when version 3.0 was released.
In this link of wikipedia you can find more information.
AS2 Code
Regarding your question, the code for loading an XML file into ActionScript 2.0
is exactly as below:
var xml:XML = new XML(); //Cria o objeto XML
//Define a função que será executada ao carregar o arquivo
xml.onLoad = function(resposta) {
if(resposta) {
trace("Carregou XML"); //Mostra no Output que carregou o arquivo xml
trace(xml);
}
else {
trace("Erro ao carregar XML!");
}
}
//Ao ocorrer um evento do servidor, como um erro, ele executará esta função:
xml.onData = function(resposta) {
trace("Resposta do servidor: ");
trace(resposta);
}
xml.load("arquivo.xml"); //Executa a ação para carregar. Qualquer URI, seja externa ou local, é aceita.
Errors that can happen will be handled by the onData
method. You can access the 2.0 language reference this link . / p>
AS3 Code
The code to load XML into ActionScript 3.0
is a little sharper, but more functional in relation to event handling.
var xml:XML; //Cria a referência ao objeto XML
var urlLoader:URLLoader = new URLLoader(); //Responsável por carregar arquivos
var urlRequest:URLRequest = new URLRequest("arquivo.xml"); //Objeto que contém e trata URLs
urlLoader.load(urlRequest);
urlLoader.addEventListener(Event.COMPLETE, carregouXML);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, erroXML);
//Evento ao carregar o XML com sucesso!
function carregouXML(e:Event):void {
xml = new XML(urlLoader.data);
trace("Carregou XML");
trace(xml);
}
//Erro ao carregar XML
function erroXML(e:IOErrorEvent):void {
trace("Erro ao carregar XML: "+e);
}
Errors can be handled by events IOErrorEvent
and SecurityError
. You can access the 3.0 language reference this link .
Conclusion
If you intend to make the ActionScript versions change, keep in mind that the entire code of your game will have to be adapted. I particularly recommend that you use the latest version 3.0, with more Web resources, used in Flex and Flash and with Adobe AIR Desktop and Mobile support.
Now, if the conversion is not possible, treat the errors with the methods mentioned and try to review some actions in the code reference in the Adobe links.