Groups | Blog | Home
all groups > flash actionscript > january 2005 >

flash actionscript : loadmovie limitation? how to go around it



Pillow
1/3/2005 10:52:18 PM
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
angrybinary NO[at]SPAM sbcglobal.net
1/3/2005 11:40:03 PM
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]

Zerodonor
1/4/2005 1:29:52 PM
Hi

Add the following to the bgHolder mc:



onClipEvent (data) {
trace(this._width);
Duke Boyne
1/4/2005 3:55:06 PM
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

Pillow
1/4/2005 6:55:35 PM
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
Duke Boyne
1/4/2005 7:56:59 PM
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);
Pillow
1/4/2005 9:07:32 PM
Duke Boyne
1/4/2005 10:17:47 PM
NSurveyor
1/4/2005 10:32:53 PM
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;
}
}
Duke Boyne
1/4/2005 10:36:29 PM
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);
Duke Boyne
1/4/2005 10:39:09 PM
The business it sthe last line of code. Change yourFilename.jpg to whatever yours is...

NSurveyor
1/4/2005 10:43:24 PM
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;
}
Duke Boyne
1/4/2005 11:02:50 PM
NSurveyor
1/4/2005 11:16:47 PM
Rothrock
1/4/2005 11:25:11 PM
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.
Pillow
1/4/2005 11:29:38 PM
Thanks guys....thank you so much~
NSurveyor
1/4/2005 11:35:18 PM
AddThis Social Bookmark Button