A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: how to put 10 different dishes (loaders) in a random sequence?

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    1

    how to put 10 different dishes (loaders) in a random sequence?

    Hello im with a doubt and need your help if its possible.
    I have a class dish and i load 1 file ".swf", and i have a little game that works like this:
    The dish moves in the x and y axis and i when i click in the dish it falls down.
    But i want to have not only 1 dish i want have 10 different dishes with diferent images. And i want that they appear in a random sequence. But i dont have ideia how i cant do that...someone can give me "light"?
    My class "dish" is like this at the moment:


    package {

    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 load_dish:Loader = new Loader();
    var path:URLRequest = new URLRequest("dish.swf");
    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;


    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() ));
    }
    }

  2. #2
    Senior Member
    Join Date
    Nov 2001
    Posts
    1,145
    You can make 10 dish images. If they're external images (jpg), load them when the flash loads.

    A dish object can have any one of the images. So when you create a dish, you select an image, load it, and show it.

    You can use an array of objects (for this and everything). Here's some general code:

    Code:
    myDishes = new Array();
    myDish:Object = new Object();
    myDish.imageNumber = i;
    var picRequest:URLRequest = new URLRequest(imageURLs[i]);
    var picLoader:Loader = new Loader();	
    picLoader.load(picRequest);	
    myDish.holder.addChild(picLoader);
    
    myDishes.push(myDish);
    This way you have a natural set of dishes - myDishes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center