Next level via using 1 key? :S

Hi guys, I have yet another problem!

I’ve been working on this really cool platform/adventure game and in this game to get to the next level you have to go through a door, but this door isn’t on the stage until you get the magical gem. Before you say, I have all of that sorted out it’s just I don’t know what code to use for when the door is on the stage and to get to the next level the character (instance: char) is on the door movieclip (instance: door) AND the player has to press the D key(68) to get to the next level.

My friend gave me this code to go inside of the players code:
if(Key.isDown(68)){
if(Math.abs(_x-door._x)<(door._width/2)){
_root.gotoAndStop(2)
}
}

But nothing happens?

Please could you reply a.s.a.p!

that code should work assuming you have level 1 on frame 1, and level 2 on frame 2 of your timeline…

if(Key.isDown(68) and char.hitTest(door._x,door._y,true))
{
this.gotoAndStop(“level 2”)
}