Copy link to clipboard
Copied
Hello, I have script:
import flash.events.Event;
import flash.display.Stage;
var suma1_number:Number;
var suma2_number:Number;
var suma3_number:Number;
stage.addEventListener(KeyboardEvent.KEY_DOWN, EnterKeyDown);
function EnterKeyDown(event:KeyboardEvent):void{
if (event.keyCode == Keyboard.ENTER){
if (Number(team1.taskai1.text) > 100 == Number(team1.taskai1.text) < 1000){
var komanda1:Number = (Number(team1.taskai1.text) + Number(team1.suma1.text)) - 100;
suma1_number = komanda1;
team1.suma1.text = String(komanda1);
team1.taskai1.text = '';
} else if (Number(team1.taskai1.text) > 1000){
var komandaA1:Number = (Number(team1.taskai1.text) + Number(team1.suma1.text))- 1000;
suma1_number = komandaA1;
team1.suma1.text = String(komandaA1);
team1.taskai1.text = '';
}else{
team1.taskai1.text = '';
}
if (Number(team2.taskai2.text) > 200 == Number(team2.taskai2.text) < 2000){
var komanda2:Number = (Number(team2.taskai2.text) + Number(team2.suma2.text)) - 200;
suma2_number = komanda2;
team2.suma2.text = String(komanda2);
team2.taskai2.text = '';
} else if (Number(team2.taskai2.text) > 2000){
var komandaA2:Number = (Number(team2.taskai2.text) + Number(team2.suma2.text))- 2000;
suma2_number = komandaA2;
team2.suma2.text = String(komandaA2);
team2.taskai2.text = '';
}else{
team2.taskai2.text = '';
}
if (Number(team3.taskai3.text) > 300 == Number(team3.taskai3.text) < 3000){
var komanda3:Number = (Number(team3.taskai3.text) + Number(team3.suma3.text)) - 300;
suma3_number = komanda3;
team3.suma3.text = String(komanda3);
team3.taskai3.text = "";
} else if (Number(team3.taskai3.text) > 3000){
var komandaA3:Number = (Number(team3.taskai3.text) + Number(team3.suma3.text)) - 3000;
suma3_number = komandaA3;
team3.suma3.text = String(komandaA3);
team3.taskai3.text = "";
}else{
team3.taskai3.text = "";
}
In fields I have calculation annswers:
team1.suma1.text
team2.suma2.text
team3.suma3.text
But then flash goes to other SCENE flash lost numbers in theese fields.
I tried this:
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);
}
BUt it works just on ONE SCENE.. Then flash goes to other scene the numbers again lost. And text fields is empty.
Maby I can save these numbers in txt file or something? And upload in new scene? But then I try to save in *.txt.. flash always ask permision to save and where to save... I hate that.
Copy link to clipboard
Copied
Scenes are a legacy of earlier versions of Flash. They should have been removed at least 10 years ago. There are many reasons to not use scenes, and none to recommend them.
In any case, if you declare a variable on the main timeline of your first scene then that variable will be available in every subsequent scene. If you declare a variable inside a movieClip then you will need to refer to the movieClip in the path to the variable if you are trying to use that variable from outside the movieClip that contains it. Further, the movieClip's existence must be continuous throughout the timeline. This becomes problematic when using scenes. Here's a link to one example: http://stackoverflow.com/questions/19629165/how-to-link-functionality-from-class-file-to-documentcla...
If you do this in the main timeline of the first scene:
var a:Number = 3;
and then on the main timeline of any subsequent scene put:
trace(a);
you will get the value 3. So you can see that the variables hold their value across the scenes.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now