0

I have a series of banners (standard sizes) which all need to load the same corresponding image for each slide. I can load them fine but I want the image to match the size of the container MC that the image is being loaded to, is that possible? Either that or to set the height/width manually...

Everything I have tried doesnt work, here is the code for the working state (where it just loads the image which stretches across the stage)

Code:

var myImage:String = dynamicContent.Profile[0].propImage.Url;

function myImageLoader(file:String, x:Number, y:Number):StudioLoader{
    var myImageLoader:StudioLoader = new StudioLoader();
    var request:URLRequest = new URLRequest(file);
    myImageLoader.load(request);
    myImageLoader.x = -52;
    myImageLoader.y =-30;   
   return myImageLoader;
}


propImage1.addChild(loadImage(enabler.getUrl(myImage),-20,0));
Dave
  • 108
  • 2
  • 15

1 Answers1

1

You can resize your loaded image after the Event.COMPLETE on the LoaderInfo (contentLoaderInfo) of your URLLoader is fired, so you can do like this :

var request:URLRequest = new URLRequest('http://www.example.com/image.jpg');
var loader:Loader = new Loader();   
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, on_loadComplete);
    function on_loadComplete(e:Event):void {
        var image:DisplayObject = loader.content;       
            image.x = 100;
            image.y = 100;
            image.width = 300;
            image.height = 200;
        addChild(image);        
    }
    loader.load(request);

Edit :

load_image('http://www.example.com/image.jpg');

function load_image(url){
    var request:URLRequest = new URLRequest(url);
    var loader:Loader = new Loader();   
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, on_loadComplete);
        function on_loadComplete(e:Event):void {
            add_image(loader.content);
        }
        loader.load(request);
}
function add_image(image:DisplayObject, _x:int = 0, _y:int = 0, _width:int = 100, _height:int = 100){
    image.x = _x;
    image.y = _y;
    image.width = _width;
    image.height = _height;
    addChild(image);    
}

Hope that can help.

akmozo
  • 9,829
  • 3
  • 28
  • 44
  • Thanks for your reply, i've tried to implement your suggestion but get errors - could you do it matching with my code? Unless i'm missing something... I've been working on this for the last 10hours ad my brains a bit fried! Thank you in advance – Dave Mar 16 '15 at 08:44
  • @Dave Firstly, try my code with any image url, and then adapt it to your code. – akmozo Mar 16 '15 at 08:48
  • Hmm, can't get it to work. See this earlier q for the full set up: http://stackoverflow.com/questions/27580023/loading-more-than-one-child-image-as3 – Dave Mar 16 '15 at 13:37