Convertir Preload en AS2
Hola a todos,
Hace unos dias puse un hilo en el que hablaba de como podia convertir una parte de un codigo de AS3 a AS2 que no hay manera que me funcione pero no se acabo de solucionar.
http://www.domestika.org/foros/5-programacion_cliente/hilos/83934-convertir_preload_de_as3_a_as2
Me falta muy poco pero claro, ese poco me fastidia el preloader. Os paso los dos codigos, a ver si veis el fallo del codigo AS2 que intenté hacer yo. Si teneis alguna duda por favor preguntarlo.
CODIGO ORIGINAL EN AS3
// keep the preloader on this frame until the movie is loaded
stop();
MovieClip(parent).stop();
// percent variable tracks what percent of the movie is loaded
var percent:Number = 0;
var oldPercent:Number = 0;
circle.width=0;
circle.height=0;
import flash.display.*;
// run the following code every time progress is made loading the movie
MovieClip(parent).loaderInfo.addEventListener (ProgressEvent.PROGRESS, loading);
function loading(event:ProgressEvent):void {
// updates the percent variable with the percent of the movie loaded
percent = Math.round(event.bytesLoaded/event.bytesTotal*100);
if(oldPercent<percent){
oldPercent=percent;
spawnPBCO();
}
// updates the textbox with the current percent
percent_txt.text = percent + "";
// updated the loading bar
circle.width=percent*.6;
circle.height=percent*.6;
// if the loading is complete, execute the finished() method
if(percent==100){
finished();
}
}
// plays the movie if it has loaded instantly
if(MovieClip(parent).loaderInfo.bytesLoaded==MovieClip(parent).loaderInfo.bytesTotal){
finished();
}
// runs when the loading is complete
function finished(){
// sets the text to 100 and the loading bar to full width
percent_txt.text = "100";
circle.width=60;
circle.height=60;
// removes listener from the loader
MovieClip(parent).loaderInfo.removeEventListener(ProgressEvent.PROGRESS,loading);
// plays the rest of the animation
play();
}
function spawnPBCO(){
var newPBCO:Pbco = new Pbco();
newPBCO.x = 0;
newPBCO.y = 0;
newPBCO.rotation = Math.random()*360;
addChild(newPBCO);
}
MI CODIGO EN AS2
// keep the preloader on this frame until the movie is loaded
stop();
_parent.stop();
var porcentaje;
var oldporcentaje;
circle.width=0;
circle.height=0;
//function cargando() {
onEnterFrame = function(){
// Declaración de variables
var total, cargados, porcentaje, oldporcentaje, rotacion;
// A la variable "total" se le asigna el tamaño de la pelicula en bytes
total = _root.getBytesTotal();
// A la variable "cargados" se le asignan el total de bytes hasta el
//momento descargados de la web
cargados = _root.getBytesLoaded();
//Por medio de una regla de tres obtiene el porcentaje cargado y redondea el valor con la función
//"Math.floor"
porcentaje = Math.floor((cargados*100)/total);
//trace("El porcentaje es: " + porcentaje);
//Asigna al campo de texto porcentaje_txt el porcentaje cargado
trace("porcentaje" + porcentaje);
trace("oldporcentaje" + oldporcentaje);
percent_txt.text = porcentaje + "";
if(oldporcentaje<percent){
oldporcentaje=porcentaje;
spawnPBCO();
}
//spawnPBCO();
circle._width = porcentaje * .6;
circle._height = porcentaje * .6;
// if the loading is complete, execute the finished() method
if (cargados == total) {
trace ("Se ha cargado completamente");
finished();
//clearInterval(hiloPrecarga);
delete this.onEnterFrame;
play();
}
}
// setInterval nos servira para que la función "cargando" se ejecute cada 1 milisegundo
// Asi, nuestra función revisara constantemente la cantidad de bytes descargados
// y solo iniciara la pelicula hasta que la descarga termine
// la variable "hiloPrecarga" nos servira para saber que esta corriendo nuestra función
// y frenar su ejecución cada milisegundo por medio de "clearInterval"
//var hiloPrecarga = setInterval(cargando, 1);
// runs when the loading is complete
function finished(){
// sets the text to 100 and the loading bar to full width
trace("Entra en finished");
percent_txt.text = "100";
circle.width=60;
circle.height=60;
_root.play();
}
function spawnPBCO(){
this.attachMovie("circulo","micirculo",getNextHighestDepth());
//micirculo._x = precarga_mc.circle._x;
//micirculo._y = precarga_mc.circle._y;
//micirculo._x = 0;
//micirculo._y = 0;
rotacion = Math.random()*360;
trace("Rotacion: " + rotacion);
micirculo._rotation = rotacion;
}
danideu
por cierto, la solución (fijaros en la variable "nom") ha sido la siguiente:
// keep the preloader on this frame until the movie is loadedstop();
//MovieClip(parent).stop();
_parent.stop();
var percent = 0;
var oldPercent = 0;
var rotacion;
var porcentaje=0;
var oldporcentaje=0;
circle.width=0;
circle.height=0;
var nom=0;
//function cargando() {
onEnterFrame = function(){
// Declaración de variables
//var total, cargados, porcentaje, oldporcentaje;
// A la variable "total" se le asigna el tamaño de la pelicula en bytes
total = _root.getBytesTotal();
// A la variable "cargados" se le asignan el total de bytes hasta el
//momento descargados de la web
cargados = _root.getBytesLoaded();
//Por medio de una regla de tres obtiene el porcentaje cargado y redondea el valor con la función
//"Math.floor"
porcentaje = Math.floor((cargados*100)/total);
//trace("El porcentaje es: " + porcentaje);
//Asigna al campo de texto porcentaje_txt el porcentaje cargado
percent_txt.text = porcentaje + "";
if (oldporcentaje < porcentaje){
oldporcentaje = porcentaje;
spawnPBCO();
}
trace("porcentaje " + porcentaje);
trace("oldporcentaje " + oldporcentaje);
//spawnPBCO();
circle._width = porcentaje * .6;
circle._height = porcentaje * .6;
// if the loading is complete, execute the finished() method
if (cargados == total) {
trace ("Se ha cargado completamente");
finished();
//clearInterval(hiloPrecarga);
delete this.onEnterFrame;
play();
}
}
// setInterval nos servira para que la función "cargando" se ejecute cada 1 milisegundo
// Asi, nuestra función revisara constantemente la cantidad de bytes descargados
// y solo iniciara la pelicula hasta que la descarga termine
// la variable "hiloPrecarga" nos servira para saber que esta corriendo nuestra función
// y frenar su ejecución cada milisegundo por medio de "clearInterval"
//var hiloPrecarga = setInterval(cargando, 1);
// runs when the loading is complete
function finished(){
// sets the text to 100 and the loading bar to full width
trace("Entra en finished");
percent_txt.text = "100";
circle.width=60;
circle.height=60;
_root.play();
}
function spawnPBCO(){
var micirculo=this.attachMovie("circulo","micirculo"+nom,getNextHighestDepth());
micirculo._x = 0;
micirculo._y = 0;
rotacion = Math.random()*360;
micirculo._rotation = rotacion;
trace("Rotacion: " + rotacion);
nom++;
trace("Nom: " + nom);
}
danideu
Hola Diego,
Verdaderamente eres un crack ... el archivo está perfecto ahora, ya hace el preload como tenia que hacerlo....
Un millon de gracias..
SAludos.
diego_lorenzo
Hola Dani,
Ya tienes en tu mail el .fla corregido. Si necesitas que explique las correciones o demás ya me avisas.
Saludos
danideu
en cuanto tenga la solución os digo algo para que todos podáis verla.
Diego esta intentando solucionarlo, ya le he pasado los archivos.
Gracias de niuevo Diego.
danideu
y donde puedo ver tu e-mail?.. he entrado en tu perfil pero no lo he visto.
Saludos
diego_lorenzo
Si no tienes inconveniente en enviármelo al mail (al ser comprado a lo mejor), mañana te podría mirarlo bien.
Saludos