PDA

View Full Version : JPG dimensions after loading


jcanistrum
02-27-2006, 09:47 PM
I´m loading a JPG image into an empty movie clip as an Holder.

I want to scale the JPG to the Holder´s size.

Loading is not a problem, scaling neither, but ....

to get the loaded JPG _width and _heigth is burning my mind

below is the code section I´m using inside a class


var imgHolder = detail.createEmptyMovieClip ("imgHolder", detail.getNextHighestDepth ());

var my_mcl:MovieClipLoader = new MovieClipLoader ();

// Create listener object:
var mclListener:Object = new Object ();
mclListener.onLoadError = function (target_mc:MovieClip, errorCode:String, status:Number)
{
trace ("Error loading image: " + errorCode + " [" + status + "]");
};
mclListener.onLoadStart = function (target_mc:MovieClip):Void
{
trace ("onLoadStart: " + target_mc);
};
mclListener.onLoadProgress = function (target_mc:MovieClip, numBytesLoaded:Number, numBytesTotal:Number):Void
{
var numPercentLoaded:Number = numBytesLoaded / numBytesTotal * 100;
trace ("onLoadProgress: " + target_mc + " is " + numPercentLoaded + "% loaded");
};
mclListener.onLoadComplete = function (target_mc:MovieClip, status:Number):Void
{
trace ("onLoadComplete: " + target_mc._width + " " + target_mc._height);
};
my_mcl.addListener (mclListener);
my_mcl.loadClip ("cristo.jpg", imgHolder);


I thougth I could get target_mc._width and target_mc._height after the Load is complete and then apply the proper xscale and yscale to imgHolder but I get ZERO for both.

What am I doing wrong ?

Thanks any help
João Carlos
Rio
Brazil

deadbeat
02-27-2006, 09:55 PM
Use onLoadInit instead on onLoadComplete...

From the help:
When you use the onLoadComplete and onLoadInit events with the MovieClipLoader class, it's important to understand how this differs from the way they work with your SWF file. The onLoadComplete event is called after the SWF or JPEG file has loaded, but before the application has been initialized. At this point it is impossible to access the loaded movie clip's methods and properties, and because of this you cannot call a function, move to a specific frame, and so on. In most situations, it's better to use the onLoadInit event instead, which is called after the content has loaded and is fully initialized.

HTH

K.

jcanistrum
02-27-2006, 09:59 PM
great,

it´s working fine ....

thanks

Use onLoadInit instead on onLoadComplete...

From the help:
When you use the onLoadComplete and onLoadInit events with the MovieClipLoader class, it's important to understand how this differs from the way they work with your SWF file. The onLoadComplete event is called after the SWF or JPEG file has loaded, but before the application has been initialized. At this point it is impossible to access the loaded movie clip's methods and properties, and because of this you cannot call a function, move to a specific frame, and so on. In most situations, it's better to use the onLoadInit event instead, which is called after the content has loaded and is fully initialized.

HTH

K.

jcanistrum
02-28-2006, 11:38 AM
Someone asked me the flas I´m doing so let´s go ahead and share with the someone else. :)

I hope it will help someone at intermediate/beginner level like me. :)

I´m trying to do everything by ActionScript, using the colin moock´s framework from Essential ActionScript 2.0.

It is fine because it solves all the pre-loader file size issues.

It´s working, but I´m still cleaning it and I´m so late with this project that I´ll not have time to refine it to make it easier to understand, ok ?.


I´doing a simple component with 2 scrollPanes

the first one show a list and when you click on it the item and its image is created on the next scrollPane.

It uses the ImageViewer class from the book and then I extend it to scale the JPG to the border size.


The hint is that you shoud use MovieClipLoader class to load the image into some empty mc and then you use the MovieClipLoader events to monitor it.

Nothing new .... but ....BUT

You should use onLoadInit instead of using onLoadComplete to get the JPG size, because, "don´t ask me why :) ", Init its the END not the Start :


public function onLoadInit (target:MovieClip):Void
{
// Remove the loading message.
container_mc.loadStatus_txt.removeTextField ();

// calculates the scale factor
// imageHolder/imageSize
//
var scaleX = container_mc.mask_mc._width / container_mc.image_mc._width;
var scaleY = container_mc.mask_mc._height / container_mc.image_mc._height;
// pick the minimum of them
//
var minScale = Math.min (scaleX, scaleY) * 100;
//
container_mc.image_mc._xscale = minScale;
container_mc.image_mc._yscale = minScale;
//
container_mc.image_mc.setMask (container_mc.mask_mc);
}


http://www.mvirtual.com.br/jcarlos/flash/testes/ListDetailPanel/

http://www.mvirtual.com.br/jcarlos/flash/testes/ListDetailPanel/listDetailpanel.zip

joão carlos
Rio
Brazil

great,

it´s working fine ....

thanks