You need to control the sprite's movement using variables. Working code is worth a 1000 words:
Rem Project: Dark Basic Pro Project
Rem Created: Saturday, November 06, 2010
Rem ***** Main Source File *****
create animated sprite 1,"ZeroX run and jump.png",12,2,1
sync on : sync rate 90
ScrWid = screen width() : ScrHgt = screen height()
x = 20 : y = 400
MaxX = ScrWid - 60 : MinX = 2 : MaxY = 398 : MinY = 2
direction = 0 : StartFrame = 1 : EndFrame = 12
jumping = 0 : JumpCount = 0 : delay = 50 : player = 1
RunStart = 1 : RunEnd = 12 : JumpStart = 13 : JumpEnd = 19
do
if direction > 0 then OldDirection = direction
direction = 0
if rightkey() = 1
if OldDirection = 8 then Mirror sprite player
direction = 4
if x < MaxX then inc x,2
StartFrame = RunStart : EndFrame = RunEnd
endif
if leftkey() = 1
if OldDirection = 4 then Mirror sprite player
direction = 8
if x > MinX then dec x,2
StartFrame = RunStart : EndFrame = RunEnd
endif
if spacekey() = 1 and jumping = 0
if direction = 0 then StartFrame = JumpStart : EndFrame = JumpEnd
jumping = 1 : JumpCount = 40
endif
if jumping = 1
if JumpCount > 20
if y > MinY then dec y,2
else
if y < MaxY then inc y,2
endif
if direction = 4 and x < MaxX then inc x,2
if direction = 8 and x > MinX then dec x,2
dec JumpCount,1
if JumpCount = 0 then jumping = 0
endif
sprite player,x,y,sprite image(1)
if direction > 0 or jumping > 0 then play sprite player,StartFrame,EndFrame,delay
sync
loop
I have attached the .png file that I made from your .gif image that is used in the code. It should be pretty straightforward, so I did not add comments to it.
You can move left or right, even while jumping. I realize the frames are not exactly lined up, but it is only to give you a working example to answer your question.