Skip to main content
Participating Frequently
May 14, 2020
Answered

Controlling image size on load to MC

  • May 14, 2020
  • 1 reply
  • 2297 views

Hi,

I am dynamically loading images into a preposoitioned and sized MC.  The image is larger than the MC but same proportions.  What I would like to do is have the image load at the same size as the MC or be scaled to fit it.

 

Currently it comes in at original size and  overflows the MC size.  Is there a setting for the properties of the MC properties that I am missing?

 

I am using this code:

 

var imageID = 'images/small/HF0000_004.jpg';
var p = new createjs.Bitmap(imageID);

//here I want to size the image to the MC

this.addChild(p);

this.play();

 

The code is in the first frame of the MC instance

 

Any help appreciated.

    This topic has been closed for replies.
    Correct answer kglad

    after loading is complete you can use:

     

    p.scaleX = this.mc.getBounds().width/p.getBounds().width ;
    p.scaleY = this.mc.getBounds().height/p.getBounds().height;

    1 reply

    kglad
    Community Expert
    kgladCommunity ExpertCorrect answer
    Community Expert
    May 14, 2020

    after loading is complete you can use:

     

    p.scaleX = this.mc.getBounds().width/p.getBounds().width ;
    p.scaleY = this.mc.getBounds().height/p.getBounds().height;

    Participating Frequently
    May 14, 2020

    Many thanks,

     

    This works perfectly in my test file.  

     

    Many thanks

    kglad
    Community Expert
    Community Expert
    May 15, 2020

    you're welcome.