分数达到一定数量后加载到影片剪辑中

时间:2013-04-17 10:40:32

标签: image actionscript-3 flash loader flash-cs5

我差不多已经完成了我的项目,但是当我尝试加载我的库中的影片剪辑时,我的分数达到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;

        }
    }
}

1 个答案:

答案 0 :(得分:0)

您应该在if(score >= 100)的末尾设置中断,因为这种情况可以在您的for循环中启动几次。您的MovieClip也可以停止,请尝试.play().gotoAndStop() 哦!并设置promotionScreen = stage.stageWidth/2promotionScreen.x = stage.stageWidth/2