Comunidad de diseño web y desarrollo en internet online

Slide show con fades | Problema con cast

Citar            
MensajeEscrito el 16 Ene 2010 08:52 pm
El objetivo de este código es hacer un slide-show que funcione de la siguiente forma. Apilo en la Display List todas las imégenes. Con Timer le quito a la última (la de mayor índice) el alpha hasta que el mismo se anule y la mando en este momento al início de la lista devolviendole el alpha para 1. Me parece que no está funcionando por un problema de "cast" en la función esmaecer.

Código ActionScript :

var aEnderecos:Array = [ "autitos/autito1.jpg", "autitos/autito2.jpg", "autitos/autito3.jpg" ]
var aCarregadores:Array = new Array();
var aContainers:Array = new Array();
var stepFade:Number = 0.01;
var photoTimer:Timer;
var indiceTop:int = aEnderecos.length - 1;

for ( var i:int = 0; i<aEnderecos.length; i++ )
{
   aCarregadores[i] = new Loader();
   aContainers[i] = new Sprite();
   aContainers[i].x = 50;
        aContainers[i].y = 50;
   this.addChild( aContainers[i] );
   aContainers[i].addChild(aCarregadores[i]);
   aCarregadores[i].load( new URLRequest ( aEnderecos[i] ) );
   if (i == aEnderecos.length -1)
   {
      aCarregadores[i].contentLoaderInfo.addEventListener(Event.COMPLETE,loadComplete);
   }
}

function loadComplete(event:Event):void 
{
  photoTimer= new Timer(8000); 
  photoTimer.start(); 
  photoTimer.addEventListener(TimerEvent.TIMER,fadePhoto); 
}

function fadePhoto(event:TimerEvent):void 
{
   addEventListener( Event.ENTER_FRAME, esmaecer )
}

function esmaecer ( event:Event ):void
{
   var target:DisplayObject = this.getChildAt(indiceTop);
   target.alpha -= stepFade;
   if ( target.alpha <= 0 )
   {
      removeEventListener( Event.ENTER_FRAME, esmaecer );
      this.setChildIndex(target, 0);
      target.alpha = 1;
   }
}

Por Ishkandar

Claber

303 de clabLevel



Genero:Masculino  

firefox
Citar            
MensajeEscrito el 18 Ene 2010 02:38 am
Estudiando un poco encontré la solución, el cast dentro de la función esmaecer debe hacerse así:

Código ActionScript :

var target:DisplayObject = this.getChildAt(indiceTop) as DisplayObject;

Por Ishkandar

Claber

303 de clabLevel



Genero:Masculino  

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.