Object move, HitTest, arrow keys

hi! i have an object and a box around it
i want my object to be only in the box area.
so it shouldn’t be move through it.
i know how to stop it when the object hits the wall, but then everything stops.

    ActionScript Code:
 [FONT=Courier New][LEFT][COLOR=#000000]**var**[/COLOR] speed:[COLOR=#0000ff]int[/COLOR]=[COLOR=#000080]5[/COLOR];     

[COLOR=#000000]var[/COLOR] [COLOR=#0000ff]stop[/COLOR]:[COLOR=#0000ff]Boolean[/COLOR]=[COLOR=#000000]false[/COLOR];
[COLOR=#000000]var[/COLOR] _hit:[COLOR=#0000ff]Boolean[/COLOR]=[COLOR=#000000]false[/COLOR]; [COLOR=#000000]**

var**[/COLOR] hit:[COLOR=#0000ff]Boolean[/COLOR] = [COLOR=#0000ff]HitTest[/COLOR].[COLOR=#000080]complexHitTestObject[/COLOR][COLOR=#000000]([/COLOR] [COLOR=#0000ff]object[/COLOR], wall, [COLOR=#000080]1[/COLOR] [COLOR=#000000])[/COLOR];
[COLOR=#0000ff]if[/COLOR][COLOR=#000000]([/COLOR] hit != _hit [COLOR=#000000])[/COLOR]
[COLOR=#000000]{[/COLOR] _hit = hit;
[COLOR=#0000ff]stop[/COLOR]=[COLOR=#000000]true[/COLOR];
trace[COLOR=#000000]([/COLOR][COLOR=#ff0000]“object hits the wall”[/COLOR][COLOR=#000000])[/COLOR];
[COLOR=#000000]}[/COLOR]

[COLOR=#0000ff]if[/COLOR][COLOR=#000000]([/COLOR]![COLOR=#0000ff]stop[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  

[COLOR=#0000ff]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR] [COLOR=#0000ff]object[/COLOR].[COLOR=#000080]x[/COLOR]-=[COLOR=#000080]2[/COLOR] * speed; [COLOR=#000000]}[/COLOR]
[COLOR=#0000ff]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR] [COLOR=#0000ff]object[/COLOR].[COLOR=#000080]x[/COLOR]+=[COLOR=#000080]2[/COLOR] * speed; [COLOR=#000000]}[/COLOR]
[COLOR=#0000ff]if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR] [COLOR=#0000ff]object[/COLOR].[COLOR=#000080]y[/COLOR]-=[COLOR=#000080]2[/COLOR] * speed; [COLOR=#000000]}[/COLOR] [COLOR=#0000ff]
if[/COLOR] COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR] [COLOR=#0000ff]object[/COLOR].[COLOR=#000080]y[/COLOR]+=[COLOR=#000080]2[/COLOR] * speed; [COLOR=#000000]}[/COLOR]

[COLOR=#000000]}

does anybody know how can i keep my object in the box (wall) area?
attached image is how it looks like
[/COLOR] [/LEFT]
[/FONT]