Variables and Responses between layers AS3

Viewed 47

I'm having a slight problem in a current project... i have an object, that when clicked activates a function, which hides several objects and changes a variable. The changing of said variable should then cause an object on another layer to appear, but all that happens is the objects disappear, but the other one doesn't appear... The code for the first layer is as follows.... The function in question is the last one...

import flash.events.Event;
import flash.system.fscommand;
import flash.events.MouseEvent;
stage.displayState = StageDisplayState.FULL_SCREEN; 
var GameMode:Number=0;//Variable Setup
var Planet:Number=0;//
swslogo.alpha = .0;//Game Menu
voidlogomenu.alpha = .0;
newgame.alpha = .0;
loadgame.alpha = .0;
exitgame.alpha = .0;
yes.alpha = .0;
no.alpha = .0;
exitprompt.alpha = .0;
MenuExitFade.alpha = .0;
SwsLogoCorner.alpha = .0;
var IntroTimer = new Timer(3000,1); //add a 3 second timer
var QuitTimer = new Timer(1000,1); //add a 1 second timer
var IntroTimer2 = new Timer(5000,1); //add a 5 second timer
IntroTimer.addEventListener(TimerEvent.TIMER_COMPLETE,swsfadein);
intro();
function intro():void
{
     IntroTimer.reset()
     IntroTimer.start();
    for (var i:int = 0; i < 50; i++)
{
    var aStar:DisplayObject = new stars;
    MenuSpawner.addChild(aStar);
}
for (var i:int = 0; i < 50; i++)
{
    var aStarDust:DisplayObject = new Stardust;
    MenuSpawner.addChild(aStarDust);
}
}
function swsfadein(e:Event=null):void
{
    IntroTimer.stop();
    IntroTimer.removeEventListener(TimerEvent.TIMER_COMPLETE,swsfadein);
    swslogo.addEventListener(Event.ENTER_FRAME, fadeinsws)
}
function fadeinsws(e:Event=null){
    if(swslogo.alpha >= 1){
        swslogo.removeEventListener(Event.ENTER_FRAME, fadeinsws);
        IntroTimer2.addEventListener(TimerEvent.TIMER_COMPLETE,swsfadeout);
        IntroTimer2.reset()
        IntroTimer2.start();
    } else {
        swslogo.alpha +=0.1;
    }
}
function swsfadeout(e:Event=null):void
{
    IntroTimer2.stop();
    IntroTimer2.removeEventListener(TimerEvent.TIMER_COMPLETE,swsfadeout);
    swslogo.addEventListener(Event.ENTER_FRAME, fadeoutsws)
}
function fadeoutsws(e:Event=null){
if(swslogo.alpha <=0){
        swslogo.removeEventListener(Event.ENTER_FRAME, fadeoutsws);
    IntroTimer.addEventListener(TimerEvent.TIMER_COMPLETE,voidfadein);
    IntroTimer.reset()
    IntroTimer.start()
    } else {
        swslogo.alpha -=0.1;
    }
}
function voidfadein(e:Event=null):void
{
        IntroTimer.stop();
    IntroTimer.removeEventListener(TimerEvent.TIMER_COMPLETE,voidfadein);
    voidlogomenu.addEventListener(Event.ENTER_FRAME, fadeinvoid)
}
function fadeinvoid(e:Event=null){
    if(voidlogomenu.alpha >= 1){
        voidlogomenu.removeEventListener(Event.ENTER_FRAME, fadeinvoid);
        IntroTimer2.addEventListener(TimerEvent.TIMER_COMPLETE,menufadein);
        IntroTimer2.reset()
        IntroTimer2.start();
    } else {
        voidlogomenu.alpha +=0.1;
    }
}
function menufadein(e:Event=null):void
{
    IntroTimer2.stop();
    IntroTimer2.removeEventListener(TimerEvent.TIMER_COMPLETE,menufadein);
    newgame.addEventListener(Event.ENTER_FRAME, fadeinnewgame);
    loadgame.addEventListener(Event.ENTER_FRAME, fadeinloadgame);
    exitgame.addEventListener(Event.ENTER_FRAME, fadeinexitgame);
    SwsLogoCorner.addEventListener(Event.ENTER_FRAME, fadeinswslogocorner)
}
function fadeinnewgame(e:Event=null){
    if(newgame.alpha >= 1){
        newgame.addEventListener(MouseEvent.CLICK, newgameclicked);
        newgame.removeEventListener(Event.ENTER_FRAME, fadeinnewgame);
    } else {
        newgame.alpha +=0.1;
    }
}
function fadeinloadgame(e:Event=null){
    if(loadgame.alpha >= 1){
        loadgame.addEventListener(MouseEvent.CLICK, loadgameclicked);
        loadgame.removeEventListener(Event.ENTER_FRAME, fadeinloadgame);
    } else {
        loadgame.alpha +=0.1;
    }
}
function fadeinexitgame(e:Event=null){
    if(exitgame.alpha >= 1){
        exitgame.addEventListener(MouseEvent.CLICK, exitgameclicked)
        exitgame.removeEventListener(Event.ENTER_FRAME, fadeinexitgame);
    } else {
        exitgame.alpha +=0.1;
    }
}
function fadeinswslogocorner(e:Event=null){
    if(SwsLogoCorner.alpha >= 1){
        SwsLogoCorner.removeEventListener(Event.ENTER_FRAME, fadeinswslogocorner);
    } else {
        SwsLogoCorner.alpha +=0.1;
    }
}
function newgameclicked(e:MouseEvent):void
{
     yesnofadein();
     exitprompt.addEventListener(Event.ENTER_FRAME, exitpromptfadein)
     exitprompt.gotoAndStop(2)
     yes.addEventListener(MouseEvent.CLICK, createnewgame)
     removemenufunctions();
}
function loadgameclicked(e:MouseEvent):void
{
     removemenufunctions();
}
function exitgameclicked(e:MouseEvent)
{
     yesnofadein();
     exitprompt.addEventListener(Event.ENTER_FRAME, exitpromptfadein)
     exitprompt.gotoAndStop(1)
     yes.addEventListener(MouseEvent.CLICK, exit)
     removemenufunctions();
}
function exitpromptfadein(e:Event=null){
    if(exitprompt.alpha >= 1){
        no.addEventListener(MouseEvent.CLICK, exitpromptfadeout)
        exitprompt.removeEventListener(Event.ENTER_FRAME, exitpromptfadein);
    } else {
        exitprompt.alpha +=0.1;
    }
}
function exitpromptfadeout(e:Event=null):void
{
     no.removeEventListener(MouseEvent.CLICK, exitpromptfadeout)
     exitprompt.addEventListener(Event.ENTER_FRAME, fadeoutexitprompt);
}
function fadeoutexitprompt(e:Event=null){
if(exitprompt.alpha <=0){
        exitprompt.removeEventListener(Event.ENTER_FRAME, fadeoutexitprompt);
    } else {
        exitprompt.alpha -=0.1;
    }
}
function yesnofadein():void
{
    yes.addEventListener(Event.ENTER_FRAME, fadeinyes)
    no.addEventListener(Event.ENTER_FRAME, fadeinno)
}
function fadeinyes(e:Event=null){
    if(yes.alpha >= 1){
        yes.removeEventListener(Event.ENTER_FRAME, fadeinyes);
    } else {
        yes.alpha +=0.1;
    }
}
function fadeinno(e:Event=null){
    if(no.alpha >= 1){
        no.addEventListener(MouseEvent.CLICK, replacemenufunctions)
        no.addEventListener(MouseEvent.CLICK, yesnofadeout)
        no.removeEventListener(Event.ENTER_FRAME, fadeinno);
    } else {
        no.alpha +=0.1;
    }
}
function yesnofadeout(e:MouseEvent):void
{
    yes.removeEventListener(MouseEvent.CLICK, exit)
    yes.removeEventListener(MouseEvent.CLICK, createnewgame)
    yes.addEventListener(Event.ENTER_FRAME, fadeoutyes)
    no.addEventListener(Event.ENTER_FRAME, fadeoutno)
    no.removeEventListener(MouseEvent.CLICK, yesnofadeout)
}
function fadeoutyes(e:Event=null){
if(yes.alpha <=0){
        yes.removeEventListener(Event.ENTER_FRAME, fadeoutyes);
    } else {
        yes.alpha -=0.1;
    }
}
function fadeoutno(e:Event=null){
if(no.alpha <=0){
        no.removeEventListener(Event.ENTER_FRAME, fadeoutno);
    } else {
        no.alpha -=0.1;
    }
}
function removemenufunctions():void
{
    exitgame.removeEventListener(MouseEvent.CLICK, exitgameclicked);
    loadgame.removeEventListener(MouseEvent.CLICK, loadgameclicked);
    newgame.removeEventListener(MouseEvent.CLICK, newgameclicked);
}
function replacemenufunctions(e:Event=null):void
{
    exitgame.addEventListener(MouseEvent.CLICK, exitgameclicked);
    loadgame.addEventListener(MouseEvent.CLICK, loadgameclicked);
    newgame.addEventListener(MouseEvent.CLICK, newgameclicked);
}
function exit(e:MouseEvent)
{
    MenuExitFade.x = -35; 
    MenuExitFade.y = 0; 
    MenuExitFade.addEventListener(Event.ENTER_FRAME, exitblackfade);
}
function exitblackfade(e:Event)
{
    if(MenuExitFade.alpha >= 1){
        MenuExitFade.removeEventListener(Event.ENTER_FRAME, exitblackfade);
        QuitTimer.addEventListener(TimerEvent.TIMER_COMPLETE,forceclose);
        QuitTimer.reset()
        QuitTimer.start();
    } else {
        MenuExitFade.alpha +=0.1;
    }
}
function forceclose(e:Event)
{
    QuitTimer.stop();
    QuitTimer.removeEventListener(TimerEvent.TIMER_COMPLETE,forceclose);
    fscommand('quit');
}
function createnewgame(e:MouseEvent)
{
    var GameMode=1;
    var Planet=1;
    MenuSpawner.alpha=0
    newgame.alpha=0
    loadgame.alpha=0
    exitgame.alpha=0
    voidlogomenu.alpha=0
    yes.alpha=0
    no.alpha=0
    exitprompt.alpha=0
    SwsLogoCorner.alpha=0
    yes.removeEventListener(MouseEvent.CLICK, createnewgame)
    no.removeEventListener(MouseEvent.CLICK, yesnofadeout)
}

the code for the second is as follows

import flash.events.Event;
import flash.system.fscommand;
import flash.events.MouseEvent;
setupplanet();
Foreground.alpha=0
function setupplanet():void
{
    Foreground.addEventListener(Event.ENTER_FRAME, PlanetLoop)
}
function PlanetLoop(e:Event=null):void
{
    if(GameMode==0){
        Foreground.alpha=0
    } else {
        Foreground.alpha=1
    }
            Foreground.gotoAndStop(1)
}

thanks...

1 Answers
Related