jeudi 2 mars 2017

Change variable value inside two functions and show result in another function

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");
                }
        }

Aucun commentaire:

Enregistrer un commentaire