Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Score Counter from Text fields.

Explorer ,
Dec 30, 2015 Dec 30, 2015

Hello, need some help. My English is not good but I hope you understand me.

I have 3 text input fields: "taskai1", "taskai2", "taskai3" and 3 dynamic text fields: "suma1", "suma2", "suma3".


I want to do this thing.

Then I press F1 key the text writing marker stand on imput field "taskai1" and I want to write numbers with keyboard for example 150 and then I press enter I want to see on dynamic text field "suma1" 150 if i write again for example 100 I want to see the result of 250 and so on. But I have a problem.

Problem is then the movie plays to next scene or next frame the number from dynamic fields gone and I have to count again. I want that flash remember these numbers until I close the flash.

Maby someone can help?

That my simple code:

stop();

stage.displayState = StageDisplayState.FULL_SCREEN;

stage.addEventListener(KeyboardEvent.KEY_DOWN, EnterKeyDown);

function EnterKeyDown(event:KeyboardEvent):void{

if (event.keyCode == Keyboard.ENTER){

var komanda1:Number = Number(taskai1.text) + Number(suma1.text);

suma1.text = String(komanda1);

taskai1.text = '';

var komanda2:Number = Number(taskai2.text) + Number(suma2.text);

suma2.text = String(komanda2);

taskai2.text = '';

var komanda3:Number = Number(taskai3.text) + Number(suma3.text);

suma3.text = String(komanda3);

taskai3.text = '';

}

}

stage.addEventListener(KeyboardEvent.KEY_DOWN, F1KeyDown);

function F1KeyDown(event:KeyboardEvent):void{

if (event.keyCode == Keyboard.F1){

stage.focus = taskai1;

}

}

stage.addEventListener(KeyboardEvent.KEY_DOWN, F2KeyDown);

function F2KeyDown(event:KeyboardEvent):void{

if (event.keyCode == Keyboard.F2){

stage.focus = taskai2;

}

}

stage.addEventListener(KeyboardEvent.KEY_DOWN, F3KeyDown);

function F3KeyDown(event:KeyboardEvent):void{

if (event.keyCode == Keyboard.F3){

stage.focus = taskai3;

}

}

TOPICS
ActionScript
683
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 31, 2015 Dec 31, 2015

the first 3 lines (with the var declarations) should be on the first frame.

the lines of code like


suma2_number=komanda2;


should be on the frame(s) where you want to save the value to used in your suma textfields.


those if-statements should be on frames where you want to re-apply the text to your suma textfields.

Translate
Community Expert ,
Dec 30, 2015 Dec 30, 2015

use a variable to save the numbers your want to appear in your textfields.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 31, 2015 Dec 31, 2015

But i dont understand where to write that variables. 😕 Im new in AS3

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 31, 2015 Dec 31, 2015

use something like:

stop();

var suma1_number:Number;

var suma2_number:Number;

var suma3_number:Number;

stage.displayState = StageDisplayState.FULL_SCREEN;

stage.addEventListener(KeyboardEvent.KEY_DOWN, EnterKeyDown);

function EnterKeyDown(event:KeyboardEvent):void{

if (event.keyCode == Keyboard.ENTER){

var komanda1:Number = Number(taskai1.text) + Number(suma1.text);

suma1_number=komanda1;

suma1.text = String(komanda1);

taskai1.text = '';

var komanda2:Number = Number(taskai2.text) + Number(suma2.text);

suma2_number=komanda2;

suma2.text = String(komanda2);

taskai2.text = '';

var komanda3:Number = Number(taskai3.text) + Number(suma3.text);

suma3_number=komanda3;

suma3.text = String(komanda3);

taskai3.text = '';

}

}

stage.addEventListener(KeyboardEvent.KEY_DOWN, F1KeyDown);

function F1KeyDown(event:KeyboardEvent):void{

if (event.keyCode == Keyboard.F1){

stage.focus = taskai1;

}

}

stage.addEventListener(KeyboardEvent.KEY_DOWN, F2KeyDown);

function F2KeyDown(event:KeyboardEvent):void{

if (event.keyCode == Keyboard.F2){

stage.focus = taskai2;

}

}

stage.addEventListener(KeyboardEvent.KEY_DOWN, F3KeyDown);

