0

我几乎完成了我的项目,但是当我尝试在我的库中加载一个电影剪辑时,当我的分数达到 100 时,它会从舞台上删除游戏,但不显示我试图显示的屏幕。

我写的代码如下。任何帮助将不胜感激。

    package 
{

    import flash.display.*;
    import flash.events.*;
    import flash.text.*;
    import flash.utils.Timer;
    import flash.utils.getDefinitionByName;

    public class blast_game extends MovieClip
    {
        // creates a variable that stores the catcher that
        //will be used to collect the chocolate bars.
        var catcher:Catcher;
        var nextObject:Timer;
        var objects:Array = new Array();
        var score:int = 0;
        const speed:Number = 7.0;
        //end of catcher code

        //beginning of game code - spawns a new catcher on screen
        //at start of game.
        public function blast_game()
        {
            catcher = new Catcher();
            catcher.y = 350;
            addChild(catcher);
            setNextObject();
            addEventListener(Event.ENTER_FRAME, moveObjects);
        }
        //end of catcher spawn

        //sets variables for the random object drops, 
        //increments the objects to appear every second.
        public function setNextObject()
        {
            nextObject = new Timer(1000+Math.random()*1000,1);
            nextObject.addEventListener(TimerEvent.TIMER_COMPLETE,newObject);
            nextObject.start();
        }
        //end of object variables


        public function newObject(e:Event)
        {
            //creates an array to hold the "Good" and "Bad" objects in
            //the application.
            var goodObjects:Array = ["Circle1","Circle2"];
            var badObjects:Array = ["Square1","Square2"];
            if (Math.random() < .5)
            {
                //replaces the "good" object when the object hits the floor, places
                //object back in array to drop again.
                var r:int = Math.floor(Math.random() * goodObjects.length);
                var classRef:Class = getDefinitionByName(goodObjects[r]) as Class;
                var newObject:MovieClip = new classRef();
                newObject.typestr = "good";
                //end of "Good" object replacement
            }
            else
            {
                //replaces the "Bad" object when the object hits the floor,    places
                //object back in array to drop again
                r = Math.floor(Math.random() * badObjects.length);
                classRef = getDefinitionByName(badObjects[r]) as Class;
                newObject = new classRef();
                newObject.typestr = "bad";
                //end of "Bad" object replacement
            }
            //randomises the location the objects will be placed on stage
            //after replacement.
            newObject.x = Math.random() * 500;
            addChild(newObject);
            objects.push(newObject);
            setNextObject();
            //end of object randomisation
        }

        public function moveObjects(e:Event)
        {
            for (var i:int=objects.length-1; i>=0; i--)
            {
                //code to increase speed of objects over time.
                objects[i].y +=  speed;
                if (objects[i].y > 400)
                {
                    removeChild(objects[i]);
                    objects.splice(i,1);
                }
                //hit test for catcher - if any object hits the catcher
                //increase or decrease score respectively.
                if (objects[i].hitTestObject(catcher))
                {
                    //increase score when catcher catches "Good" object
                    if (objects[i].typestr == "good")
                    {
                        score +=  10;
                    }
                    else
                    //decrease score if catcher catches "Bad" object.
                    {
                        score -=  5;
                    }
                    //prevents score from going below 0
                    if (score < 0)
                    {
                        score = 0;
                    }
                    scoreDisplay.text = "Score: " + score;
                    //once object hits catcher, remove object from                                                                                              stage.
                    removeChild(objects[i]);
                    objects.splice(i,1);
                }
                //if statement to move screen to promotion screen
                //once score reaches past 100
//THIS IS WHERE I THINK THE ISSUE IS!!!
            if(score >= 100) {
                var promotionScreen:promotion = new promotion;
                //stage.removeChild(this)
                addChild(promotionScreen);
                removeEventListener(Event.ENTER_FRAME, moveObjects);
                promotionScreen = stage.stageWidth / 2;
                promotionScreen = stage.stageHeight /2;


            }
            //end of if statement
            }






            //sets catcher to work with mouse movement.
            catcher.x = mouseX;

        }
    }
}
4

1 回答 1

0

你应该在里面设置breakif(score >= 100)因为这个条件可以在你的 for 循环中启动几次。也MovieClip可以阻止你,所以尝试.play().gotoAndStop() 哦!promotionScreen = stage.stageWidth/2你应该设置promotionScreen.x = stage.stageWidth/2

于 2013-04-17T11:08:57.170 回答