Copy link to clipboard
Copied
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 ;/
Copy link to clipboard
Copied
what do your traces show?
are you adding more than once? do you remove after you add? do you still have a reference when your remove?
Copy link to clipboard
Copied
Traces shows that everything going like I want. function after function like 123456 not 132546. whats why i have so mutch traces. and everything works fine.with other movieclips they shows one time and then they finish play they just removed. but with that one mc_bankrot1 i have problems. Mc_bankrot1 after add this move plays til frame 20 and stops. Then i refocusing to others input textfields. Second time then i adding points this mc_bankrot1 have to play til last frame and dissapier. But that i see flash dont find this mc_bankrot1 on stage. 😕
Copy link to clipboard
Copied
copy and paste the trace output from using the following:
replace:
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");
}
with:
stage.addChild(mc_bankrot1);
mc_bankrot1.x=300;
mc_bankrot1.y=300;
trace('added',mc_bankrot1,mc_bankrot1.stage);
mc_bankrot1.addEventListener(Event.ENTER_FRAME, pointsbankrot1);
mc_bankrot1.play();
}
replace:
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);
}}
with:
function pointsbankrot1(e:Event):void{
if (mc_bankrot1.currentFrame==20) {
bankrot1();
mc_bankrot1.removeEventListener(Event.ENTER_FRAME, pointsbankrot1);
}}
function pointsbankrot1no(e:Event):void{
if (mc_bankrot1.currentFrame==mc_bankrot1.totalFrames) {
stage.removeChild(mc_bankrot1);
trace('remove',mc_bankrot1,mc_bankrot1.stage);
mc_bankrot1.removeEventListener(Event.ENTER_FRAME, pointsbankrot1no);
}}
Copy link to clipboard
Copied
Before refocusing;
added [object bankrotas1] [object Stage]
remove [object bankrotas1] null
After refocusing fields
added [object bankrotas1] [object Stage]
I have the same result. Seems everything works til refocusing text fields.
Copy link to clipboard
Copied
This is FLA file. and SWFfiles. If someone can look inside, maby i do something wrong. I dont know....
Copy link to clipboard
Copied
what do you mean by 'refocusing fields' and what part of your code executes/what changes after you 'refocus fields'?
Copy link to clipboard
Copied
In mine time line i have 3 movieclips with names team1, team2, team3
Inside movieclips i have input text fields (white) team1.taskai1.text, team2.taskai2.text, team3.taskai3.text
And Dynamic texfields team1.suma1.text, team2.suma2.text, team3.suma3.text
In time line layer 2 i have script keyEvents for focusing:
For example if i press A key stage focus on team1.taskai1 inut text field.
If i pres B stage focus on team2.taskai2.text
If i press C stage focus on team3.taskai3.text
Then i focus into team1.taskai1.text i can input number 40 after presing Enter i have this number (40) in suma1.text DYNAMIC TEXTFIELD. Then i can write another number (20) > ENTER and in the suma1 dynamic text field I get 60 and etc.
When in textfield taskai1 i write "." i have this:
var suma1_Number:Number;
var b:String = ".";
var b2:String = ",";
var c:String = "*";
var d:String = "/";
var e:String = "-";
........
if(taskai1.text == b || taskai1.text == b2){
stage.addChild(mc_bankrot1);
mc_bankrot1.x=300;
mc_bankrot1.y=300;
trace('added',mc_bankrot1,mc_bankrot1.stage);
mc_bankrot1.addEventListener(Event.ENTER_FRAME, pointsbankrot1);
mc_bankrot1.play();
}}........
function pointsbankrot1(e:Event):void{
if (mc_bankrot1.currentFrame==20) {
bankrot1();
mc_bankrot1.removeEventListener(Event.ENTER_FRAME, pointsbankrot1);
}}
function bankrot1(){
komanda1 = 0;
suma1_Number = komanda1;
suma1.text = String(komanda1);
taskai1.text = "'';
}
Thats all.. in SUMA1 dynamic text field i have 0 and i have added movie clip mc_bankrot1 on the screen.
If i write number 20 or something then again works sum taskai1.text (20 ) + suma.text (0) = 20. And then:
...
if (stage.contains(mc_bankrot1)){
mc_bankrot1.addEventListener(Event.ENTER_FRAME, pointsbankrot1no);
mc_bankrot1.play();
}
...
function pointsbankrot1no(e:Event):void{
if (mc_bankrot1.currentFrame==mc_bankrot1.totalFrames) {
stage.removeChild(mc_bankrot1);
trace('remove',mc_bankrot1,mc_bankrot1.stage);
mc_bankrot1.removeEventListener(Event.ENTER_FRAME, pointsbankrot1no);
}}
And the mc_bankrot1 dissapiers from screen.
BUT
if i refocus with key B or key C to team2.taskai2.text doing something... and then i come back to team1.taskai1.text
if i write some number (35) i have
taskai1.text (35 ) + suma.text (0 becouse of bankrot1) = 35.
But mc_bankrot1 not dissapiering.
This functon dosent work.
if (stage.contains(mc_bankrot1)){
mc_bankrot1.addEventListener(Event.ENTER_FRAME, pointsbankrot1no);
mc_bankrot1.play();
}
Copy link to clipboard
Copied
too complicated to solve via a forum and i don't download and correct files unless i'm hired.
maybe someone else will download your files and help you.
Copy link to clipboard
Copied
I recorded video of my flash file. I mean how it works. You can see what is hapening.
Copy link to clipboard
Copied
Thanks for your time.. I just dont know what to do:/
Copy link to clipboard
Copied
i recommend you wait to see if someone will do that work for free.
if you don't want to wait, you can hire me by sending me an email via: http://www.kglad.com > contact
Find more inspiration, events, and resources on the new Adobe Community
Explore Now