views:

40

answers:

2

So this is a weird error that I am getting because I have four movie clips on my frame that I have running back and forth across the screen in a frogger like game. Three of them work and the fourth one does not even though I have the same code basically for all of them. Why would I get an error for one, but not the other 3? Here is my code:

if((chris.x - laneOne) >= 0 && !turn1){
    chris.scaleX = 1;
    chris.x -= laneOne;
    turn1 = false;
}else{
    turn1 = true;
}
if((chris.x + laneOne) <= 500 && turn1){
    chris.scaleX = -1;
    chris.x += laneOne;
    turn1 = true;
}else{
    turn1 = false;
}
//Lane 2
if((kate.x - laneTwo) >= 0 && !turn2){
    kate.scaleX = 1;
    kate.x -= laneTwo;
    turn2 = false;
}else{
    turn2 = true;
}
if((kate.x + laneTwo) <= 500 && turn2){
    kate.scaleX = -1;
    kate.x += laneTwo;
    turn2 = true;
}else{
    turn2 = false;
}
//Lane 3
/*if((seth.x - laneThree) >= 0 && !turn3){
    seth.scaleX = 1;
    seth.x -= laneThree;
    turn3 = false;
}else{
    turn3 = true;
}
if((seth.x + laneThree) <= 500 && turn3){
    seth.scaleX = -1;
    seth.x += laneThree;
    turn3 = true;
}else{
    turn3 = false;
}*/
//Lane 4
if((mel.x - laneFour) >= 0 && !turn4){
    mel.scaleX = 1;
    mel.x -= laneFour;
    turn4 = false;
}else{
    turn4 = true;
}
if((mel.x + laneFour) <= 500 && turn4){
    mel.scaleX = -1;
    mel.x += laneFour;
    turn4 = true;
}else{
    turn4 = false;
}

Seth is the one that doesn't work, but basically this makes these movie clips of running characters look like they are running back and forth and the lanes is the speed at which they go and the turns are just to make sure that they go all the way to the side.

That is my first question.

My second question is I have a character on the same frame and I want to move him via the keyboard and I am using senocular's keyObject class and it doesn't work unless if I minimize the screen and then re-open the screen. Once I re-open the screen it works just fine.

I have a hunch that both of these problems are related to a movie clip not being fully loaded, but I am new to flash and as3 so any help would be greatly appreciated. Also if more clarification is needed please ask for it so I can get some help cause I have had this problem for about 2 days now and still can't figure it out!

A: 

Problem 1: use trace() to find out whether or not 'seth' is undefined for some reason. Since the code you pasted doesn't mention Seth I can't make a better suggestion there... [edit: StackOverflow is truncating your code on my iPhone, but trace is still how I would debug the problem, look for undefined properties]

Problem 2: make sure your key listeners are added to the stage and not a child object. That way you don't have to click the Swf to gain focus before the listeners work.

[edit 2: figured out how to see your code -- the 'seth' codeblock is commented out, is that your problem?]

Casey
haha no seth being commented out is not my problem, actually I posted this on flash forum as well and I got an answer there to my first question, but now I am still trying to figure out the second one. Also yes my listeners are added to the stage.
Chris
You'll need to post some code for #2 if you want help on that one. It's also nice to post the solution to your first problem so others can see how it was solved
Casey
A: 
Chris