Avatar billede jadirir Nybegynder
31. juli 2004 - 20:07 Der er 6 kommentarer

Image size and movieclip?

I load an image in a movieclip, the image size is grater than the moveclip, so how can I specify the image size should fit the moveclip without modifying the image?
Thanks
Avatar billede pyroman Nybegynder
01. august 2004 - 10:40 #1
You should load the image in a seperate movieclip in your first movieclip. When the image is fully loadet, you can specify the size of the movieclip with its normal properties.
Your code could look like this:


function loadImage(file, name, depth, width, height){
  var img = this.createEmptyMovieClip(name, depth);
  img.loadMovie(file);
  var handler = new Object();
  handler.onEnterFrame = function(){
    if(img.getBytesLoaded() == img.getBytesTotal() && img.getBytesTotal() > 0){
      img._width = width;
      img._height = height;
      delete this;
    }
  }
}


Then you can use this function in your movieclip like in this example:


loadImage("landscape.jpg", "myImg", 1, 300, 200);
Avatar billede jadirir Nybegynder
01. august 2004 - 23:15 #2
I do not want to use so much code. My aim is to hit a button and load the image in a movieclip such that the  image size should not be bigger than the mc size:
on (release) {
    _root.picture.loadMovie("myimage.jpg");
}
Unless otherwise Thanks for your effort:
Avatar billede jadirir Nybegynder
01. august 2004 - 23:16 #3
I do not want to use so much code. My aim is to hit a button and load the image in a movieclip such that the  image size should not be bigger than the mc size:
on (release) {
    _root.picture.loadMovie("myimage.jpg");
}
Unless otherwise Thanks for your effort:
Avatar billede pyroman Nybegynder
01. august 2004 - 23:43 #4
Of cause you can't just use loadMovie("myimage.jpg"); - that's the problem...
loadMovie() can't do it all for you, thats why you should define your own method that does what you want - that's the point in programming!

Escuse me saying this - but I just can't see why you changed your mind, just because the solution is a few lines of code....

But ok - no problem :)
Avatar billede jadirir Nybegynder
02. august 2004 - 21:44 #5
Even if I use the suggested code, the image size does not change at all. If I call the method as: loadImage("landscape.jpg", "myImg", 1, 100, 50); gives the original image size.
I use the code in the on release() {.....} statement of a button.
Thanks for your reply
Avatar billede jadirir Nybegynder
02. august 2004 - 21:45 #6
does not works still
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
IT-kurser om Microsoft 365, sikkerhed, personlig vækst, udvikling, digital markedsføring, grafisk design, SAP og forretningsanalyse.

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester