2013-04-17 33 views
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; 

     } 
    } 
} 
+0

你的'升級「課程從哪裏來?你有運行時錯誤嗎?當實例化'promotion'類時,你應該讀'new promotion()' – m90

+0

ive將它改爲new promotion(),但它不起作用 –

回答

0

您應該設置休息內,在if(score >= 100)年底,因爲這種情況下可以啓動幾次在你的for循環。您的MovieClip也可以停止,所以請嘗試.play().gotoAndStop() 哦!並且你設置了promotionScreen = stage.stageWidth/2而你應該promotionScreen.x = stage.stageWidth/2