Symbol 123 MovieClip Frame 1
_global.doors_movie = this;
Main.getInstance().init();
this.onEnterFrame = function () {
Main.getInstance().step();
};
Symbol 124 MovieClip [__Packages.Main] Frame 0
class Main
{
var doors, shadows, plint, knob, door_frames, soundman, ref_pos, interval_init, door_in_center;
function Main () {
doors = _global.doors_movie.mc_doors;
shadows = _global.doors_movie.mc_shadows;
plint = _global.doors_movie.mc_plint;
knob = _global.doors_movie.mc_extra_knob;
door_frames = Parameters.door_frames;
soundman = new SoundManager();
ref_pos = [];
var _local4 = _global.doors_movie.mc_ref;
var _local3 = 1;
while (_local3 <= _local4._totalframes) {
_local4.gotoAndStop(_local3);
ref_pos[_local3] = _local4.mc_circle._x;
_local3++;
}
_local4._visible = false;
if (Parameters.delay_dingdong > 0) {
interval_init = setInterval(this, "onInit", Parameters.delay_dingdong);
} else {
onInit();
}
}
static function getInstance() {
if (instance == null) {
instance = new Main();
}
return(instance);
}
function init() {
var _local4 = [doors, shadows];
var _local3 = 0;
while (_local3 < _local4.length) {
var _local2 = _local4[_local3];
for (var _local5 in _local2) {
if (typeof(_local2[_local5]) == "movieclip") {
_local2[_local5].removeMovieClip();
} else {
delete _local2[_local5];
}
}
_local3++;
}
door_objs = [];
appendDoor();
setPlint();
}
function step() {
max_frame = 0;
min_frame = 100;
var _local2 = 0;
while (_local2 < door_objs.length) {
var _local3 = door_objs[_local2];
_local3.step();
setDepthOfDoor(_local2);
max_frame = Math.max(max_frame, _local3.__get__frame());
min_frame = Math.min(min_frame, _local3.__get__frame());
_local2++;
}
if (min_frame > 1) {
appendDoor();
}
if ((max_frame < door_frames) and (counter > door_objs.length)) {
insertDoor();
}
setPlint();
if ((door_in_center != undefined) and ((door_in_center.__get__frame() == 49) or (door_in_center.__get__frame() == 50))) {
knob.gotoAndStop(door_in_center.__get__frame() - 48);
knob._visible = true;
} else {
door_in_center = null;
knob._visible = false;
}
}
function setDepthOfDoor(n) {
var _local2 = door_objs[n].frame;
var _local4 = ((_local2 > 50) ? (((4 * door_frames) * door_frames) - ((door_frames * _local2) + (door_frames - n))) : ((door_frames * _local2) + (door_frames - n)));
door_objs[n].setDepth(_local4);
}
function appendDoor() {
var _local3 = createDoor(counter);
door_objs.push(_local3);
_local3.id = counter;
counter++;
var _local2 = door_objs.length;
if (_local2 > 1) {
door_objs[_local2 - 1].door_prev = door_objs[_local2 - 2];
door_objs[_local2 - 2].door_next = door_objs[_local2 - 1];
}
}
function insertDoor() {
var _local2 = createDoor((counter - door_objs.length) - 1);
_local2.id = (counter - door_objs.length) - 1;
door_objs.unshift(_local2);
_local2.gotoFrame(door_frames, true);
var _local3 = door_objs.length;
if (_local3 > 1) {
door_objs[1].door_prev = _local2;
_local2.door_next = door_objs[1];
}
}
function createDoor(n) {
var _local3 = doors.attachMovie("door", "door" + n, 1);
var _local4 = shadows.attachMovie("shadow", "shadows" + n, 1);
var _local2 = new Door(_local3, _local4, ref_pos);
_local2.addListener(this, onCollision, "onCollision");
_local2.addListener(this, onComplete, "onComplete");
_local2.addListener(this, onClosed, "onClosed");
_local2.addListener(this, onCenter, "onCenter");
_local2.addListener(this, onOpening, "onOpening");
return(_local2);
}
function setPlint() {
plint.gotoAndStop(1);
while (max_frame > plint._currentframe) {
plint.nextFrame();
}
}
function onCenter(door) {
door_in_center = door;
}
function onCollision(force, frame) {
var _local2 = Parameters.vol_min + (((100 - Parameters.vol_min) * force) / Parameters.max_vol_at_force);
var _local4 = -100 + ((200 * (ref_pos[frame] - ref_pos[ref_pos.length - 1])) / (ref_pos[1] - ref_pos[ref_pos.length - 1]));
var _local3 = "hit0" + (random(3) + 1);
soundman.playSound(_local3, _local2, _local4);
}
function onComplete(door) {
var _local6 = Parameters.vol_min + (((100 - Parameters.vol_min) * Math.abs(door.__get__speed())) / Parameters.max_vol_at_force);
var _local8 = -100;
var _local7 = "close0" + (random(2) + 1);
soundman.playSound(_local7, _local6, _local8);
var _local2 = 0;
while (_local2 < door_objs.length) {
if (door_objs[_local2] == door) {
var _local4 = _local2;
break;
}
_local2++;
}
if (_local4 > 0) {
door_objs[0].destroy();
door_objs.shift();
var _local3 = 0;
while (_local3 < door_objs.length) {
setDepthOfDoor(_local3);
_local3++;
}
}
}
function onClosed(door) {
var _local6 = Parameters.vol_min + (((100 - Parameters.vol_min) * Math.abs(door.__get__speed())) / Parameters.max_vol_at_force);
var _local8 = 100;
var _local7 = "close0" + (random(2) + 1);
soundman.playSound(_local7, _local6, _local8);
var _local2 = door_objs.length - 1;
while (_local2 >= 0) {
if (door_objs[_local2] == door) {
var _local4 = _local2;
break;
}
_local2--;
}
if (_local4 < (door_objs.length - 1)) {
door_objs[door_objs.length - 1].destroy();
door_objs.pop();
counter--;
var _local3 = 0;
while (_local3 < door_objs.length) {
setDepthOfDoor(_local3);
_local3++;
}
}
}
function onOpening(door) {
var _local2 = 100;
var _local4 = ((door.__get__frame() < (door_frames / 2)) ? 100 : -100);
var _local3 = "open";
soundman.playSound(_local3, _local2, _local4);
}
function onInit() {
clearInterval(interval_init);
var _local2 = 100;
var _local4 = 0;
var _local3 = "doorbell";
soundman.playSound(_local3, _local2, _local4);
}
static var instance = null;
var door_objs = [];
var min_frame = 0;
var max_frame = 0;
var counter = 0;
}
Symbol 125 MovieClip [__Packages.Door] Frame 0
class Door
{
var dragging, mc_door, mc_shadow, ref_pos, dx_per_frame, maxspeed, friction, demping, frames, lastpos, origpos, door_prev, door_next;
function Door (mcdoor, mcshadow, ref_xs) {
dragging = false;
mc_door = mcdoor;
mc_shadow = mcshadow;
mc_door.stop();
mc_shadow.stop();
ref_pos = ref_xs;
mc_door.container = this;
mc_door.onPress = function () {
this.container.onPress();
this.onRelease = (this.onReleaseOutside = function () {
this.container.onRelease();
});
};
dx_per_frame = Parameters.dx_per_frame;
maxspeed = Parameters.maxstepsize * dx_per_frame;
friction = Parameters.friction;
demping = Parameters.demping;
collision_table = Parameters.collision_table;
frames = mc_door._totalframes;
counter = 0;
speed = (0);
}
function destroy() {
mc_door.removeMovieClip();
mc_shadow.removeMovieClip();
}
function show(bool) {
mc_door._visible = ((bool == undefined) ? true : (bool));
}
function step() {
var _local6 = mc_door._xmouse;
if (dragging) {
var _local8 = Math.round(_local6 - lastpos);
var _local3 = _local6 - origpos;
if ((_local3 < ref_pos[frame + 1]) and (frame < frames)) {
var _local5 = 1;
var _local2 = frame + 1;
while (_local2 <= frames) {
if (_local3 > ref_pos[_local2]) {
var _local4 = frame + Math.ceil(((_local2 - 1) - frame) / 2);
break;
}
_local2++;
}
if (_local4 == undefined) {
var _local4 = frame + Math.ceil((frames - frame) / 2);
}
} else if ((_local3 > ref_pos[frame - 1]) and (frame > 1)) {
var _local5 = -1;
var _local2 = frame - 1;
while (_local2 >= 1) {
if (_local3 < ref_pos[_local2]) {
var _local4 = frame + Math.floor(((_local2 + 1) - frame) / 2);
break;
}
_local2--;
}
if (_local4 == undefined) {
var _local4 = frame + Math.floor((1 - frame) / 2);
}
}
lastpos = _local6;
speed = (((_local4 == undefined) ? 0 : (Math.round(ref_pos[_local4] - ref_pos[frame]))));
} else {
counter = counter + Math.abs(speed);
if ((counter / dx_per_frame) >= 1) {
var _local7 = Math.floor(counter / dx_per_frame);
counter = counter % dx_per_frame;
var _local5 = (-speed) / Math.abs(speed);
var _local4 = Math.min(frames, Math.max(1, frame + (_local5 * _local7)));
}
}
if (_local4 != undefined) {
if (_local4 == frames) {
} else if (_local4 == 1) {
} else if (_local5 == 1) {
if ((door_prev != undefined) and (getCollisionFrame(door_prev.__get__frame(), _local5) < _local4)) {
var _local4 = getCollisionFrame(door_prev.__get__frame(), _local5);
notifyListeners("onCollision", [Math.abs(speed) + Math.abs(door_prev.__get__speed()), door_prev.__get__frame()]);
door_prev.addSpeed(speed * demping);
speed = (0);
}
} else if ((door_next != undefined) and (getCollisionFrame(door_next.__get__frame(), _local5) > _local4)) {
var _local4 = getCollisionFrame(door_next.__get__frame(), _local5);
notifyListeners("onCollision", [Math.abs(speed) + Math.abs(door_next.__get__speed()), door_next.__get__frame()]);
door_next.addSpeed(speed * demping);
speed = (0);
}
gotoFrame(_local4);
}
speed = speed * friction;
}
function getCollisionFrame(fr, dir) {
var _local4 = 0;
var _local2 = 0;
while (_local2 < collision_table.length) {
var _local3 = collision_table[_local2];
if (fr < _local3[0]) {
break;
}
_local4 = _local3[1];
_local2++;
}
return(fr - (dir * _local4));
}
function setDepth(n) {
mc_door.swapDepths(n);
mc_shadow.swapDepths(n);
}
function gotoFrame(n, bool_dont_notify) {
n = Math.min(frames, Math.max(1, n));
var _local3 = frame;
mc_door.gotoAndStop(n);
mc_shadow.gotoAndStop(n);
if (bool_dont_notify) {
return(undefined);
}
if (((_local3 == 1) and (n > 1)) or ((_local3 == frames) and (n < frames))) {
notifyListeners("onOpening", [this]);
} else if ((n == 49) or (n == 50)) {
notifyListeners("onCenter", [this]);
} else if (n >= frames) {
notifyListeners("onComplete", [this]);
speed = (0);
counter = 0;
if (Parameters.stop_dragging_on_end) {
dragging = false;
}
} else if (n <= 1) {
notifyListeners("onClosed", [this]);
speed = (0);
counter = 0;
if (Parameters.stop_dragging_on_end) {
dragging = false;
}
}
}
function get mc() {
return(mc_door);
}
function get frame() {
return(mc_door._currentframe);
}
function set speed(n) {
_speed = Math.max(-maxspeed, Math.min(maxspeed, n));
counter = 0;
//return(speed);
}
function get speed() {
return(_speed);
}
function addSpeed(n) {
speed = (speed + n);
}
function onPress() {
_speed = 0;
dragging = true;
lastpos = mc_door._xmouse;
origpos = mc_door._xmouse - ref_pos[frame];
}
function onRelease() {
dragging = false;
}
function addListener(cbobj, cbfn, eventname) {
if (_listeners[eventname] eq undefined) {
_listeners[eventname] = [];
}
for (var _local5 in _listeners[eventname]) {
if (_listeners[eventname][_local5][0] == cbobj) {
var _local3 = true;
break;
}
}
if (!_local3) {
_listeners[eventname].push([cbobj, cbfn]);
}
}
function removeListener(cbobj, eventname) {
if (eventname != undefined) {
for (var _local4 in _listeners) {
for (var _local5 in _listeners[_local4]) {
if (_listeners[_local4][_local5][0] == cbobj) {
_listeners[_local4][_local5][0] = null;
}
}
}
} else {
for (var _local5 in _listeners[eventname]) {
if (_listeners[eventname][_local5][0] == cbobj) {
_listeners[_local4][_local5][0] = null;
}
}
}
}
function notifyListeners(eventname, args) {
var _local2 = 0;
while (_local2 < _listeners[eventname].length) {
var _local3 = _listeners[eventname][_local2];
_local3[1].apply(_local3[0], args);
_local2++;
}
}
var collision_table = [];
var _speed = 0;
var counter = 0;
var _listeners = {};
}
Symbol 126 MovieClip [__Packages.Parameters] Frame 0
class Parameters
{
function Parameters () {
}
static var delay_dingdong = 300;
static var dx_per_frame = 10;
static var maxstepsize = 25;
static var friction = 0.95;
static var demping = 0.7;
static var stop_dragging_on_end = false;
static var vol_min = 40;
static var max_vol_at_force = 70;
static var sound_pan_factor = 1;
static var collision_table = [[1, 0], [8, 2], [12, 3], [18, 4], [83, 3], [89, 2], [93, 1], [101, 0]];
static var door_frames = 101;
}
Symbol 127 MovieClip [__Packages.SoundManager] Frame 0
class SoundManager
{
function SoundManager () {
}
function playSound(id, vol, pan) {
var _local4 = _global.root.getNextHighestDepth();
var _local3 = _global.doors_movie.createEmptyMovieClip("mc_sound" + _local4, _local4);
var snd = new Sound(_local3);
snd.setVolume(((vol == undefined) ? 100 : (vol)));
snd.setPan(Parameters.sound_pan_factor * ((pan == undefined) ? 0 : (pan)));
snd.attachSound(id);
snd.start();
_local3.snd = snd;
_local3.onEnterFrame = function () {
if (snd.position == snd.duration) {
this.removeMovieClip();
}
};
}
}