user1847226
user1847226

Reputation: 3

Action Script 2 only last function working

I have this problem where only the last function works, and all of the previous ones are ignored by flash. Since all the functions are written the same way, I can't find the problem.

This code is simply a press button to change scene type of thing, where I press a certain key and it changes, but in this case only the last key I've chosen works.

Any tip?

var gomas:Object = new Object();
var chocolate:Object = new Object();
var tarte:Object = new Object();
var peixe:Object = new Object();
var lama:Object = new Object();

gomas.onKeyDown = function() 
    {
        if (Key.getCode() == "51","54","222","87","73","71","86"); 
            {
                   loadMovieNum("01 Gomas.swf",0);
            }
    };
Key.addListener(gomas);

chocolate.onKeyDown = function() 
    {
        if (Key.getCode() == "49","56","69","71","76","67","78");
            {
                   loadMovieNum("02 Chocolate.swf",0);
            }
    };
Key.addListener(chocolate);

tarte.onKeyDown = function() 
    {
        if (Key.getCode() == "52","48","82","75","66","85");
            {
                   loadMovieNum("03 Tarte.swf",0);
            }
    };
Key.addListener(tarte);

peixe.onKeyDown = function() 
    {
        if (Key.getCode() == "50","55","84","79","83","72","77"); 
            {
                   loadMovieNum("04 Peixe.swf",0);
            }
    };
Key.addListener(peixe);

lama.onKeyDown = function() 
    {
        if (Key.getCode() == "53","57","81","89","80","68","74"); 
            {
                   loadMovieNum("05 Lama.swf",0);
            }
    };
Key.addListener(lama);

Upvotes: 0

Views: 68

Answers (1)

mitim
mitim

Reputation: 3201

It looks like the problem is in your if statements. Running your code, all of the methods get called in order when a key is pressed. Since they all load an swf in to the same level, they'd overwrite resulting in the last one being loaded.

I don't think you can put in commas like that, it seems to get treated as a different condition. This always traces out "yes" (my guess is due to the "54" being 'truthy'):

var temp:String = "1";
if(temp == "0", "54"){
    trace("yes");
}

I'd suggest using a switch statement since you just want to check key codes matching single values.

Upvotes: 1

Related Questions