我正在開發一款小遊戲,並取得了一些成功。 我遇到了一些問題,並設法解決它們(我認爲),但這一個困擾着我。 遊戲正在工作,但它引發了上面的錯誤,我想解決。 任何人都可以提供任何建議如何解決這個問題? 我相信這是這條線(因爲當我發表評論時,錯誤不會發生),但花了最近兩個小時試圖用各種方式解決它,沒有喜樂。如何解決「類型錯誤#2007參數子必須非空」?
for (var i:int = 0;i <=20;i++)
{
addToys(1200 * Math.random(), 200 * Math.random() * 2);
}
如果有人能指出方式會有很大幫助。 我嘗試了谷歌搜索,但我的腦海裏試圖這樣做。 我錯過了什麼?
難道問題是我在時間軸上有兩層包含動畫? (我只是這樣做,因爲我不知道如何通過動作單獨添加它們)。
我附上了下面的完整代碼。請記住,我仍在學習,所以請溫柔。 :d
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
public class MyGame extends MovieClip {
public function MyGame() {
const BG_SPEED:int = 5;
const BG_MIN:int = -550;
const BG_MAX:int = 0;
var bg:BackGround = new BackGround;
var toy1:Toy1 = new Toy1;
var toy2:Toy2 = new Toy2;
var toy3:Toy3 = new Toy3;
var toy4:Toy4 = new Toy4;
var toy5:Toy5 = new Toy5;
var toy6:Toy6 = new Toy6;
var toy7:Toy7 = new Toy7;
var toy8:Toy8 = new Toy8;
var toy9:Toy9 = new Toy9;
var toy10:Toy10 = new Toy10;
var toy11:Toy11 = new Toy11;
var toy12:Toy12 = new Toy12;
var toy13:Toy13 = new Toy13;
var toy14:Toy14 = new Toy14;
var toy15:Toy15 = new Toy15;
var toy16:Toy16 = new Toy16;
var toy17:Toy17 = new Toy17;
var toy18:Toy18 = new Toy18;
var toy19:Toy19 = new Toy19;
var toy20:Toy20 = new Toy20;
var toyArray:Array = new Array();
toyArray.push(toy1);
toyArray.push(toy2);
toyArray.push(toy3);
toyArray.push(toy4);
toyArray.push(toy5);
toyArray.push(toy6);
toyArray.push(toy7);
toyArray.push(toy8);
toyArray.push(toy9);
toyArray.push(toy10);
toyArray.push(toy11);
toyArray.push(toy12);
toyArray.push(toy13);
toyArray.push(toy14);
toyArray.push(toy15);
toyArray.push(toy16);
toyArray.push(toy17);
toyArray.push(toy18);
toyArray.push(toy19);
toyArray.push(toy20);
addChildAt(bg, 0);
stage.addEventListener(Event.ENTER_FRAME, bgScroll);
function addToys(xpos, ypos)
{
addChild(toyArray[i]);
toyArray[i].x = xpos;
toyArray[i].y = ypos;
}
for (var i:int = 0;i <=20;i++)
{
addToys(1200 * Math.random(), 200 * Math.random() * 2);
}
function bgScroll (e:Event)
{
if (stage.mouseX > 600 && bg.x > BG_MIN)
{
bg.x -= BG_SPEED;
for (var i:int=0; i< toyArray.length; i++)
{
(toyArray[i] as MovieClip).x -=BG_SPEED
}
}
else if (stage.mouseX < 50 && bg.x < BG_MAX)
{
bg.x += BG_SPEED;
for (var j:int=0; j< toyArray.length; j++)
{
(toyArray[j] as MovieClip).x +=BG_SPEED
}
}
}
}
}
}
任何幫助將不勝感激。
你嘗試改變「爲」從「我<= 20」到「I <20條件「? – Crabar 2014-12-02 15:24:38
我也嘗試過,它也可以。謝謝。我一直忘記,一切從零開始,不是1! – ZombieDude 2014-12-08 11:37:47