Flash Player loses focus with button + removeChild
Well, this week, I was doing a little game that to the player start to play needs click in one “start game” button and after uses the keyboard to control the character moves. So until this point all OK, but what i didn’t told you is that when click’s in the “start game”, it disappears with one removeChild() (because it appears above all the stage).
After this, my character was no more moving… I fought “wow could be my InputManager class not working so fine…”, but I tried find some bug or something wrong and nothing. After some tries, accidentally I removed the buttonMode = true - propertie that i was defining to that my “start game” Movie Clip behaviors like Button - and tcharam… All working…..
At first we need remind that Keyboard events will just works when Flash Player get focus. And accidentally I found a way of Flash Player loses focus with on removeChild().
So what is happening here?!
First, open the swf file (focus it); after, click at the button (button with focus); later on, the button is removed from the stage (the focus is removed together with the button - so here are the problem). Now if I click on the stage, or other local in the swf file (Flash Player will get focus again) and it will works…
Here is a source code as example :
var spBtn = new Sprite(); spBtn.buttonMode = true; spBtn.graphics.beginFill( 0xff0000, .4 ); spBtn.graphics.drawRect( 0, 0, this.stage.stageWidth, this.stage.stageHeight ); spBtn.graphics.endFill(); addChild( spBtn ); addEventListener ( KeyboardEvent.KEY_DOWN, managekeyDown ); spBtn.addEventListener( MouseEvent.MOUSE_DOWN, mouseClick ); function mouseClick ( e : Event ) : void { spBtn.removeEventListener( MouseEvent.MOUSE_DOWN, mouseClick ); removeChild( spBtn ); } function managekeyDown ( e : KeyboardEvent ) : void { if ( e.keyCode == Keyboard.LEFT ) { trace ( “JUST TRACE IF FLASH PLAYER HAVE FOCUS ON IT” ); } }
======= Updated at August 1º (expect update more the blog…) ======
To fix this issue you must reset the focus to the stage. So the code will change just in this part:
function mouseClick ( e : Event ) : void { spBtn.removeEventListener( MouseEvent.MOUSE_DOWN, mouseClick ); removeChild( spBtn ); //After the remove child we’ll reset the focus to stage this.stage.focus = this; }
![]()
From now on just English…
Well guys, unhappily - to whom just want to know in Portuguese - and happily to the rest of the World, I’ll be writing just in English on my blog. I’m taking this action looking forward an better transparency to change informations on line, once the majority of the ActionScript Gurus communicate each others in English and too because I’ve a lot of abroad ActionScript friends.
So, to those that want continues seeing ActionScript related subjects in Portuguese, I strongly advice join to the AUGRS ( Adobe User Group Rio Grande do Sul) discussion list.
To the others, we’ll be in touch.
== Versão em Português / Portuguese Version ==
Bom pessoal, infelizmente - para aqueles que só saber Português - e felizmente para o resto do mundo, estarei blogando de agora em diante somente em Inglês. Estou tomando esta medida visando uma melhor transparência para troca de informações online, uma vez que a maioria dos gurus da área se comunicam em inglês e também levando em conta de que tenho muitos amigos da área no exterior.
Então, para quem quiser continuar vendo assuntos relacionados a ActionScript em Português, aconselho estes a participarem da lista de discussão do AUGRS ( Adobe User Group Rio Grande do Sul).
Aos demais, estaremos em contato, porém agora Inglês.
No commentsO que é Singularity?
Bom pessoal, voltando a blogar depois de um tempo (espero não perder o pique novamente por conta de muito trabalho, conforme aconteceu).
Afinal de contas, agora até eu andei ficando curioso com esse tal de Singularity do Aral Balkan.
Afinal de contas, o que é o Singularity? Uma nova Tecnologia em Flash? RIA? Um site em Web 2.0?
Como a curiosidade é tanta, estou colocando essa imagem no meu blog para ser um dos primeiros a saber o que que é isso! Logo que sair a descrição ou mesmo for lançada alguma coisa estarei aqui falando.
2 commentsPapervision3D 2.0 Alpha
Foi lançada hoje de madrugada a tão esperada versão 2.o da Biblioteca Papervision 3D.
Na nova versão possuímos recursos tais como: ShadeMaterials, Shaders, ASCollada (agora com suporte a animação), Frustrum Culling, Multiple Viewports, Render to Scene e muito mais…
Para quem quiser ter uma idéia do que podemos fazer no a nova versão dê uma olhada no link abaixo que exemplifica aplicação de iluminação de phong e bumpMapping.
swf:
http://www.rockonflash.com
FLA:
http://www.rockonflash.com
Então aproveite agora mesmo para fazer o download da nova versão a partir do SVN no endereço: http://papervision3d.googlecode.com/svn/trunk/
Abraços.
2 comments
Material (artigo e exemplos) do minicurso de ActionScript 3.0 para Games
Olá pessoal,
fiquei meio parado nas duas últimas semanas por causa do SBGames 2007 e de uns projetos pessoais.
O SbGames 2007 foi simplesmente ótimo e o pré-evento GDS superou as expectativas.
O AUGRS apresentou duas palestras, uma de AS2 e Advergames com Pedro Taranto e Alberto Amaral e a minha de AS3 para Games.
O meu minicurso teve como título “Conhecendo o ActionScript 3.0 para o desenvolvimento de jogos utilizando o Adobe Flash CS3″ e foram abordadas questões desde o básico do AS3 referindo-se a DisplayList e ao Sistema de Eventos até a parte de Simulações de Física com a APE e 3D com Papervision 3D.
O artigo pode ser adquirido nesse link http://www.filipesilvestrim.com/gds_2007/minicursoAS3Games.pdf e os exemplos (classes e .fla) podem ser feitos o download aqui http://www.filipesilvestrim.com/gds_2007/Fonte.zip .
Atenção: Ao fazer o download dos códigos fonte, favor ler o arquivo leia-me.html para que os exemplos rodem corretamente.
2 comments









