Actionscript 2.0 to 3.0
The language ActionScript 2.0 / 1.0
is limited by having few classes, assuming that it was created only to supply some actions of the Flash, including is not event-oriented, which makes it difficult to handle errors. We can practically say that, in relation to ActionScript 3.0
, just like the name.
The errors occur because many actions you did on AS2 are nothing like AS3, so by converting 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 the release of version 3.0 took place.
At this link wikipedia you can find more information.
Code AS2
Regarding your question, the code to load an XML file into ActionScript 2.0
is just like 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 may occur will be handled by the method onData
. You can access the language reference 2.0 at this link.
Code AS3
The code to load the XML into ActionScript 3.0
is a little sharper, but more functional in relation to the treatment of events.
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 language reference 3.0 at this link.
Completion
If you intend to change versions of Actionscript, 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 conversion is not possible, treat errors with the methods cited and look for some actions in the code reference in the Adobe links.
What mistake happens when?
– Felipe Avelar
I just edited above, I basically found that I am implementing in AS2, not As3 so the above code does not give. There is some load url for AS2?
– user3644929
I tested the first example in AS2 and it worked correctly... What error appears? I would recommend you use Actionscript 3.0, this is not possible?
– bio
Yes it is, but to convert after me error "1046: Type was not found or was not a Compile-time Constant: Void."
– user3644929
The first example, namely to load locally works well. But I want to host xml on the web server and I can’t get it through the url
– user3644929