开发者

Flash and as3 question

开发者 https://www.devze.com 2023-01-07 06:55 出处:网络
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 on

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) 开发者_C百科>= 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!


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?]


Okay so the answer to the first problem is that I had the same movie clip in a previous frame so all I had to do to get it to work is give it a different instance name.

For the second question I am still stumped. All I have is a screen where the user can click on a button to play the game before it starts and after I click the button to play the main character doesn't move unless I minimize the screen and re-open it, which is not good. I did it before with a class, and the button was a movie clip, but now I am using just a simple button and have the same conundrum.

Here is the code I have to make it go to the actual game:

stop();
playGame.addEventListener(MouseEvent.CLICK, buttonClicked);
var clicked:Boolean = false;
function buttonClicked(event:MouseEvent){
    clicked = true;
    this.gotoAndStop('start');
}

Does this help you guys help me?

0

精彩评论

暂无评论...
验证码 换一张
取 消