Can't remove Childs from stage after focus event
I have simple key event with focus:
stage.addEventListener(KeyboardEvent.KEY_DOWN, np1KeyDown);
function np1KeyDown(event:KeyboardEvent):void{
if (event.keyCode == 65){
stage.focus = team1.taskai1;
if(stage.focus == team1.taskai1){
trace("text field 1 has focus.")
if(team1.currentFrame == 1){
team1.play();
}
}
if(stage.focus != team2.taskai2){
trace("Text field 2 not focus.");
if(team2.currentFrame == 13){
team2.play();
}
}
if(stage.focus != team3.taskai3){
trace("Text field 3 not focus.");
if(team3.currentFrame == 13){
team3.play();
}
}
}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, np2KeyDown);
function np2KeyDown(event:KeyboardEvent):void{
if (event.keyCode == 83){
stage.focus = team2.taskai2;
if(stage.focus != team1.taskai1){
trace("text field 1 not focus.");
if(team1.currentFrame == 13){
team1.play();
}
}
if(stage.focus == team2.taskai2){
trace("Text field 2 has focus.");
if(team2.currentFrame == 1){
team2.play();
}
}
if(stage.focus != team3.taskai3){
trace("Text field 3 not focus.");
if(team3.currentFrame == 13){
team3.play();
}
}
}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, np3KeyDown);
function np3KeyDown(event:KeyboardEvent):void{
if (event.keyCode == 68){
stage.focus = team3.taskai3;
if(stage.focus != team1.taskai1){
trace("text field 1 not focus.");
if(team1.currentFrame == 13){
team1.play();
}
}
if(stage.focus != team2.taskai2){
trace("Text field 2 not focus.");
if(team2.currentFrame == 13){
team2.play();
}
}
if(stage.focus == team3.taskai3){
trace("Text field 3 has focus.");
if(team3.currentFrame == 1){
team3.play();
}
}
}
}
In the same frame I have 3 movie clips. team1, team2, team3
In these movieclips i have frames with actions:
import flash.events.Event;
var suma1_Number:Number;
var b:String = ".";
var b2:String = ",";
var c:String = "*";
var d:String = "/";
var e:String = "-";
var mc_scoreloader1:pelnomitaskai1 = new pelnomitaskai1;
var mc_twice1:kartdu2 = new kartdu2;
var mc_division1:dal2 = new dal2;
var mc_bankrot1:bankrotas1 = new bankrotas1;
stage.addEventListener(KeyboardEvent.KEY_DOWN, EnterKeyDown1);
function EnterKeyDown1(event:KeyboardEvent):void{
if (event.keyCode == Keyboard.ENTER){
if(taskai1.text == ""){
taskai1.text = "";
trace("PIRMOS KOMANDOS LANGELYJE NIEKO NEIRASYTA");
}
if(Number(taskai1.text) > 0 || Number(taskai1.text) < 0){
trace("TENKINAMA SALYGA (taskai1.text) > arba < UZ 0");
trace("1 KOMANDA GAUNA" + taskai1.text + "TASKU");
addChild(mc_scoreloader1);
mc_scoreloader1.x=-370;
mc_scoreloader1.y=-880;
trace("mc_scoreloader1 IKELTAS");
mc_scoreloader1.addEventListener(Event.ENTER_FRAME, pointsloading1);
mc_scoreloader1.ptaskai1.text = taskai1.text;
mc_scoreloader1.play();
trace("mc_scoreloader1.GROJAMA");
}
if(taskai1.text == c){
trace("TENKINAMA X2 SALYGA");
trace("1 KOMANDA GAUNA DVIGUBAI DAUGIAU TASKU");
addChild(mc_twice1);
mc_twice1.x=-50;
mc_twice1.y=-83;
trace("mc_twice1 IKELTAS");
mc_twice1.addEventListener(Event.ENTER_FRAME, pointstwice1);
mc_twice1.play();
trace("mc_twice1.GROJAMA");
}
if(taskai1.text == d){
trace("TENKINAMA /2 SALYGA");
trace("1 KOMANDA PRARANDA PUSE TASKU");
addChild(mc_division1);
mc_division1.x=0;
mc_division1.y=3;
trace("mc_division1 IKELTAS");
mc_division1.addEventListener(Event.ENTER_FRAME, pointsdivision1);
mc_division1.play();
trace("mc_division1.GROJAMA");
}
if(taskai1.text == b || taskai1.text == b2){
trace("TENKINAMA BANKROTO SALYGA");
trace("1 KOMANDA PRARANDA VISUS TASKUS");
stage.addChild(mc_bankrot1);
mc_bankrot1.x=300;
mc_bankrot1.y=300;
trace("mc_bankrot1 IKELTAS");
mc_bankrot1.addEventListener(Event.ENTER_FRAME, pointsbankrot1);
mc_bankrot1.play();
trace("mc_bankrot1.GROJAMA");
}
}
}
//EVENT LISTENERS
function pointsloading1(e:Event):void {
if (mc_scoreloader1.currentFrame==mc_scoreloader1.totalFrames) {
trace("scoreloader1.BAIGTA GROTI");
trace("FUNKCIJOS SUDETIS/ATIMTIS ISKVIETIMAS");
sumpoints1();
removeChild(mc_scoreloader1);
trace("scoreloader1 PANAIKINTAS");
mc_scoreloader1.removeEventListener(Event.ENTER_FRAME, pointsloading1);
trace("---BAIGTA------------------");
if (stage.contains(mc_bankrot1)){
mc_bankrot1.addEventListener(Event.ENTER_FRAME, pointsbankrot1no);
trace("mc_bankrot1 YRA EKRANE");
mc_bankrot1.play();
trace("mc_bankrot1.GROJAMA");
}
}}
function pointstwice1(e:Event):void {
if (mc_twice1.currentFrame==mc_twice1.totalFrames) {
trace("mc_twice1.BAIGTA GROTI");
trace("FUNKCIJOS DAUGYBA ISKVIETIMAS");
twicepoints1();
removeChild(mc_twice1);
trace("mc_twice1.PANAIKINTAS");
mc_twice1.removeEventListener(Event.ENTER_FRAME, pointstwice1);
trace("---BAIGTA------------------");
}}
function pointsdivision1(e:Event):void{
if (mc_division1.currentFrame==mc_division1.totalFrames) {
trace("mc_division1.BAIGTA GROTI");
trace("FUNKCIJOS DALYBA ISKVIETIMAS");
divisionpoints1();
removeChild(mc_division1);
trace("mc_division1.PANAIKINTAS");
mc_division1.removeEventListener(Event.ENTER_FRAME, pointstwice1);
trace("----BAIGTA--------------------");
}}
function pointsbankrot1(e:Event):void{
if (mc_bankrot1.currentFrame==20) {
trace("mc_division1.BANKROTO ZENKLAS EKRANE");
trace("FUNKCIJOS BANKROTAS ISKVIETIMAS");
bankrot1();
mc_bankrot1.removeEventListener(Event.ENTER_FRAME, pointsbankrot1);
trace("----BAIGTA--------------------");
}}
function pointsbankrot1no(e:Event):void{
if (mc_bankrot1.currentFrame==mc_bankrot1.totalFrames) {
trace("mc_bankrot1.BAIGTA GROTI");
stage.removeChild(mc_bankrot1);
trace("mc_bankrot1.PANAIKINTA");
mc_bankrot1.removeEventListener(Event.ENTER_FRAME, pointsbankrot1no);
trace("----BAIGTA--------------------");
}}
//MATEMATINIU VEIKSMU FUNKCIJOS
var komanda1:Number;
function sumpoints1(){
komanda1 = Number(taskai1.text) + Number(suma1.text);
suma1_Number = komanda1;
suma1.text = String(komanda1);
taskai1.text = '';
trace("SUDETIES VEIKSMAS");
}
function twicepoints1(){
komanda1 = Number(suma1.text) * 2;
suma1_Number = komanda1;
suma1.text = String(komanda1);
taskai1.text = '';
trace("DAUGYBOS VEIKSMAS");
}
function divisionpoints1(){
komanda1 = Number(suma1.text) / 2;
suma1_Number = komanda1;
suma1.text = String(komanda1);
taskai1.text = '';
trace("DALYBOS VEIKSMAS");
}
function bankrot1(){
komanda1 = 0;
suma1_Number = komanda1;
suma1.text = String(komanda1);
taskai1.text = '';
trace("BANKROTO VEIKSMAS");
}
Everything works perfectly how I want. But jus one BUT. When flash adds mc_bankrot1 the movie stops on frame 20. Then I refocusing to other movie clip doing something... Then I come back and add points after ENTER the mc_bankrot1 have to play til finish and removeChild(mc_bankrot1). But mc_bankrot1 not play jus stay on the stage. All this works till refocusing. Maby someone can look at this messy and say me why?:/
3 days looking for solution but nothing works ;/
