PDA

View Full Version : image size from array?


Navarone
10-12-2005, 11:02 PM
This might be a component question but I'll start here. First I am trying to get the actual image size of the image when I click on my thumbnail before it getloaded into my pictures scrollPane. I have set up global variables to capture the image sizes and attempted to set up an array. This only gives me the first image size in the array, if I click on another thumbnail, I get the same image size. I am not sure what I am doing wrong and would appreciate any help. :)

var myScrollPane:mx.containers.ScrollPane;
myScrollPane.contentPath = 'Holder_mc';
//
this.zoom_out.onPress = function() {
myScrollPane.content.myLoader.scaleX /= 1.5;
myScrollPane.content.myLoader.scaleY /= 1.5;
trace(myScrollPane.content.myLoader.scaleX);
myScrollPane.invalidate();
};
this.zoom_in.onPress = function() {
myScrollPane.content.myLoader.scaleX += 100;
myScrollPane.content.myLoader.scaleY += 100;
trace(myScrollPane.content.myLoader.scaleX);
myScrollPane.invalidate();
};
//
var MAX_WIDTH:Number = 65;
var MAX_HEIGHT:Number = 65;
var mclListener:Object = new Object();
mclListener.onLoadInit = function(mc:MovieClip) {
// set variables to keep the original image dimensions
_global.xw = mc._width;
_global.xh = mc._height;
//trace(xw);
//trace(xh);
// where image width is greater than image height
if (mc._width>mc._height) {
mc._width = MAX_WIDTH;
mc._height = (mc._height*MAX_WIDTH)/_global.xw;
// center image
mc._y = (75-mc._height)/2;
}
//where image height is greater than image width
if (mc._height>mc._width) {
mc._height = MAX_HEIGHT;
mc._width = (mc._width*MAX_HEIGHT)/_global.xh;
mc._x = (75-mc._width)/2;
}
};
//
MyPicVars = new LoadVars();
MyPicVars.load("jetPlane.txt");
MyPicVars.onLoad = function(success) {
if (success) {
var t_mc:MovieClip;
Rc = this["Rc"];
//trace(Rc);
for (i=0; i<=Rc-1; i++) {
t_mc = thumbs.content.attachMovie("thumb_mc", "thumb"+i, i, this.getNextHighestDepth());
t_mc._x = 5;
t_mc._y = 5+(i*80);
// load images into thumbs scroll pane
_root["mc"+i] = new MovieClipLoader();
_root["mc"+i].addListener(mclListener);
_root["mc"+i].loadClip("jetPlane/"+this["pic"+i], t_mc.Container_mc);
//
t_mc.i = i;
t_mc.location = this["pic"+i];
t_mc.onRelease = function() {
//
img_size = new Array(_global.xw, _global.xh);
trace(img_size.join(","));
//
// load image into pictures scroll pane
//trace(this.location);
myScrollPane.content.myLoader.contentPath = "jetPlane/"+this.location;
myScrollPane.invalidate();
//trace(_global.xw)
//trace(_global.xh)
//trace(myScrollPane.content.myLoader.width);
//trace(myScrollPane.content.myLoader.height);
};
thumbs.invalidate();
}
} else {
trace("not loaded");
}
};

Navarone
10-13-2005, 02:32 AM
ok, I have tried a dozen things and this is the latest incarnation. I'm really lost. Adding this code in the mclListner

//
img_size = new Array(_global.xw, _global.xh);
trace(img_size.join(","));
//

gives me this in the output window:
920,883
897,895
664,925
397,649
517,706
580,865
886,901

The only thing is the order is reversed for some reason, that is to say
the first image in the thumbs scrollpane is 886,901.

Now the following gives me the right numbers except that the first thumb I click is always 100,100. Subsequent clicks will give me the image sizes begining with 886,901. So if i click on the second thumb image I get the first image size.


trace(myScrollPane.content.myLoader.width);
trace(myScrollPane.content.myLoader.height);

Sunny13
10-13-2005, 12:06 PM
can't get the code.... too long...but an idea ..... enlarge the picture to xScale and yScale to 100 and get the height and width at that time.