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