Jump to content

AS3 - Butões dentro de um movie clip


byrus
 Share

Recommended Posts

Estou a criar um conjunto de butões através de uma class que lê num XML quantos butões e respectivo texto a serem criados.

Parte do código é o seguinte:

Index.fla

function addButton(event:TimerEvent):void {
if(event) {
	event.target.stop() ;
	event.target.reset() ;
	event.target.removeEventListener(TimerEvent.TIMER, addButton) ;
}

var pickOne:uint = Math.floor(Math.random()) ;

var b:AnimButton = new AnimButton(xmlList[0].children()[btnArray[pickOne]].toString()) ;
b.x = 150 ;
b.y = 50  + (btnArray[pickOne] * 30) ;

b.name = "B" + btnArray[pickOne] ;
addChild(b) ;
b.addEventListener(MouseEvent.MOUSE_OVER, buttonHandler) ;
b.addEventListener(MouseEvent.MOUSE_OUT, buttonHandler) ;
b.addEventListener(MouseEvent.CLICK, buttonHandler) ;

btnArray.splice(pickOne, 1) ;

if(btnArray.length > 0) {
	startTimer(100);// time between adding buttons
}
}

AnimButton.as

public function AnimButton(labelTxt:String) {
var tformat1:TextFormat = new TextFormat("Calibri", 16, 0x999999);

tfTop = new TextField() ;
tfTop.mouseEnabled = false ;
tfTop.embedFonts = true ;
tfTop.selectable = false ;
tfTop.autoSize = TextFieldAutoSize.LEFT ;
tfTop.defaultTextFormat = tformat1 ;
tfTop.text = labelTxt ;
tfTop.x = 0 ;
tfTop.y = 0 ;

addChild(tfTop) ;
}

Até aqui tudo bem. Mas precisava que esses butões fossem criados dentro de um layer específico no ficheiro principal fla para que posteriormente os consiga centrar artravés de uma outra class que atualiza dimensões e posicionamentos dos objetos tendo em conta as dimensões doa stage (resize).

Alguém consegue ajudar?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.