0

所以我是 AS3 的新手,试图为智能手机制作一个简单的视频游戏。在我遇到这个问题之前,一切都很顺利。我在时间轴上使用和操作对象没有问题,而且突然间无论我尝试什么,我都得到了 1046。

这是一些出现错误的代码:

mp = new MP_00();

在顶部我有这个:

import flash.display.MovieClip;
var mp:Movieclip;

最后是:

function mapMove(){
mp.y = mp.y - playerSpeed;
}

我一直在寻找解决方案,但似乎没有人遇到同样的问题。我确实将 AS 链接设置为 MP_00 并且我尝试放入的任何对象,它都不起作用。虽然以前以相同的方式放置物体,但它们可以工作。

例如我有这个

var player:MovieClip;

player = new Player();

将 AS Linkage 设置为 Player,并且可以正常工作。

这一切都在 Flash Professional cs6 中完成

编辑 1 完整代码 请记住,很多东西是占位符或只是未完成的代码。

在此代码上,我为同一个对象两次收到错误

Scene 1 1046: Type was not found or was not a compile-time constant:
MP_00. 
Scene 1, Layer 'Actions', Frame 1, Line 165 1046: Type was not
found or was not a compile-time constant: MP_00.

这就是错误。

import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.text.engine.SpaceJustifier;
import flashx.textLayout.operations.MoveChildrenOperation;

/*----------------------------Main VARs-----------------------------*/
var STATE_START:String="STATE_START";
var STATE_START_PLAYER:String="STATE_START_PLAYER";
var STATE_PLAY:String="STATE_PLAY";
var STATE_END:String="STATE_END";
var gameState:String;

var player:MovieClip;
var playerSpeed:Number;
var map:Array;
var bullets:Array;
//holds civil vehicles
var civil:Array; 
//holds enemy vehicles
var enemy:Array; 
var explosions:Array;

var BBullet:MovieClip;

//maps
var mp:MovieClip;
/*
var MP_01:MovieClip;
var MP_02:MovieClip;
var MP_03:MovieClip; 
*/

//sets the bullet type and properties
var BType = "BBasic";
var BProp:Array;

//bullet preperties by type

var BBasic:Array = new Array(1, 1, 100, 50, 0, new BBasicA());

/**
ARRAY SETTING
0 = bullet position (middle , back, sides etc...)
    1-middle front
    2-left side front
    3-right side front
    4-left and right side middle
    5-back
    7-left and right side wheels

1 = bullet direction
    1-forward
    2-back
    3-sides

2 = fire speed (in millisecounds so 1000 = 1sec)

3 = speed of movement

4 = damage 10-100

5 = name of the firing animation in library

6 = name of launch animation in library

7 = name of impact animation in library 
**/

var level:Number;

//BCivil speed and randomness
var BCSpeed:Number = 3;
var BCRand:Number = 120;

/*------------------------------Setup-------------------------------*/


introScreen.visible = false;
loadingScreen.visible = false;
gameScreen.visible = false;
endScreen.visible = false;

//map visibility
//MpRSimple.visible = false;

/*---------------------------Intro screen--------------------------*/


/*-----------------------------mainScreen---------------------------*/

mainScreen.play_btn.addEventListener(MouseEvent.CLICK, clickAway);
function clickAway(event:MouseEvent):void
{
    gameStart();
    }

function gameStart():void
{
    //Move main screen from stage
    mainScreen.visible = false;

    //Begin loading the game
    loadingScreen.visible = true;
    gameState = STATE_START;
    trace (gameState);
    addEventListener(Event.ENTER_FRAME, gameLoop);
    }

/*----------------------------gameLoop-----------------------------*/

function gameLoop(e:Event):void
{
    switch(gameState)
    {
        case STATE_START:
            startGame();
            break;

        case STATE_START_PLAYER:
            startPlayer();
            break;

        case STATE_PLAY:
            playGame();
            break;

        case STATE_END:
            endGame();
            break;

        }
    }
/*-_________________________-Game STATES-_________________________-*/

/*---------------------------STATE_START---------------------------*/

function startGame():void
{

    level = 1; //setting level for enemies

    //Graphics
        //player icon
    player = new Player(); 
        //add bullet holder
    bullets = new Array();
        //basicCivil icon
    civil = new Array(); 
        //basicEnemy icon
    enemy = new Array(); 
        //holds explosions
    explosions = new Array(); 

    //map
    //mp = new MP_00();
    //var mp:MP_00 = new MP_00();

    //Load map parts

    //End startGame
    gameState = STATE_START_PLAYER;
    trace(gameState);
    }

/*------------------------STATE_START_PLAYER-----------------------*/

function startPlayer():void
{
    //start the player

    //set possition of player
    player.y = stage.stageHeight - player.height;
    addChild(player);
    addEventListener(Event.ENTER_FRAME, movePlayer);

    //changing screens
    gameScreen.visible = true;

    //start game
    gameState = STATE_PLAY;
    trace(gameState);

    }

