AIR random assets
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: AIR random assets

  1. #1
    Member
    Join Date
    Jun 2004
    Posts
    83

    AIR random assets

    Hi!

    Working on a mobile application (AIR for Android).
    I have a specific class that handles the assets.
    If I load/use "FlowerImageClass2" it's woking fine, but I want to load many differnet assets randomly.

    Basically I want to do something like this in psuedo-code:
    myClass = "FlowerImageClass" + rnd;

    I've tried solutions like this, but it's not working...
    var myClass:Class = new (getDefinitionByName("FlowerImageClass"+rnd)) as Class);


    Part of the code looks like this:
    Code:
    		[Embed(source="../assets/flower1.png")]
    		private var FlowerImageClass1:Class;
    		
    		[Embed(source="../assets/flower2.png")]
    		private var FlowerImageClass2:Class;
    
    		public function Flower(xPos:Number, yPos:Number){
    
    			rnd = Math.random() * 2 + 1;
    
    			bitmap = new FlowerImageClass2 as Bitmap;
    			bitmap.x = xPos - bitmap.width/2;
    			bitmap.y = yPos - bitmap.height/2;
    			addChild(bitmap);
                    }
    I want to try this solution, but if it will be to tricky I can go for another approach..

    Any kind of help will be appreciated.

    -- thanks for in advance
    /S-fish

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,440
    This would work:
    import flash.display.Bitmap;

    [Embed(source = "images/image.png")]
    var FlowerImageClass1:Class;
    var bitmap1:Bitmap = new FlowerImageClass1 as Bitmap;
    [Embed(source = "images/image001.jpeg")]
    var FlowerImageClass2:Class;
    var bitmap2:Bitmap = new FlowerImageClass2 as Bitmap;
    var rnd:Array=new Array(bitmap1,bitmap2);

    var bitmap:Bitmap = rnd[int(Math.random() * 2)] as Bitmap;
    bitmap.x = 100;
    bitmap.y = 100;
    addChild(bitmap);
    - The right of the People to create Flash movies shall not be infringed. -
    | www.Flashscript.biz | Flashscript Biz Classes/Components |

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

Poll by Flashkit.com