Reputation: 23
I'm new at programming, and I have faced a problem in my code bellow. I keep getting the same value of the created variable inside last function without taking the change of the other functions. So this is what I want to do: I want to use a value of the variable "state" from last applied function "onActivate" or "onDeactivate" and test this variable "state" inside a "ShowState" function.
import flash.utils.Timer;
import flash.events.Event;
stop();
var state: Boolean = true;
stage.addEventListener(Event.ACTIVATE, onActivate);
stage.addEventListener(Event.DEACTIVATE, onDeactivate);
function onActivate(Event): void {
state == true;
trace("inside");
}
function onDeactivate(Event): void {
state == false;
trace("outside");
}
var StateTime: Timer = new Timer(6000, 0);
StateTime.addEventListener(TimerEvent.TIMER, ShowState);
StateTime.start();
function ShowState(evt: Event): void {
if (state == true) {
trace("Ready");
}
}
Upvotes: 2
Views: 136
Reputation: 81
If I understand your problem correctly you want to change the value of your state variable in your onActivate and onDeactivate function.
When you want to compare variables '==' is used, just like you do in your ShowState function.
To set a value a single '=' sign is used, so instead of:
state == true; // in your onActivate function
// and
state == false; // in your onDeactivate function
You should use:
state = true; // in your onActivate function
// and
state = false; // in your onDeactivate function
Besides the problem you have setting the value it is good practice to start function names in actionscript with a lowercase character.
Finally the parameters in your function declaration are not named in your onActivate and onDeactivate functions, to be quite honest I'm not sure if this will cause any errors, but instead of:
function onActivate(Event) : void {
// your code
}
you could use:
function onActivate(e : Event) : void {
// your code
}
Hope that's all clear, good luck!
Upvotes: 4