byrus Posted February 25, 2012 at 03:16 PM Report Share #441130 Posted February 25, 2012 at 03:16 PM 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 More sharing options...
clera Posted February 27, 2012 at 10:23 AM Report Share #441288 Posted February 27, 2012 at 10:23 AM boas, crias um movieClip dentro nessa layer especifica, por exemplo "container_mc". e depois adicionas os butões a esse movieclip.. container_mc.addChild(b); Link to comment Share on other sites More sharing options...
byrus Posted February 27, 2012 at 10:47 PM Author Report Share #441414 Posted February 27, 2012 at 10:47 PM Impecável. Obrigado! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now