# AS3 MC to timeline?

**URL:** <https://forum.kirupa.com/t/as3-mc-to-timeline/315532>\
**Category:** flash\
**Created:** [October 28, 2010, 9:06am UTC](https://forum.kirupa.com/t/as3-mc-to-timeline/315532 "2010-10-28T09:06:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![InvisAr](https://avatars.discourse-cdn.com/v4/letter/i/94ad74/32.png) [@InvisAr](https://forum.kirupa.com/u/InvisAr)\
**Post date:** [October 28, 2010, 9:06am UTC](https://forum.kirupa.com/t/as3-mc-to-timeline/315532/1 "2010-10-28T09:06:27Z")

</div>

Hi!

Having problems with a game I’m creating in as3.  
After leaving the main game screen(the corridor in this case) the user comes to facing a door.  
Here, the user can click the door and enter a room.  
But, the problem is, the user in this case can’t click the door again after leaving the main gamescreen.  
I don’t know why, searched for problems and errors in the code, but found none.

Here’s the code for the main gamescreen:  
[AS]stop();  
import flash.display.DisplayObject;  
import flash.events.Event;  
import flash.events.MouseEvent;

var musDoor1:Boolean;  
var musDoor2:Boolean;  
var musDoor3:Boolean;  
var musDoor4:Boolean;  
var musDoor5:Boolean;  
var musDoor6:Boolean;  
var musDoor7:Boolean;  
var musDoor8:Boolean;  
var musDoor9:Boolean;

var doors:Array = [door\_mc,  
door\_mc1,  
door\_mc2,  
door\_mc3,  
door\_mc4,  
door\_mc5,  
door\_mc6,  
door\_mc7,  
door\_mc8];

this.addMouseEventListenerToEachDoor();  
super.stage.addEventListener(Event.ENTER\_FRAME, this.enterFrameHandler);

function addMouseEventListenerToEachDoor():void  
{  
var i:int = doors.length;  
while (i–)  
{  
doors\*.addEventListener(MouseEvent.MOUSE\_DOWN, this.mouseDownHandler);  
}  
}

function enterFrameHandler(event:Event):void  
{  
if (musDoor1) { door\_mc && door\_mc.callMe();  
door\_mc && door\_mc.addEventListener(“timeLineFinished”, onDoorPlayed);}  
else if (musDoor2) { door\_mc1.callMe();  
door\_mc1.addEventListener(“timeLineFinished”, onDoorPlayed1);}  
else if (musDoor3) { door\_mc2.callMe();  
door\_mc2.addEventListener(“timeLineFinished”, onDoorPlayed2);}  
else if (musDoor4) { door\_mc3.callMe();  
door\_mc3.addEventListener(“timeLineFinished”, onDoorPlayed3) }  
else if (musDoor5) { door\_mc4.callMe();  
door\_mc4.addEventListener(“timeLineFinished”, onDoorPlayed4) }  
else if (musDoor6) { door\_mc5.callMe();  
door\_mc5.addEventListener(“timeLineFinished”, onDoorPlayed5) }  
else if (musDoor7) { door\_mc6.callMe();  
door\_mc6.addEventListener(“timeLineFinished”, onDoorPlayed6) }  
else if (musDoor8) { door\_mc7.callMe();  
door\_mc7.addEventListener(“timeLineFinished”, onDoorPlayed7) }  
else if (musDoor9) { door\_mc8.callMe();  
door\_mc8.addEventListener(“timeLineFinished”, onDoorPlayed8) }  
else stop();  
}

function mouseDownHandler(event:MouseEvent):void  
{  
switch(event.target)  
{  
case door\_mc : musDoor1 = true; break;  
case door\_mc1 : musDoor2 = true; break;  
case door\_mc2 : musDoor3 = true; break;  
case door\_mc3 : musDoor4 = true; break;  
case door\_mc4 : musDoor5 = true; break;  
case door\_mc5 : musDoor6 = true; break;  
case door\_mc6 : musDoor7 = true; break;  
case door\_mc7 : musDoor8 = true; break;  
case door\_mc8 : musDoor9 = true; break;  
default: break;  
}  
}

function onDoorPlayed(e:Event):void  
{  
gotoAndPlay(3);  
}

function onDoorPlayed1(e:Event):void  
{  
gotoAndPlay(4);  
}

function onDoorPlayed2(e:Event):void  
{  
gotoAndPlay(5);  
}

function onDoorPlayed3(e:Event):void  
{  
gotoAndPlay(6);  
}

function onDoorPlayed4(e:Event):void  
{  
gotoAndPlay(8);  
}

function onDoorPlayed5(e:Event):void  
{  
gotoAndPlay(9);  
}

function onDoorPlayed6(e:Event):void  
{  
gotoAndPlay(10);  
}

function onDoorPlayed7(e:Event):void  
{  
gotoAndPlay(11);  
}

function onDoorPlayed8(e:Event):void  
{  
gotoAndPlay(12);  
}[/AS]

The code for the movieclip which is the first door is this:  
[AS]  
stop();  
function callMe():void  
{  
play();  
}

addEventListener(Event.ENTER\_FRAME, onEnterFrame);

function onEnterFrame(e:Event):void  
{  
if (currentFrame == totalFrames)  
{  
dispatchEvent(new Event(“timeLineFinished”));  
}  
}[/AS]

And the code for “facing” the door after clicking it in the corridor:  
[AS]  
stop();  
import flash.display.MovieClip;  
import flash.display.DisplayObject;  
import flash.events.Event;  
import flash.events.MouseEvent;

var dörr:Boolean;  
var papper:Boolean;

var döpp:Array = [door\_btn,  
paper\_btn];

this.addEvents();  
super.stage.addEventListener(Event.ENTER\_FRAME, FRAME);

function addEvents():void  
{  
var i2:int = döpp.length;  
while(i2–)  
{  
döpp[i2].addEventListener(MouseEvent.MOUSE\_DOWN, clickhandle);  
}  
}

function FRAME(event:Event):void  
{  
if(door\_btn) { door\_btn && door\_btn.callMe();  
door\_btn && door\_btn.addEventListener(“timeLineFinished”, onDoorPlay)}  
else if(paper\_btn) { paper\_btn && paper\_btn.callBtn();  
paper\_btn && paper\_btn.addEventListener(“timeLineFinished”, onBtnPlay)}  
else stop();  
}

function clickhandle(event:MouseEvent):void  
{  
switch(event.target)  
{  
case door\_btn : dörr = true; break;  
case paper\_btn : papper = true; break;  
default: break;  
}  
}

function onDoorPlay(event:Event):void  
{  
gotoAndPlay(2);  
}

function onBtnPlay(event:Event):void  
{  
stop();  
}  
[/AS]

And the codes for the door & paper in that screen is approx. the same as for the doors.

Any ideas?  
Thanks!

EDIT : Can click the door, but when the timeline reaches the frame where the input textfield is to be created, it isn’t.The framescript doesn’t run… :S
