Skip to main content
October 28, 2010
Question

AS3 MC to timeline?

  • October 28, 2010
  • 1 reply
  • 271 views

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?

This topic has been closed for replies.

1 reply

October 28, 2010

EDIT: changed the "facing the door" frame to if(dörr) and if(papper), but it still doesn't work.

EDIT2: It works clicking the door.

But now the timeline won't stop at where the room actually is.

It just keeps repeating and repeating..

EDIT3: 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