//player controll
function movePlayer(e:Event):void 
{

    //gameScreen.visible = true;

    //mouse\touch recognition
    player.x = stage.mouseX;
    player.y = stage.mouseY;

    //player does not move out of the stage
    if (player.x < 0)
    {
        player.x = 0;
    }
    else if (player.x > (stage.stageWidth - player.width))
    {
        player.x = stage.stageWidth + player.width;
    }

    }

//setting bullet type
if (BType == "BBasic")
{
        BProp = BBasic;
    /*case BMissile;
        BProp = BMissile;
        break; */
    }
//creating bullets


//gameScreen.fire_btn.addEventListener(MouseEvent.CLICK, fireHandler());


/*
function fireHandler():void
{
    var bulletTimer:Timer = new Timer (500);
    bulletTimer.addEventListener(TimerEvent.TIMER, timerListener);
    bulletTimer.start();
    trace("nja");
    }

function timerListener(e:TimerEvent):void
{
    //need and if statement to determine the bullet speed and travel depended on type of bullet
    var tempBullet:MovieClip = /*BProp[5] new BBasicA();
    //shoots bullets in the middle
    tempBullet.x = player.x +(player.width/2); 
    tempBullet.y = player.y;
    //shooting speed
    tempBullet.speed = 10; 
    bullets.push(tempBullet);
    addChild(tempBullet);
    //bullets movement forward
    for(var i=bullets.length-1; i>=0; i--)
    {
        tempBullet = bullets[i];
        tempBullet.y -= tempBullet.speed;
        }
    }
*/

/*----------------------------STATE_PLAY---------------------------*/

function playGame():void
{
    //gameplay
    //speedUp();
    mapMove();
    //fire();
    makeBCivil();
    makeBEnemy();
    moveBCivil();
    moveBEnemy();
    vhDrops();
    testCollision();
    testForEnd();
    removeExEplosions();
    }


function mapMove(){
    mp.y = mp.y - playerSpeed;
    }

/*
function speedUp():void
{
    var f:Number;
    for (f<10; f++;)
    {
        var playerSpeed = playerSpeed + 1;
        f = 0;
        //mapMove();
        MpRSimple = new MP_RS();
        MpRSimple.y = MpRSimple.y - playerSpeed;
        trace ("speed reset");
        }
    trace (f);
    }
*/

function makeBCivil():void
{
    //random chance
    var chance:Number = Math.floor(Math.random()*BCRand);
    if (chance <= 1 + level) 
    {
        var tempBCivil:MovieClip;
        //generate enemies
        tempBCivil = new BCivil();
        tempBCivil.speed = BCSpeed;
        tempBCivil.x = Math.round(Math.random()*800);

        addChild(tempBCivil);
        civil.push(tempBCivil);
        }
    }

function moveBCivil():void
{
    //move enemies
    var tempBCivil:MovieClip;
    for(var i:int = civil.length-1; i>=0; i--)
    {
        tempBCivil = civil[i];
        tempBCivil.y += tempBCivil.speed
        }

    //testion colision with the player and screen out
    if (tempBCivil.y > stage.stageHeight /* || tempBCivil.hitTestObject(player) */)
    {
        trace("ds hit");
        //makeExplosion (player.x, player.y);
        removeCivil(i);
        //gameState = STATE_END;
        }
    }

//Test bullet colision
function testCollision():void
{
    var tempBCivil:MovieClip;
    var tempBEnemy:MovieClip;
    var tempBullet:MovieClip;

    //civil/bullet colision
    civils:for(var i:int=civil.length-1; i>=0; i--)
    {
        tempBCivil = civil[i];
        for (var j:int=bullets.length-1; j>=0; j--)
        {
            tempBullet = bullets[j];
            if (tempBCivil.hitTestObject(tempBullet))
            {
                trace("laser hit the civil");
                makeExplosion (tempBCivil.x, tempBCivil.y);
                removeCivil(i);
                removeBullet(j);
                break civils;
                }
            }
        }

    //enemy/bullet colision
    enemy:for(var k:int=enemy.length-1; k>=0; k--)
    {
        tempBEnemy = enemy[k];
        for (var l:int=bullets.length-1; l>=0; l--)
        {
            tempBullet = bullets[l];
            if (tempBEnemy.hitTestObject(tempBullet))
            {
                trace("bullet hit the Enemy");
                makeExplosion (tempBEnemy.x, tempBEnemy.y);
                removeEnemy(k);
                removeBullet(l);
                break enemy;
                }
            }
        }
    }

function makeExplosion(ex:Number, ey:Number):void
{
    var tempExplosion:MovieClip;
    tempExplosion = new boom();
    tempExplosion.x = ex;
    tempExplosion.y = ey;
    addChild(tempExplosion)
    explosions.push(tempExplosion);
    }

function makeBEnemy():void
{
    //random chance
    var chance:Number = Math.floor(Math.random()*BCRand);
    if (chance <= 1 + level) 
    {
        var tempBEnemy:MovieClip;
        //generate enemies
        tempBEnemy = new BEnemy();
        tempBEnemy.speed = BCSpeed;
        tempBEnemy.x = Math.round(Math.random()*800);

        addChild(tempBEnemy);
        enemy.push(tempBEnemy);
        }

    }

