A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: images in array

  1. #1
    Junior Member
    Join Date
    Jul 2007
    Posts
    3

    images in array

    Hi,

    I am new to AS3 and FLEX.

    here is my code:

    public var FloorImage:Array = ["1.png","2.png","3.png","4.png","4.png"];

    now the images are stored in the array. say, i want to use image 1.png to draw on the screen by using the bitmap and bitmapdata components.
    how would i go about it?

    thank.

    JJ

  2. #2
    Senior Member
    Join Date
    Dec 2005
    Location
    No where
    Posts
    105
    right now, that array is just an array of strings, not an array of images. What you have to do is load those images from external files. If you were using air it would be pretty simple, but to do it in either air or flex 2.0 (i put your current array in floorImagesURLs and the loaded images will go in floorImages):
    code:

    import flash.display.Loader;
    import flash.display.Bitmap;
    import flash.net.URLRequest;
    import flash.events.Event;

    public var floorImagesURLs:Array = ["1.png","2.png","3.png","4.png","4.png"];
    public var floorImages:Array = [];
    public var doneLoading:Boolean = false;

    private var loader:Loader;
    public function loadFloorImages():void{
    loader = new Loader();
    loader.load(new URLRequest(String(floorImagesURLs[0])));
    loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, loadNext);
    }
    private function loadNext(e:Event):void{
    floorImages.push(loader.content as Bitmap);

    if(floorImages.length == floorImagesURLs.length) {
    doneLoading = true;
    return;
    }

    loader = new Loader();
    loader.load(new URLRequest(String(floorImagesURLs[(floorImages.length-1)])));
    loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, loadNext);
    }



    a bit messy, but it should work, just call loadFloorImages() and then when doneLoading == true, you can use the images from floorImages.

    Then to use those images as bitmaps: if you want to use 1.png, you would simply use floorImages[0], 2.png is floorImages[1], etc..

    EDIT: I dont know why, but flashkit keeps putting spaces in Event.COMPLETE. There shouldnt be any there.
    Last edited by ck_drknes; 07-07-2007 at 12:21 PM.

  3. #3
    Junior Member
    Join Date
    Jul 2007
    Posts
    3
    hi, ck_drknes, thanks for the reply. i am going to try now. really appreciate it.

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