function F3KeyDown(event:KeyboardEvent):void{

if (event.keyCode == Keyboard.F3){

stage.focus = taskai3;

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 31, 2015 Dec 31, 2015

Thank you kglad,

But Nothing hapends.

All works fine just in one keyframe. If i go to the next KEYFRAME in dynamic text fields everything is gone.

I made all fiels to one MovieClip with Actions it works in diferent keyframes until I came to second Scene2. I need that flash remember dynamic fields numbers until i close the flash. If the Scene2 starts i want to see the same numbers.

I WILL TRY TO EXPLAIN

Scene1 Starts .. dynamic field is empty.

Then in input text field I write 50 + ENTER in dynamic field I see 50. if I write again 25 + ENTER in dynamic field i see 75, if i write 50 in dynamic field I get 125 and so on. Then the movie jumps to other scene or other keyframe.. The dynamic field again empty. The number 125 is gone and i dont know how to do that flash remember the last number in 3 dynamic textfields whatever the flash do. If i close the flash thats ok. next time then i start the flash  want to see every fields empty. But until flash is open i want to see theese fiels with last numbers whatever  flash do or whatever flash jumps (keyframe25, scene 6, scene 45, scene 1, scene 15, keyframe857444).

I start to think that I cant do this with simple script.

This flash i just use on my pc. Before I tryed to do that with txt file. Text loading/text save. I write a number press Enter....script saves number to txt and upoloads number from txt file to dynamic text field. But then the script wants to write in txt file the flash asks confirmation to save txt file. I dont want to ask me for confirmation just save text and what`s it.  But now i want to do the same just in other way.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 31, 2015 Dec 31, 2015

when you return you have to assign those variable values (converted to strings) to the text property of those textfields.

stop();

var suma1_number:Number;

var suma2_number:Number;

var suma3_number:Number;

if(!isNaN(suma1_number){

suma1.text=String(sum1_number);

}

if(!isNaN(suma2_number){

suma2.text=String(sum2_number);

}

if(!isNaN(suma3_number){

suma3.text=String(sum3_number);

}

stage.displayState = StageDisplayState.FULL_SCREEN;

stage.addEventListener(KeyboardEvent.KEY_DOWN, EnterKeyDown);

function EnterKeyDown(event:KeyboardEvent):void{

if (event.keyCode == Keyboard.ENTER){

var komanda1:Number = Number(taskai1.text) + Number(suma1.text);

suma1_number=komanda1;

suma1.text = String(komanda1);

taskai1.text = '';

var komanda2:Number = Number(taskai2.text) + Number(suma2.text);

suma2_number=komanda2;

suma2.text = String(komanda2);

taskai2.text = '';

var komanda3:Number = Number(taskai3.text) + Number(suma3.text);

suma3_number=komanda3;

suma3.text = String(komanda3);

taskai3.text = '';

}

}

stage.addEventListener(KeyboardEvent.KEY_DOWN, F1KeyDown);

function F1KeyDown(event:KeyboardEvent):void{

if (event.keyCode == Keyboard.F1){

stage.focus = taskai1;

}

}

stage.addEventListener(KeyboardEvent.KEY_DOWN, F2KeyDown);

function F2KeyDown(event:KeyboardEvent):void{

if (event.keyCode == Keyboard.F2){

stage.focus = taskai2;

}

}

stage.addEventListener(KeyboardEvent.KEY_DOWN, F3KeyDown);

function F3KeyDown(event:KeyboardEvent):void{

if (event.keyCode == Keyboard.F3){

stage.focus = taskai3;

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 31, 2015 Dec 31, 2015

I create a symbol (name "Symbol 2") with all text fields ant in first keyframe I add the action script but i have some errors:

Symbol 'Symbol 2', Layer 'Layer 2', Frame 1, Line 5    1084: Syntax error: expecting rightparen before leftbrace.

Symbol 'Symbol 2', Layer 'Layer 2', Frame 1, Line 8    1084: Syntax error: expecting rightparen before leftbrace.

Symbol 'Symbol 2', Layer 'Layer 2', Frame 1, Line 11    1084: Syntax error: expecting rightparen before leftbrace.

1  var suma1_number:Number;

2  var suma2_number:Number;

3  var suma3_number:Number;

4

5  if(!isNaN(suma1_number){

6  suma1.text=String(suma1_number);

7  }

8  if(!isNaN(suma2_number){

9  suma2.text=String(suma2_number);

10 }

11 if(!isNaN(suma3_number){

12 suma3.text=String(suma3_number);

13 }

I think that I have a long way to understand what is going on with what comands and how to write theese comands.

Maby I do something wrong.. I mean that I created a move clip object?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 31, 2015 Dec 31, 2015

no, that's my error.

that code should be:

1  var suma1_number:Number;

2  var suma2_number:Number;

3  var suma3_number:Number;

4

5  if(!isNaN(suma1_number)){

6  suma1.text=String(suma1_number);

7  }

8  if(!isNaN(suma2_number)){

9  suma2.text=String(suma2_number);

10 }

11 if(!isNaN(suma3_number)){

12 suma3.text=String(suma3_number);

13 }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 31, 2015 Dec 31, 2015

The problem was with (   (   ) ) First i need to lern English. But iot not helps.

Then the "Symbol 2" apears on the other Scene the fields are empty:| Or i dont understand where i have to write this script

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 31, 2015 Dec 31, 2015

the first 3 lines (with the var declarations) should be on the first frame.

the lines of code like


suma2_number=komanda2;


should be on the frame(s) where you want to save the value to used in your suma textfields.


those if-statements should be on frames where you want to re-apply the text to your suma textfields.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 31, 2015 Dec 31, 2015

I think that thios script should be add on every keyframe where textfields loading?

var suma1_number:Number;

var suma2_number:Number;

var suma3_number:Number;

if(!isNaN(suma1_number)){

suma1.text=String(suma1_number);

}

if(!isNaN(suma2_number)){

suma2.text=String(suma2_number);

}

if(!isNaN(suma3_number)){

suma3.text=String(suma3_number);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 31, 2015 Dec 31, 2015

kglad

you are MY HERO !  

Thanks!!!

Everything is working FINE!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 31, 2015 Dec 31, 2015

you're welcome.

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 31, 2015 Dec 31, 2015

HAPPY NEW YEAR!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 31, 2015 Dec 31, 2015
LATEST

thank you.

happy new year to you, too!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines