感謝的答案! 所以我不能在同一個「瑞士法郎」的所有菜餚? 我需要創建儘可能多的swf? 我的類菜是這樣直到如今 我沒有其他辦法可以做到這一點(只有包含所有菜餚的SWF)
包{
import flash.events.Event;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.MouseEvent;
public class Dishe {
var velX: int;
var velY: int ;
var game:Game; //i have also a class game to control everyting
var broken_dish:URLRequest = new URLRequest("broken_dish.swf");
var gravity:int = 2;
var dishFilenames:Array = [ 'dish.swf','second_dish.swf'];
var randomIndex:int = Math.random() * dishFilenames.length;
var filename:String = dishFilenames[randomIndex];
var load_dish:Loader = new Loader();
var path:URLRequest = new URLRequest(filename);
public function Dishe(e:Game, vX:int, vY:int)
{
velX = vX;
velY = vY;
load_dish.x = -180;
load_dish.y = randomBetween(250,-5);
load_dish.load(caminho);
game = e;
game.myStage.addChild(load_dishe);
load_dish.addEventListener(MouseEvent.CLICK, _shoot);
}
public function broken_dish(e:Event)
{
velY += gravity;
load_dish.y +=velY ;
if(load_dish.y >= game.myStage.stageHeight)
{
game.game_states(Game.state_playing);
}
}
public function _enterFrame(e:Event):void
{
if(load_dish.content!=null)
{
load_dish.x += velX;
load_dish.y += velY *(1 - (load_dish.x/game.myStage.stageWidth) * 2);
if(load_dish.x > game.myStage.stageWidth)
{
load_dish.y = randomBetween(250,-5);
load_dish.x = -180;
}
}
}
public function _shoot(e:MouseEvent):void
{
trace("nice!!");
game.game_states(Game.state_stop);
load_dishe.load(broken_dish);
}
function randomBetween(a:int, b:int) : int {
return a + int(Math.round((b-a)*Math.random()));
}
}
}
我試試嗎?但不工作!我試過這個代碼,但總是出現同一道菜! – OzzC
應該工作得很好,你不能在你現有的代碼中錯誤地複製或者有其他問題。只要你有一個多個獨特的文件名數組,這應該工作得很好。 – prototypical
感謝您的回答...我將您的代碼調整爲適合我的工作,但會發生什麼情況是randomIndex結果總是相同,所以我總是在第一個([0])位置上放置相同的菜餚! – OzzC