Foros del Web » Creando para Internet » Flash y Actionscript »

duda en codigo preloader

Estas en el tema de duda en codigo preloader en el foro de Flash y Actionscript en Foros del Web. Hola!. tenemos este código en AS2.0, es un preloader completo, todo programado sin ningún objeto de biblioteca, bajad hasta donde dice: **vars only for the ...
  #1 (permalink)  
Antiguo 24/03/2009, 09:17
 
Fecha de Ingreso: marzo-2009
Ubicación: Elda - Alicante
Mensajes: 55
Antigüedad: 15 años, 1 mes
Puntos: 0
duda en codigo preloader

Hola!. tenemos este código en AS2.0, es un preloader completo, todo programado sin ningún objeto de biblioteca, bajad hasta donde dice: **vars only for the example version**//:
gracias.

Código PHP:
//bar preloader begins with 0
//bar_l (length bar) is how long you wanna the whole bar be 
bar=0
bar_l
=180//
//bar_w is the height of bar
bar_w=10
//cube_l is length of curved lines and the space between them
cube_l=10
//colors-->//
color_line=0xFFFFFF
color_line_limit
=0x000000
color_curved_lines
=0x666666
color_text
=0xFFFFFF
//<--colors//
size_text=16
//i create the first bar
_root.createEmptyMovieClip("line",2)
line.lineStyle(2,color_line,50)
//this function declares the constant size of the white bar
function keep_drawed(){
line.beginFill(color_line,100)
line.moveTo(0,0)
line.lineTo(bar,0)
line.lineTo(bar,bar_w)
line.lineTo(0,bar_w)
line.lineTo(0,0)
line.endFill()}
//here i declare the location of all bars
line._x=Stage.width/2-(bar_l/2)
line._y=Stage.height/2
//now, i create a second bar, this "line_limit" declares the grey bar
line.duplicateMovieClip("line_limit",1)
line_limit.beginFill(color_line_limit,75)
line_limit.moveTo(0,0)
line_limit.lineTo(bar_l,0)
line_limit.lineTo(bar_l,bar_w)
line_limit.lineTo(0,bar_w)
line_limit.lineTo(0,0)
line_limit.endFill()
//i add the curved lines into a mc called "cub"
_root.createEmptyMovieClip("cub",3)
cub.createEmptyMovieClip("cube",4)
cub.cube.beginFill(color_curved_lines,25)
cub.cube.moveTo(0,0)
cub.cube.lineTo(cube_l,0)
cub.cube.lineTo(cube_l*2,bar_w)
cub.cube.lineTo(cube_l,bar_w)
cub.cube.lineTo(0,0)
cub.cube.endFill()
//cubes: Array
cubes=[]
//quantity of curved lines is length of the grey bar divided by 2
cubes_max=Math.round(bar_l/2)
//direction of curved lines || default: "left"
direction_lines="left"
//curved lines declarations
for(c=1;c<=cubes_max;c++){
    
cub.cube.duplicateMovieClip("cube"+c,4+c)
    
cubes[c]=cub["cube"+c]
    
cubes_width=(cube_l*2)*c
if(direction_lines=="right"){cubes[c]._x=(Math.floor(line._x-cubes_width)+bar_l)}//=(barl_l*3)-cubes_width
if(direction_lines=="left"){cubes[c]._x=line._x+cubes_width}
    }
    
//cub declarations
    
cub._y=line._y
    
//the origibal "cube" is invisible
    
_root.cub.cube._visible=false
//MOVES CURVE LINES
//if you want to move the curved lines: write TRUE
//if you don't want to move curved lines: write FALSE
    
lines_movement=true
    
//function to move curved lines to right direction
    
function move_lines(speed){
    for(
c=1;c<=cubes_max;c++){
    if(
direction_lines=="right"){
    
cubes[c]._x+=speed
    
if(cubes[c]._x>cubes_width){
        
cubes[c]._x=-(cube_l*2)}}
    
//function to move curved lines to left direction
    
if(direction_lines=="left"){
    
cubes[c]._x-=speed
    
if(cubes[c]._x<-(cube_l*2)){
        
cubes[c]._x=cubes_width-(cube_l*2)}}
    }
}
    
//here i crete a "mask" to hide parts of curved lines
_root.createEmptyMovieClip("mask",this.getNextHighestDepth())
mask.beginFill(0xFF0000,100)
mask.moveTo(0,0)
mask.lineTo(bar_l,0)
mask.lineTo(bar_l,bar_w)
mask.lineTo(0,bar_w)
mask.lineTo(0,0)
mask.endFill()
mask._x=line._x
mask
._y=line._y
//mask...
cub.setMask(mask)
//here i create the text you'll see under the bar
_root.createTextField("info",this.getNextHighestDepth(),Stage.width/2-100,line._y+bar_w,200,bar_w*size_text)
//now, i specify a new format to the text
var txt_fmt:TextFormat = new TextFormat();
txt_fmt.color color_text;
txt_fmt.font="Digital"
txt_fmt.align "center"
txt_fmt.size=size_text
txt_fmt
.bold=true
info
.multiline =true;





//**vars only for the example version**//
num=0;bar=0;line.clear();bar_vel1;click_screen=false
//****//
//this function loads the bytes and total bytes of .swf file

    
onEnterFrame=function(){
    
load_movie()
    
keep_drawed()
    if(
lines_movement){move_lines(0.5)}
    
    
//**vars only for the example version**//
    
if(bar<bar_l){bar+=bar_vel}
    
porcent=Math.round((bar*100)/bar_l)
    
info.text=Math.round(porcent)+"%"
    
info.setTextFormat(txt_fmt);
    
    if(
info.text=="100%"){
        
line.clear();line_limit.clear()
        
line.removeMovieClip();line_limit.removeMovieClip()
        
cub.removeMovieClip();mask.removeMovieClip();info.text=""
        
nextFrame()

    }
}

stop(); 
Si copiais y pegais en el fotograma 1 de una escena vereis que funciona reproduce de 0% a 100% y da paso a lo que haya a continuación.
El problema es que un preloader no debe mostrar tranquilamente el recorrido de la barra, (este código está hecho así por que es un ejemplo) si no que debe de usar los bytes cargados y los totales para darse más prisa en terminar la animación.
Lo he intentado pero los números se me quedan parados.
Cómo aplico el siguiente código en el código anterior y que funcione?:

Código PHP:
bytes=_root.getBytesLoaded()
    
bytes_t=_root.getBytesTotal()

    
porcent=Math.round((bytes*100)/bytes_t)
    
info.text=porcent+"%"

    
if(info.text=="NaN%"){info.text=0+"%"}
    
info.setTextFormat(txt_fmt);
    
bar=Math.round((bytes*bar_l)/bytes_t
  #2 (permalink)  
Antiguo 25/03/2009, 08:23
 
Fecha de Ingreso: marzo-2009
Ubicación: Elda - Alicante
Mensajes: 55
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: duda en codigo preloader

Hola!

El código que hay que cambiar sólo hace referencia a la condición - if - y a las variables, ya que el código de prueba saca los valores de las variables, de las medidas de la barra y no de los bytes cargados de la película, yo ya lo he intentado pero no me sale bien, alguien que me eche un cable, plis??. sólo hay que leer la parte de abajo del código, no el código entero.

Muchas gracias!!
  #3 (permalink)  
Antiguo 01/04/2009, 11:04
 
Fecha de Ingreso: marzo-2009
Ubicación: Elda - Alicante
Mensajes: 55
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: duda en codigo preloader

Hola.
Nadie echa una mano? que no se pierda el mensaje.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:49.