Custom button class


hello,

i creating button class, problem when add
textfield, hand cursor doesn't show, i've tried mousechildren
with no results.

i want know if best way create custom button,
only need 3 states , label on button, here's code:

package {
//import flash.display.displayobjectcontainer;
import flash.display.sprite;
import flash.display.simplebutton;
import flash.display.loader;
import flash.events.event;
import flash.net.urlrequest;

import flash.text.textfield;
import flash.text.textformat;
import flash.text.textfieldautosize;

public class boton extends sprite {
private var _boton:simplebutton;
private var _etiqueta:sprite;
private var home:object;
private var formato:textformat;
private var texto:textfield;
private var mensaje:string;
private var alineacion:string;
private var textocreado:boolean = false;
private var ancho:number;
private var alto:number;

public function boton(level:object, txt:string) {
home = level;
mensaje = txt;
_etiqueta = new sprite();
_etiqueta.buttonmode = false;
_etiqueta.mousechildren = false;

_boton = new simplebutton();
_boton.upstate = cargarimagen('boton_normal.png');
_boton.overstate = cargarimagen('boton_over.png');
_boton.downstate = cargarimagen('boton_down.png');
_boton.hitteststate = _boton.upstate;

addchild(_boton);
}

protected function cargarimagen(img:string):sprite {
var picloader:loader = new loader();
var imagen:string = img;
var request:urlrequest = new urlrequest(imagen);

picloader.contentloaderinfo.addeventlistener(event.complete, imagencargada);
picloader.load(request);
var carg:sprite = new sprite();
carg.addchild(picloader);
return carg;
}

private function imagencargada (ev:event) {
if (!textocreado) {
textocreado = true;
ancho = _boton.width;
alto = _boton.height;
crearetiqueta();
}
}
public function crearetiqueta(posx:int = 0, posy:int = 0) {
formato = home.formato_boton;
texto = new textfield();
texto.autosize = textfieldautosize.center;
texto.selectable = false;
texto.embedfonts = true;
texto.antialiastype = "advanced";
texto.defaulttextformat = formato;
texto.x = posx;
texto.y = posy;
texto.width = 100;
texto.text = mensaje;
texto.selectable = false;
texto.x = (ancho - texto.width) / 2;
texto.y = (alto -texto.height) / 2;
_etiqueta.addchild(texto);
addchild(_etiqueta);
}
}
}


best regards!
hugo.



More discussions in ActionScript 3


adobe

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support