imageExtended
Septiembre 10th, 2008Aquí voy a poner una clase que me ha hecho falta. Se trata de una clase que extiende la clase Image añade un evento cuando se ha cargado que espera un frame. Si no se espera este frame no coloca la imagen y no se sabe cual es el alto y el ancho entre otras cosas.
No se si habrá otra forma de hacerlo.
-
-
package com.esneo.imageExtended
-
{
-
import flash.events.Event;
-
-
import mx.controls.Image;
-
-
public class ImageExtended extends Image
-
{
-
public static const COMPLETE_AND_READY:String="completeAndReady";
-
-
public function ImageExtended()
-
{
-
super();
-
this.addEventListener(Event.COMPLETE,doComplete);
-
}
-
-
private function doComplete(e:Event):void
-
{
-
this.removeEventListener(Event.COMPLETE,doComplete);
-
this.addEventListener(Event.ENTER_FRAME,doEnterFrame);
-
}
-
-
private function doEnterFrame(e:Event):void
-
{
-
trace(e.target.width+':'+e.target.height);
-
// cuando pasa un frame ya está listo para usarse
-
// ya tiene height y width
-
if (width!=0 || height!=0)
-
{
-
this.removeEventListener(Event.ENTER_FRAME,doEnterFrame);
-
this.dispatchEvent(new Event(COMPLETE_AND_READY));
-
}
-
}
-
}
-
}
-
