here is my script, very simple, load in a jpg and scale it...how to do it? the jpg will be different size all the time. I want to load those jpg in movie and scale them all to the same size. But after the using loadmovie to load jpg in, i can't determine the width or height of the jpg.... bgHolder.loadMovie('imageName.jpg', 5); trace ('bgHolder._width: ' + bgHolder._width); // give me 0, the same with height. anyone can help? thanks lincoln
Before you trace back the _width, you have to make sure the image has loaded. Put the trace functions in an onLoad handler: bgHolder.loadMovie('imageName.jpg', 5); bgHolder.onLoad = function(ok){ if(ok) { trace ("bgHolder._width: " + bgHolder._width); } else { trace(#@$%!); } } angry1010011010 [quoted text, click to view] "Pillow" <webforumsuser@macromedia.com> wrote in message news:crcib2$8qu$1@forums.macromedia.com... > here is my script, very simple, load in a jpg and scale it...how to do it? > the > jpg will be different size all the time. I want to load those jpg in movie > and > scale them all to the same size. But after the using loadmovie to load jpg > in, > i can't determine the width or height of the jpg.... > bgHolder.loadMovie('imageName.jpg', 5); trace ('bgHolder._width: ' + > bgHolder._width); // give me 0, the same with height. anyone can help? > thanks > lincoln >
Hi Add the following to the bgHolder mc: onClipEvent (data) { trace(this._width);
Lincoln (Great They Might be Giants Album), Your problem is a simple one. When you load a jpg into a movieClip, that clip no longer behaves like a movie clip. It is now considered a jpg by Flash. So do this: wrapper_mc = bgHolder.createEmptyMovieClip("wrapper", 1) wrapper_mc.loadMovie("imageName.jpg", 5); trace ("bgHolder._width: " + bgHolder._width); You can now control the jpg using the MovieClip bgHolder, but the jpg is actually nested in bgHolder inside of the jpg formerly known as MovieClip called "wrapper_mc" (or bgHolder .wrapper) Yours, Duke
Thank you in advance, But I tried both solution and it still doesn't work How about please put down the code here for me to do a dynamic JPG load in and scale all JPG to the same resolution say 150 x 105. How to do? -------------------------------------my code ---------------------------------- function loadImg () { logoHolder.loadMovie(logoArray[count], 5); // logoArray[count] has all the image file name logoHolder._width = 150; logoHolder._height = 105; //set width and height of the logoHolder } -----------------------------------end--------------------------------- please let me know why my code doesn't work. Thx
Pillow, If you are loading a JPG into logoHolder, logoHolder will no longer be a movieClip. So you won't be able to set or read properties from logoHolder. You need to create a "wrapper" inside of logoHolder, then load the JPG into the wrapper. Then you may modify logoHolder because it is still a movieClip. The "wrapper will no longer be a movieClip,m it will be a JPG, so you can't touch it anymore. Look at my code in the above post. wrapper_mc = logoHolder.createEmptyMovieClip("wrapper", 1) wrapper_mc.loadMovie("imageName.jpg", 1); trace ("logoHolder._width: " + logoHolder._width);
You are wrong. The problem occurs because you have to wait for flash to load the content and then you can find out it's width and height. So, all you need to do, is make flash wait until the image is completely loaded. You can do something as simple as: bgHolder.loadMovie("imageName.jpg", 5); onEnterFrame = function(){ if(bgHolder._width!=0){ trace ("bgHolder._width: " + bgHolder._width); delete onEnterFrame; } }
Try this. It should handle everything. It's using thje very powerful MoviClipLoaderClass. Drop this code in the first frame of a movie and change the filename of the JPG. var jpgHolder_mc = createEmptyMovieClip("wrapper", 1); // var my_mcl = new MovieClipLoader(); var myListener = new Object(); myListener.onLoadStart = function(target_mc) { //you may ignore this unless you want something to happen at load start }; myListener.onLoadProgress = function(target_mc, loadedBytes, totalBytes) { //you may ignore this unless you want to track the load progress }; myListener.onLoadComplete = function(target_mc) { //you may ignore this unless you want to do something RIGHT before the image is initialized }; myListener.onLoadInit = function(target_mc) { trace("target_mc._width: "+target_mc._width); //look you can modify the image here target_mc._xscale = 50 }; myListener.onLoadError = function(target_mc, errorCode) { //you may ignore this unless you want to handle an error }; my_mcl.addListener(myListener); my_mcl.loadClip("yourFilename.jpg", jpgHolder_mc);
The business it sthe last line of code. Change yourFilename.jpg to whatever yours is...
Duke, loadMovie only loads the specified file inside of the specified location. For example, the following code definitely shows that someMC is still an mc after loading an image: createEmptyMovieClip('someMC',1); someMC.loadMovie('someJPEG.jpg'); someMC.onEnterFrame = function(){ someMC._xscale = someMC._yscale = Math.random()*100; someMC._x = _xmouse; someMC._y = _ymouse; }
If you are using MX04, check out the MovieClipLoader class. In the help files you will see there is an onLoadInit event handler. Inside that handler you can set the width and the height to whatever you want. Works like a charm.
Thanks guys....thank you so much~
Don't see what you're looking for? Try a search.
|