Wall and Floor Collisions

I’m having some trouble making a simple 2D platformer. Basically I have this code that tests for floor and ceiling collisions while the character is jumping. I have another set of code that prevents it from walking through walls. Both work by themselves, but when they are together they don’t. When the character touches the floor, it immediately teleports to the right side of the platform (where there is no longer floor) and falls until it reaches another floor. It then repeats this process every time it hits a floor. How can I fix this?
The jump code:


if (up&&!jump) {
     jSpeed=8;
     if (currentFrame<26) {
          jump=true;
          gotoAndStop(26);
    }
}
if (jump) {
    if (jSpeed>0) gotoAndStop(27);
    else gotoAndStop(28);
    this.y-=jSpeed;
    jSpeed-=.4;
}
for (var i:int=0; i<r.mArray[0].length; i++){
    var h:DisplayObject=r.mArray[0]*;
    jump=true;
    if (mA[2].hitTestObject(h)&&y<h.y) { //if on ground
        jSpeed=0;
        jump=false;
        ground=true;
        if (currentFrame>26&&currentFrame!=29) gotoAndStop(1);
        y=h.y-23;
        break;
    }
    if (mA[2].hitTestObject(h)&&y>h.y) { //if hits ceiling
        jSpeed*=-1;
        y=h.y+h.height+30.7;
        break;
    }
}

h is the floor/wall being tested and mA[2] is the mask of the character.

The wall code:


for (var j:int=0; j<r.mArray[0].length; j++) {
    var w=r.mArray[0][j];
    var v=mA[2];
    if (x>w.x) while (v.hitTestObject(w)&&x<w.x-v.width) pan(-1); //right
    else while (v.hitTestObject(w)&&w.x<x+v.width) pan(1); //left
}

w is the wall being tested and v is the mask of the character. The function pan() moves the walls and other objects to give the appearance the character is moving.

If anybody could help me I would really appreciate it. This has been bugging me for a while and I feel like the answer is so simple but I just can’t see it. Thank you in advance.