Skip to main content
Inspiring
Oct 16, 2015 3:10 PM UTC
Answered

Trying to create a five nights at freddies parody.

package

{

  import flash.display.*;

  import flash.events.*;

  import flash.events.MouseEvent;

  public class LeftSide extends MovieClip

  {

  public var leftLight:Boolean;

  public function LeftSide()

  {

  leftLight = false;

  updateFrames();

  LeftLight.addEventListener(MouseEvent.MOUSE_DOWN, turnOn);

  }

  public function turnOn(event:MouseEvent):void

  {

  LeftLight.removeEventListener(MouseEvent.MOUSE_DOWN, turnOn);

  leftLight = true;

  LeftLight.addEventListener(MouseEvent.MOUSE_UP, turnOff);

  updateFrames();

  }

  public function turnOff(event:MouseEvent):void

  {

  LeftLight.removeEventListener(MouseEvent.MOUSE_UP, turnOff);

  leftLight = false;

  LeftLight.addEventListener(MouseEvent.MOUSE_DOWN, turnOn);

  updateFrames();

  }

  public function updateFrames()

  {

  if(leftLight == true)

  {

  this.gotoAndStop(2);

  }

  if(leftLight == false)

  {

  this.gotoAndStop(1);

  }

  }

  }

}

this is what i expect: so when i hold the light button, the light turns on (frame 2) and when i let go, it turns off (frame 1).

what happens: it turns on when i hold it, but after a few seconds, it turns off automatically. it seems the leftLight variable flips back and forth. But if i hold it for like one second and i let go, it seems to work perfectly.  but only when i hold it a few seconds, it turns off by itself.

the LeftLight button was dragged in the LeftSide MovieClip and i did the instance name thing.

a similar problem is occurring with the camera button,  when i click the camera button, it adds a grey block(just for testing) on top of the screen but after a few seconds, it goes to the back of the screen behind everything. 

another similar problem:  i made a transparent button(workBtn) and when you click it it zooms in to ur computer so it looks like ur working and i added a returnBtn to return and zoom back out to the normal state. the zoom stays,  but the returnBtn stays only a few seconds and disappears.  i would have to click the workBtn again to make a appear again.  the returnBtn works fine when you click it.

package

{

  import flash.events.*;

  import flash.display.MovieClip;

  import flash.display.*;

  import flash.events.MouseEvent;

  import flash.display.SimpleButton;

  public class ThreeNightsAtSomePlace extends MovieClip

  {

  public var PlayBtn:playBtn;

  public var tnasp:Title;

  public var night1:Night1;

  public var leftSide:LeftSide;

  public var rightSide:RightSide;

  public var yourRoom:YourRoom;

  public var working:Boolean;

  public var returnBtn:Return;

  public var CameraBtn:cameraBtn;

  public var camera:Cameras;

  public function ThreeNightsAtSomePlace()

  {

  MainMenu();

  }

  public function MainMenu()

  {

  tnasp = new Title;

  addChild(tnasp);

  PlayBtn = new playBtn;

  PlayBtn.x = -300;

  PlayBtn.y = 200;

  addChild(PlayBtn);

  PlayBtn.addEventListener(MouseEvent.CLICK, playGame);

  }

  public function playGame(event:MouseEvent):void

  {

  night1 = new Night1

  night1.x = 250;

  night1.y = 180;

  addChild(night1);

  removeChild(tnasp);

  removeChild(PlayBtn);

  stage.addEventListener(Event.ENTER_FRAME, removeNight1);

  }

  public function removeNight1(event:Event)

  {

  if(night1.currentFrame == 60)

  {

  playNightOne();

  if(contains(night1))

  {

  removeChild(night1);

  }

  }

  }

  public function playNightOne()

  {

  working = false;

  leftSide = new LeftSide;

  leftSide.x = -500;

  leftSide.y = 200;

  addChild(leftSide);

  rightSide = new RightSide;

  rightSide.x = 950;

  rightSide.y = 200;

  addChild(rightSide);

  yourRoom = new YourRoom;

  yourRoom.scaleY = 1.055;

  yourRoom.scaleX = 0.94;

  yourRoom.x = 225;

  yourRoom.y = 150;

  addChild(yourRoom);

  CameraBtn = new cameraBtn;

  CameraBtn.x = 250;

  CameraBtn.y = 650;

  addChild(CameraBtn);

  CameraBtn.addEventListener(MouseEvent.CLICK, checkCamera);

  yourRoom.workBtn.addEventListener(MouseEvent.CLICK, work);

  }

  public function checkCamera(event:MouseEvent):void

  {

  camera = new Cameras;

  camera.x = 250;

  addChild(camera);

  }

  public function work(event:MouseEvent):void

  {

  returnBtn = new Return;

  returnBtn.scaleX = .5;

  returnBtn.scaleY = .5;

  returnBtn.x = 500;

  returnBtn.y = 50;

  addChild(returnBtn);

  working = true;

  this.x = -800;

  this.y = -300;

  this.scaleX = 3.5;

  this.scaleY = 3.5;

  returnBtn.addEventListener(MouseEvent.CLICK, goBack);

  }

  public function goBack(event:MouseEvent):void

  {

  removeChild(returnBtn);

  working = false;

  this.x = 0;

  this.y = 0;

  this.scaleX = 1;

  this.scaleY = 1;

  }

  }

}

