TypeError:错误#1010:术语未定义且没有属性。在MineAssign / NukesExplode()

时间:2015-10-29 16:34:07

标签: actionscript-3 actionscript

我遇到了这个功能的问题,“NukesExplode”。单击一个nuke时,它会被删除并被explodeArray中的元素替换。相反,当我点击它时,我收到一个输出错误(标题),它只是消失了。

package {
import flash.display.MovieClip;//allows custom images to be used
import flash.text.TextField;//allows textfields to be used
import flash.events.MouseEvent;//allows buttons and other mouse events to be used
import flash.utils.Timer;//allows timers to be used
import flash.events.TimerEvent;//allows timers to interact with other variables and custom events
import flash.display.Sprite; //allows listener events to take place
import flash.events.Event; //allows events to be invoked and take place
import flash.media.Sound;//allows sound to be used and played
import flash.net.URLRequest;//allows the playing of sounds from the library
public class MineAssign extends MovieClip {//class

    public function MineAssign(){//constructor
        TitleScreen();
    }//End of Constructor

    public function TitleScreen(){//adds a Title Screen
        var tsBackground:tsBack= new tsBack();
        tsBackground.x= -22
        tsBackground.width=650
        tsBackground.height=450
        addChild(tsBackground);

        var mainTheme:tsTheme = new tsTheme(); 
        mainTheme.addEventListener(Event.COMPLETE, CompleteHandler); 
        function CompleteHandler(event:TimerEvent){
        }
        mainTheme.play();

        var counter = 0;
        var myTimer:Timer = new Timer(5000);
        myTimer.addEventListener(TimerEvent.TIMER, TimerFunction)
        function TimerFunction(event:TimerEvent){
            counter++
            removeChild(tsBackground);
            AddStuff();

            myTimer.stop();
        }
        myTimer.start();

    }//end of TitleScreen

    public function AddStuff(){//adds the game

        var mapBack:Map = new Map();
        mapBack.width= 550
        mapBack.height= 400
        mapBack.x= 25
        addChild(mapBack);

        var gameLogo:Logo = new Logo();
        gameLogo.x=25
        gameLogo.y=0
        addChild(gameLogo);

        var subLogo:SubLogo = new SubLogo();
        subLogo.y=45
        subLogo.x=25
        addChild(subLogo);

        var inputFieldOne:TextField= new TextField
        inputFieldOne.y= 400
        inputFieldOne.x= 25
        inputFieldOne.width= 150
        inputFieldOne.text= "Number of Nukes:"
        inputFieldOne.height= 25
        inputFieldOne.border= true
        inputFieldOne.restrict= "0-9"
        addChild(inputFieldOne)

        var inputFieldOneTwo:TextField= new TextField
        inputFieldOneTwo.y= 400
        inputFieldOneTwo.x= 120
        inputFieldOneTwo.width= 50
        inputFieldOneTwo.height= 25
        inputFieldOneTwo.type= "input"
        inputFieldOneTwo.restrict= "0-9"
        inputFieldOneTwo.maxChars=  2
        addChild(inputFieldOneTwo)

        var inputFieldTwo:TextField= new TextField
        inputFieldTwo.y= 425
        inputFieldTwo.x= 25
        inputFieldTwo.width= 150
        inputFieldTwo.height= 23
        inputFieldTwo.border= true
        inputFieldTwo.text= "Click me to drop some nukes!"
        addChild(inputFieldTwo)

        inputFieldTwo.addEventListener(MouseEvent.CLICK, ClickButton2); 
        function ClickButton2(event:MouseEvent) {
            DropNukes(inputFieldOneTwo);
        }

    }//end of AddStuff

    public var theNukes:Array= new Array();
    public var textnum:Number;
    public var explodeArray:Array= new Array();

    public function DropNukes(inputFieldOneTwo){//function that deals with the myNuke array

        textnum= Number(inputFieldOneTwo.text);

        for(var i:int; i < textnum; i++){
            theNukes.push(new myNuke());
            theNukes[i].addEventListener(MouseEvent.CLICK, NukesExplode);
            theNukes[i].x= Math.random()*370+50;
            theNukes[i].y= Math.random()*370-50;
            theNukes[i].rotation= Math.random()*360
            addChild(theNukes[i]);
        }
    }//end of DropNukes

    public function NukesExplode(event:MouseEvent){//function that makes the nukes explode when clicked and calculates the distances to the closest mine

        var clicked:int = theNukes.indexOf(event.currentTarget)
        removeChild(theNukes[clicked]);
        theNukes.splice(clicked, 1);

        for(var i:int; i < textnum; i++){
            theNukes.push(new blownUp());
            explodeArray[i].height= 70;
            explodeArray[i].width= 70;

            if(event.currentTarget == theNukes[i]){//If a nuke is clicked, remove it and replace it with the explode array
                theNukes.splice(i, 0);
                removeChild(theNukes[i]);
                addChild(explodeArray[i]);
                explodeArray[i].x= theNukes[i].x;
                explodeArray[i].y= theNukes[i].y;
            }//End of If Statement
        }//End of For Loop
    }//end of NukesExplode

}//end of class

} //包裹的结尾

1 个答案:

答案 0 :(得分:0)

如果您可以告诉我们有关抛出错误的特定行(可能需要为其安装Debug Flash Player),那将会很棒。

但是,从我看到的情况来看,我建议尝试评论最后的if语句:

if(event.currentTarget == theNukes[i]){//If a nuke is clicked, remove it and replace it with the explode array
theNukes.splice(i, 0);
removeChild(theNukes[i]);
addChild(explodeArray[i]);
explodeArray[i].x= theNukes[i].x;
explodeArray[i].y= theNukes[i].y;

}

因为,首先,看起来条件不会给出真实,因为你已经从上面的Nukes数组中删除了event.currentTarget。