AIR random assets
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: AIR random assets

  1. #1
    Join Date
    Jun 2004

    AIR random assets


    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:
    		private var FlowerImageClass1:Class;
    		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;
    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

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    press the picture...
    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;
    - The right of the People to create Flash movies shall not be infringed. -
    | | 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