Skip navigation
GrahamTheFlashNoob
Currently Being Moderated

Need help when swapping rooms in my point and click game

Jun 21, 2012 7:20 AM

Ok i am making my first point and click game in flash to familiarize myself with some of the basics.

I have set up a room with a 2 walls(rooms) at the moment, and on the first frame there are 4 screws that when clicked play a small animation and are then removed, works fine so far.  But if i leave that room then go back into it the screws are back in their original position.  How do i stop this from happening, i am guessing i have to put an if formula somewhere on my addChild(TLscrew) or put it somewhere else besides in the enter_frame function.  Anyway heres my code any help would be appreciated. 

 

import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.MovieClip;

stop();

myWords.addEventListener(MouseEvent.CLICK, cleartext);
doorHandle.addEventListener(MouseEvent.CLICK, losehandle);
doorBit.addEventListener(MouseEvent.CLICK, turnDoorBit);
tele.addEventListener(MouseEvent.CLICK, turnOnTele);
skyremote.addEventListener(MouseEvent.CLICK, gotoRemoteBack);


addEventListener(Event.ENTER_FRAME, loop);

 

var TLScrew:MovieClip = new screw();
var TRScrew:MovieClip = new screw();
var BLScrew:MovieClip = new screw();
var BRScrew:MovieClip = new screw();
var topBattery:MovieClip = new AABattery();
var bottomBattery:MovieClip = new AABattery();
var remoteHand:MovieClip = new Hand();
var TLout:Boolean = false;
var TRout:Boolean = false;
var BLout:Boolean = false;
var BRout:Boolean = false;
var doorBitStraight:Boolean = true;
var teleSwitchedOn:Boolean = false;
var beenToOtherRoom:Boolean = false;

 

TLScrew.addEventListener(MouseEvent.CLICK, screwout1);
TRScrew.addEventListener(MouseEvent.CLICK, screwout2);
BLScrew.addEventListener(MouseEvent.CLICK, screwout3);
BRScrew.addEventListener(MouseEvent.CLICK, screwout4);


function loop(e:Event):void{

tele.buttonMode = true;
TLScrew.buttonMode = true;
TRScrew.buttonMode = true;
BLScrew.buttonMode = true;
BRScrew.buttonMode = true;
doorHandle.buttonMode = true;

addChild(TLScrew);
  TLScrew.x = 258;
  TLScrew.y = 205.1;
 
addChild(TRScrew);
  TRScrew.x = 268;
  TRScrew.y = 205.1;

addChild(BRScrew);
  BRScrew.x = 268;
  BRScrew.y = 230.35
 
addChild(BLScrew);
  BLScrew.x = 258;
  BLScrew.y = 230.35;



if(TLScrew.currentFrame == 24){
  removeChild(TLScrew);
}
if(TRScrew.currentFrame == 24){
  removeChild(TRScrew);
}
if(BLScrew.currentFrame == 24){
  removeChild(BLScrew);
}
if(BRScrew.currentFrame == 24){
  removeChild(BRScrew);
}

}
function losehandle(e:MouseEvent):void{
myWords.text = "handle fell off";
doorHandle.gotoAndPlay(2);
doorHandle.removeEventListener(MouseEvent.CLICK, losehandle);
}

function turnDoorBit(e:MouseEvent):void{
if(TLout == true && TRout == true && BLout == true && BRout == true && doorBitStraight == true){
  doorBit.rotation = 75;
  doorBitStraight = false;
}
else if(TLout == true && TRout == true && BLout == true && BRout == true && doorBitStraight == false){
  doorBit.rotation = 360;
  doorBitStraight = true;
}
}

function gotoRemoteBack(e:MouseEvent):void{
gotoAndStop(2);
addChild(topBattery);
addChild(bottomBattery);
addChild(remoteHand);
topBattery.x = 174.8;
topBattery.y = 134.75;
bottomBattery.x = 127.8;
bottomBattery.y = 192.8;
bottomBattery.rotation = 180;
remoteHand.x = 360.3;
remoteHand.y = 143.75;
arrowBack.addEventListener(MouseEvent.CLICK, gotoMain);
beenToOtherRoom = true;
}

function gotoMain(e:MouseEvent):void{
removeChild(topBattery);
removeChild(bottomBattery);
removeChild(remoteHand);
gotoAndStop(1);


}


function turnOnTele(e:MouseEvent):void{
if(teleSwitchedOn == false){
tele.gotoAndStop(2);
teleSwitchedOn = true;
}else if(teleSwitchedOn == true){
  tele.gotoAndStop(1);
  teleSwitchedOn = false;
}
}

function cleartext(e:MouseEvent):void{
myWords.text = "";
}


function screwout1(e:MouseEvent):void{
TLScrew.gotoAndPlay(2);
TLout = true;

}

function screwout2(e:MouseEvent):void{
TRScrew.gotoAndPlay(2);
TRout = true;
}

function screwout3(e:MouseEvent):void{
BLScrew.gotoAndPlay(2);
BLout = true;
}

function screwout4(e:MouseEvent):void{
BRScrew.gotoAndPlay(2);
BRout = true;
}


 
Replies
  • Currently Being Moderated
    Jun 21, 2012 8:00 AM   in reply to GrahamTheFlashNoob

    If the intention is to not have the screws appear when you return, then one way to deal with that is to isolate all of the code that creates the screws into functions and conditionals and have a boolean variable, maybe named "screwsUsed" or something like that, that you declare without assigning a value...

     

    var screwsUsed:Boolean;

     

    and then in a function where you want to decide if you create the screws or not you use that boolean .  You do not assign it a value (true) until after the screws have been used the first time.

     

    if(!screwsUsed){   // note the " ! " meaning NOT

       // use the screws

     

       // sometime later, not necessarily in this section

       screwsUsed = true;

    }

     

    What happens is the screwsUsed variable falls out as false because it is null (no value) at the start.  When you assign it a true value, it sticks because when you return to that frame, the value is not being assigned.

     

    Like the screwsUsed variable, you can declare the screws outside any functions so they are available to any function, and only instantiate them inside that conditional. This way you only create instances when you need them, not each time you enter that frame...

     

    var TLScrew:screw;

    var TRScrew:screw;

    var BLScrew:screw;

    var BRScrew:screw;

     

    if(!screwsUsed){   // note the " ! " meaning NOT

       // use the screws  

       TLScrew = new screw();

       TRScrew = new screw();

       BLScrew = new screw();

       BRScrew = new screw();

     

       // sometime later, not necessarily in this section

       screwsUsed = true;

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 21, 2012 8:45 AM   in reply to GrahamTheFlashNoob

    If you are using the BLout, etc, then like I said with the screwsUsed, you should only declare it, do not assign it a false value or else when you return to that frame the false value gets reassigned.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 21, 2012 9:25 AM   in reply to GrahamTheFlashNoob

    Instead of having that code to remove them, you could try letting them remove themselves.  In the last frame (24) within each screw mc, try using...

     

    MovieClip(parent).removeChild(this);

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points