function moveBEnemy():void
{
    //move enemies
    var tempBEnemy:MovieClip;
    for(var i:int = enemy.length-1; i>=0; i--)
    {
        tempBEnemy = enemy[i];
        tempBEnemy.y += tempBEnemy.speed
        }

    //testion colision with the player and screen out
    if (tempBEnemy.y > stage.stageHeight /* || tempBCivil.hitTestObject(player) */)
    {
        trace("enemy");
        //makeExplosion (player.x, player.y);
        removeEnemy(i);
        //gameState = STATE_END;
        }
    }

function vhDrops():void
{}

function testForEnd():void
{
    //check damage


    //end game
    //gameState = STATE_END;
    trace(gameState);
    }

/*--------------------REMOVING BS FROM STAGE-----------------------*/
//removing civils
function removeCivil(idx:int):void 
{
    if(idx >= 0)
    {
        removeChild(civil[idx]);
        civil.splice(idx, 1);
        }
    }

//removing enemies
function removeEnemy(idx:int):void 
{
    if(idx >= 0)
    {
        removeChild(enemy[idx]);
        enemy.splice(idx, 1);
        }
    }

//removing civils
function removeBullet(idx:int):void 
{
    if(idx >= 0)
    {
        removeChild(bullets[idx]);
        bullets.splice(idx, 1);
        }
    }

//removing expired explosions
function removeExEplosions():void 
{
    var tempExplosion:MovieClip;
    for(var i=explosions.length-1; i>=0; i--)
    {
        tempExplosion = explosions[i];
        if (tempExplosion.currentFrame >= tempExplosion.totalFrames)
        {
            removeExplosion(i);
            }
        }
    }

//removing civils
function removeExplosion(idx:int):void 
{
    if(idx >= 0)
    {
        removeChild(explosions[idx]);
        explosions.splice(idx, 1);
        }
    }



/*--------------------------STATE_END------------------------------*/

function endGame():void
{

    }


/*gameScreen*/

/*endScreen*/

而且我确定这里还有其他一些错误的代码,但这并不重要。

设置为 AS 和 AS 链接的导出:http: //i.stack.imgur.com/UvMAt.png

编辑:删除了第二个 var 声明,仍然得到同样的错误。

4

1 回答 1

0

如果您提供更多代码和解释,那就太好了,但是在这里我发现了 1046 :“您会收到此错误的一个原因是,如果您在舞台上有一个与您的库中的对象同名的对象。”

看看:http ://curtismorley.com/2007/06/20/flash-cs3-flex-2-as3-error-1046/

您是否在网上搜索过代码 1046 的任何解释?你检查过这个吗?

我看到你有两个var mp声明。尝试删除第一个,var mp:MovieClip;. 如果它不起作用,请仔细检查您的 Flash 库,确保该MP_00名称可用。如果它是一个影片剪辑,请检查它是否为 ActionScript 导出。如果是实例名称,请检查它是否没有被使用过两次。

编辑。

我的建议是:

1-将所有引用更改mpmp1。可能与实例“...舞台上的对象与库中的对象同名”存在冲突。

2-var mp1:MP_00;而不是var mp:MovieClip;在声明部分。

3- 把mp1 = new MP_00();后面放在 startGame() 函数中

4-确保您的新mp1变量无处不在,并且您没有更多的参考。为mp变量。

如果……还是不行。我建议:更改您的 MovieClip 链接的名称,likeTestA或其他。是的,我知道,对一切都有疑问,但没有魔法,测试一切肯定会显示问题。

编辑。

对于mapMove()功能...

首先:确保该speedUp()函数可用,而不是在注释中,并在您的playGame()函数中调用它。您的playerSpeed变量必须有一个值,因此请更改 : var playerSpeed = playerSpeed + 1;for playerSpeed = playerSpeed + 1;。不要var对同一个变量使用两次声明。(见var playerSpeed:Number;头文件。)

此外...您必须知道MP_00舞台上的剪辑是否是您的mp1剪辑。(我假设您发布了您拥有的所有代码。)

案例 A :MP_00在您开始剪辑时在舞台上。

如果你真的MP_00在屏幕上看到你的,那意味着你不必做mp1 = new MP_00();and addchild(mp1);。它已经为您完成了(从库中拖动一个剪辑并给出一个名称实例,与执行newand相同addchild)。

找到实例名称(或给出一个)。您应该获取您的实例名称并移动您的对象(这里的实例名称是mp1):

mp1.y = mp1.y - playerSpeed;

案例 B:MP_00当您开始剪辑时不在舞台上。

做:1-您的声明:var mp1:MP_00; 2-分配内存:mp1 = new MP_00(); 3-添加到显示列表:addchild(mp1); 4-“摇动它 bb”:mp1.y = mp1.y - playerSpeed;mp1.y -= playerSpeed;

我不知道你的知识水平到底是多少,所以我试着把所有的东西都放进去。对不起,如果它太多了。

于 2013-04-14T17:52:26.133 回答