无法找到1026错误请求位置帮助

时间:2015-12-11 14:58:43

标签: actionscript-3 flash

我似乎无法找到1026错误的来源:

import flash.events.KeyboardEvent;
import flash.events.Event;
import flash.ui.Keyboard;
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.events.*;
import flash.display.Sprite;
import fl.controls.ProgressBar;
stop();
var NueMCSpeed:Number = 10;
var _movingUp:Boolean = false;
var _movingDown:Boolean = false;
var _movingLeft:Boolean = false;
var _movingRight:Boolean = false;
var _focused:Boolean = false;
var _attacking:Boolean = false;
var ShootAllow:Boolean = true;
var timer:Number = 2;
var shotN:Number = 0;
var SHOTINDEX:Number  = 0;
NueMC.gotoAndStop("NueG");
var _root:Object;
var speed:int = 10;
Mainp();
function Mainp()
{
    //var NueMC:MovieClip;

    // add listeners
    stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
    stage.addEventListener(KeyboardEvent.KEY_DOWN, myOnPress);
    stage.addEventListener(KeyboardEvent.KEY_UP, myOnRelease);
}
function createPlayer():void
{
    var NueMC:MovieClip;
    NueMC.x = stage.stageWidth / 2;
    NueMC.y = stage.stageHeight / 2;
    stage.addChild(NueMC);
}

function myOnPress(event:KeyboardEvent):void
{
    switch ( event.keyCode )
    {
        case Keyboard.UP :
            _movingUp = true;
            NueMC.gotoAndStop("NueG");
            break;

        case Keyboard.DOWN :
            _movingDown = true;
            NueMC.gotoAndStop("NueG");
            break;

        case Keyboard.LEFT :
            _movingLeft = true;
            NueMC.gotoAndStop("NueL");
            break;

        case Keyboard.RIGHT :
            _movingRight = true;
            NueMC.gotoAndStop("NueR");
            break;

        case Keyboard.SHIFT :
            _focused = true;
            break;

        case Keyboard.Z :
            _attacking = true;
            //timer++
            //if(timer == 3){
                //shoot();
                //timer = 0
            //}
            break;
    }
}
function myOnRelease(event:KeyboardEvent):void
{
    switch ( event.keyCode )
    {
        case Keyboard.UP :
            _movingUp = false;
            NueMC.gotoAndStop("NueG");
            break;

        case Keyboard.DOWN :
            _movingDown = false;
            NueMC.gotoAndStop("NueG");
            break;

        case Keyboard.LEFT :
            _movingLeft = false;
            NueMC.gotoAndStop("NueG");
            break;

        case Keyboard.RIGHT :
            _movingRight = false;
            NueMC.gotoAndStop("NueG");
            break;

        case Keyboard.SHIFT :
            _focused = false;
            break;

        case Keyboard.Z :
            _attacking = false;
            break;
    }
}
function enterFrameHandler(event:Event):void
{
    if (_focused == true)
    {
        NueMCSpeed = 5;
        ShootAllow = true
    }
    if (_focused == false)
    {
        NueMCSpeed = 10;
    }
    if ( _movingLeft && !_movingRight )
    {
        NueMC.x -=  NueMCSpeed;
    }
    if ( _movingRight && !_movingLeft )
    {
        NueMC.x +=  NueMCSpeed;
    }
    if ( _movingUp && !_movingDown )
    {
        NueMC.y -=  NueMCSpeed;
    }
    if ( _movingDown && !_movingUp )
    {
        NueMC.y +=  NueMCSpeed;
    }
    if(NueMC.y < 165)
{
    NueMC.y = 165
}
if(NueMC.y > 885)
{
    NueMC.y = 885
}
if(NueMC.x > 520)
{
    NueMC.x = 520
}
if(NueMC.x < 10)
{
    NueMC.x = 10
}


    // Move diagonally
    if ( _movingLeft && _movingUp && !_movingRight && !_movingDown )
    {

    }
    if ( _movingRight && _movingUp && !_movingLeft && !_movingDown )
    {

    }
    if ( _movingLeft && _movingDown && !_movingRight && !_movingUp )
    {

    }
    if ( _movingRight && _movingDown && !_movingLeft && !_movingUp )
    {

    }

}

var pIsDead:Boolean = false;

var LSP:Number = .1;

var NP:Number = .0001;

var vx:Number = NueMC.x;

var vy:Number = NueMC.y;

var BHPN:Number = BHP.scaleX

if(ShootAllow == true && _attacking == true)
{
stageRef.addChild(new Bullet(stageRef, x + vx, y + vy));
ShootAllow = false;
}
if (NueMC.NHB.hitTestObject(stage.DBS.DBHB) && NueLB.scaleX > .1)

{

NueLB.scaleX -= LSP;
Score -=10000;
NueMC.gotoAndStop("NueDie");
pIsDead = true;

}

然后在.as文件中我有:

package 
{

    import flash.display.MovieClip;
    import fl.controls.ProgressBar;
    import flash.display.Stage;

    import flash.events.Event;


    public class Bullet2 extends flash.display.MovieClip
    {


        private var stageRef2:Stage;
        private var bulletSpeed:Number = 20;
        public function Bullet2(stageRef:Stage, xd:Number, yd:Number):void
        {

            this.stageRef = stageRef2;

            this.x = xd;

            this.y = yd;


            addEventListener(Event.ENTER_FRAME, loop, false, 0, true);

        }


        private function loop(e:Event):void
        {

            y -=  bulletSpeed;

            if (y < 125)
            {
                removeSelf();
            }
        }


        private function removeSelf():void
        {

            removeEventListener(Event.ENTER_FRAME, loop);


            if (stageRef.contains(this))
            {
                stageRef.removeChild(this);

            }

        }

    }
}

我需要尽快完成这个程序,所以非常感谢帮助。 PS代码很长,因为我不知道错误在哪里,因为flash不想给我这条线。

1 个答案:

答案 0 :(得分:1)

错误在这一行:function Mainp()问题是它位于时间轴上,您不能在时间轴上放置构造函数。您应该找到主*.as文件,并在Mainp()定义中放置class Mainp