PDA

View Full Version : loading image inside of movieclip


RussellReal
11-08-2009, 02:21 AM
how would I LOAD an image.. into a movieclip.. then resize the movieclip to the size of the image..

now I know how to put the image inside of the movieclip with addChild(), but then when I try to resize the movieclip to the size of the IMAGE, it changes the size of the image inside the movieclip.. now I know that when a movieclip scales so does everything else.. so my question is.. how to go about modifying this to make it work no matter what

basically I have a editor so to speak and when you drag the blips it will resize it.. but the problem is actually LOADING the image into the movieclip because once it is same width/height as the movieclip (and shows that way on the screen) my script will handle it perfectly. is there a trick to this.. here is the code I've got so far..

function dispatch(e:Event):void {
this.removeChildAt(2);
var l:LoaderInfo = imageLoader.contentLoaderInfo;
var sizes:Array = alter_image_sizes(l.width,l.height,this.parent.par ent.width,this.parent.parent.height);
this.addChildAt(imageLoader,2);
this.width = sizes[0];
this.height = sizes[1];
this.getChildAt(2).width = this.width * this.scaleX;
this.getChildAt(2).height = this.height * this.scaleY;
MovieClip(this.parent).applyBorder();
}
the loader can change so I remove it from the movieclip when the dispatch function gets called, imageLoader is the loader which loads the image.. sizes just returns either max sized resized proportions or regular height of the image.. note "this" or rather the element I'm using is by default 100x100.

also notice I tried using scaleX and scaleY but I've tried it without and still no luck. please help! Thanks <3

nyghtrunner
11-08-2009, 06:20 AM
For starters, I wouldn't add the imageLoader as a child like that. Make a "holder" clip, and add the imageLoader to that, via:

holder = MovieClip(imageLoader.content);

Then setting the height/width should be as simple as:

holder.height = this.height; //depending on what "this" is.
holder.width = this.width;


If for some reason that doesn't work, another way to do it would be to calculate the difference, and use that to get a scaleFactor, and scale the "holder", like so:


var newScaleX:Number = this.width/holder.width;
var newScaleY:Number = this.height/holder.height;
holder.scaleX = newScaleX;
holder.scaleY = newScaleY;

But again... That depends on what the "this' is referring to. You might want to try tracing "this.width" just to see what that returns. You should know right away if it's correct.

RussellReal
11-08-2009, 02:48 PM
Okay I've tried all of your examples, #1 MovieClip() can't take a Loader as an argument.. the container sizes right.. I did traces and the image I'm trying to load is 130x86 and it resizes correctly, but when I add my image to the container and set the loader to 130x86 and run a trace it says the image is 169x86?? lol wtf

Greg SS
11-09-2009, 02:51 AM
What you have to remember is that the width and height of a movieclip is a computed number, obtained by multiplying the real width and height by the X and Y scale.

So say you have a movieclip holder, you place a 100 x 200 bitmap into that, you scale the movieclip to 100 x 100, remove the bitmap and put a 100 x 400 bitmap in the movieclip.
The result is a movieclip with 100 width and 200 height. Why?

Because when you scale the holder the first time, you effectively setting its scaleX to 1, and scaleY to 0.5 (100 is half of 200), and when you put in the second bitmap, it inherits the holder scale, scaling its height by 0.5.