This topic is closed to new replies. Start a new post to keep the conversation going.
nezarovCorrect answer
Inspiring
Oct 19, 2015 5:16 PM UTC

take a look at this other problem that might be similar.

CameraBtn.addEventListener(MouseEvent.CLICK, checkCamera);

public function checkCamera(event:MouseEvent):void

  {

  camera = new Cameras;

  camera.x = 250;

  addChild(camera);

  }

button works fine and a new camera is added on the screen.

But after a few seconds, it falls behind the background i put, even thought i didn't set any depth to it.


The code is correct, I think the wrong in somewhere else, try to remove the stage event listener (removeNight1)

stage.addEventListener(Event.ENTER_FRAME, removeNight1);

public function removeNight1(event:Event)

{

     if(night1.currentFrame == 60)

     {

          stage.removeEventListener(Event.ENTER_FRAME, removeNight1);

          removeChild(night1);

          playNightOne();

     }


}

41 replies

Participant
Apr 16, 2022 8:54 PM UTC

comment je crée des choses

 

 

 

 

 

 

 

Translate
Inspiring
Oct 16, 2015 4:09 PM UTC

Did you try to change the lamps? D

You have to create a MovieClip for the light modes including two frames with the light graphics, frame 1 for light off mode and the second for light on mode..

Add stop(); in frame 1 of the light MovieClip, and give it an instance name "light_mc"

then change the code as following:

  LeftLight.addEventListener(MouseEvent.MOUSE_DOWN, turnOn);

LeftLight.addEventListener(MouseEvent.MOUSE_UP, turnOff);

  public function turnOn(event:MouseEvent):void

  {

  leftLight = true;

  updateFrames();

  }

  public function turnOff(event:MouseEvent):void

  {

  leftLight = false;

  updateFrames();

  }

public function updateFrames()

  {

  if(leftLight == true)

  {

  light_mc.gotoAndStop(2);

  }

else // you can use if(leftLight == false) or else if(leftLight == false)...

{

light_mc.gotoAndStop(1);

}

}

Translate
Inspiring
Oct 16, 2015 5:03 PM UTC

i put the light animation in the "LeftSide" movieClip.  there is a frame where the light is off and there is a frame where the light is on.

but there is the weird problem where if i trace whether left light is on or off it seems to flip back and forth,

Translate
Inspiring
Oct 16, 2015 5:09 PM UTC

add these two lines to set the LeftSide on (off mode) at the beginning:

LeftSide.gotoAndStop(1);

LeftSide = false;

Translate