A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Load random images from library

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    1

    Load random images from library

    Hi I'm a newbie to AS3 so any help is very much appreciated.

    I'm getting the following error when I run this code: Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.

    I'm trying to load images from the library into an array and then load them to the stage randomly when a button is clicked. I have a rough idea of whats going wrong but I've looked everywhere and tried so many different ways that it's messed up now, so please could somebody help me:

    Actionscript Code:
    var Img01:URLRequest=new URLRequest("image1");
    var Img02:URLRequest=new URLRequest("image2");
    var Img03:URLRequest=new URLRequest("image3");

    var imgList1:Array=[Img01, Img02, Img03];

    var imgLoader:Loader = new Loader();
    imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);

    function onComplete(event:Event):void
    {
      var randomImage1:Bitmap = Bitmap(imgLoader1.content);
      imgLoader1.load(randomImage1);
    }

    loadbutton.addEventListener(MouseEvent.CLICK, generate);
    function generate(event:MouseEvent):void
    {
        var imgRandom1 = imgList1[Math.floor(Math.random()* imgList1.length)];
        imgLoader1.load(imgRandom1);
        trace("click");
    }

    Thanks in advance for any help

  2. #2
    You are doing it in the wrong way/ The URL request is for URL links to the images - not to the library. The way you can add image from the library dinamically is this:

    1) Appy ActionScript Linkage to the image - go to the properties of the image, tab Actionscript and check the Export for ActionScript and Export in frame 1 check-boxes.

    2) The text fields Class and Base Class become active. In the Class write : myBitmapData or whatever name you want for your image. In the Base Class should be text flash.display.BitmapData (don`t change this text).Click OK.

    3)The in first frame of your movie write code like this:

    var myBitmapDataObject:myBitmapData = new myBitmapData(100, 100);
    var myImage:Bitmap = new Bitmap(myBitmapDataObject);
    addChild(myImage);

    There you go. The image will be added to the stage. Use this way to load images in your functions.


    Scotty does know how to Fla-make cool ads.

    http://flamake.net - this Ads will Fla-make you crazy. Find your cheap flash banners and see the best commercials around the world.

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