AS3无法识别MovieClip - 1046:未找到类型或不是编译时常量:MP_00

时间:2013-04-14 15:31:59

标签: actionscript-3 flash-cs6

所以我是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设置为播放器,并且可以正常工作。

这一切都在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声明,仍然得到相同的错误。

1 个答案:

答案 0 :(得分:0)

如果你提供更多的代码和解释会很棒,但在这里我发现1046: “你会得到这个错误的一个原因是你在舞台上有一个与你库中的对象同名的对象。”

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

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

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

EDIT。

我的建议是:

1-将mp的所有引用更改为mp1。也许与实例“......舞台上的对象与库中的对象同名”存在冲突。

声明部分中的

2- var mp1:MP_00;而不是var mp:MovieClip;

3-将mp1 = new MP_00();放回startGame()函数

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

如果......它仍然不起作用。我建议:更改MovieClip链接的名称,例如TestA或其他。是的,我知道,对所有事情都有疑问,但没有魔力,测试一切都会肯定会显示问题。

EDIT。

对于mapMove()功能......

首先:确保speedUp()功能可用,而不是在评论中,并在playGame()功能中调用它。您的playerSpeed变量必须具有值,因此更改var playerSpeed = playerSpeed + 1; playerSpeed = playerSpeed + 1;。不要对同一个变量使用var两次声明。 (请参阅头文件中的var playerSpeed:Number;。)

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

案例A:MP_00在您启动剪辑时处于舞台上。

如果您在屏幕上看到了MP_00,则表示您不必执行mp1 = new MP_00();addchild(mp1);。它已经为您完成了(从库中拖动剪辑并提供名称实例,与执行newaddchild)相同。

找到实例名称(或给出一个)。您应该获取实例名称并移动对象(此处实例名称为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;

我完全不知道你的知识水平是什么,所以我试着把所有东西都放进去。对不起,如果太多了。