Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 30, 2006, 05:45 PM   #1
londonweb
macrumors 6502
 
Join Date: Sep 2005
Location: london
ActionScript: Get dimensions of loaded jpeg?

Another Actionscript problem (but hopefully a quick one):

How do I obtain the dimensions of a jpeg that has been loaded into a movieclip using the loadMovie() function? If I ask for the _width and _height values, I just get the size of the original movieclip into which the jpeg was loaded (ie. 0, since it's an empty clip), but not the size of the jpeg itself.

Here is the offending code (nb. thanks to Robx2 for helping with this part!):

for (var j=1; j<20; j++) {
thumbstrip.createEmptyMovieClip("thumbnail_"+j, j);
thumbstrip["thumbnail_"+j].loadMovie("../../images/thumbs/wd_beau_"+j+".jpg");

var prevwidth = thumbstrip["thumbnail_"+(j-1)]._width; //should get the width of the previously loaded image
var prevx = thumbstrip["thumbnail_"+(j-1)]._x;
var xpos = (prevwidth+prevx+3);

thumbstrip["thumbnail_"+j]._x= xpos; //should position next image at the right edge of the last
thumbstrip["thumbnail_"+j]._y= -100;
trace (prevwidth);
}
londonweb is offline   0 Reply With Quote
Old Jan 30, 2006, 05:53 PM   #2
floyde
macrumors 6502a
 
floyde's Avatar
 
Join Date: Apr 2005
Location: Monterrey, México
hmm... I did that once... I can't for the life of me remember how I did it though . I'll get back to you once I get home, I have the code there.
__________________
"He who will not reason is a bigot; he who cannot is a fool; and he who dares not is a slave."
floyde is offline   0 Reply With Quote
Old Jan 30, 2006, 05:59 PM   #3
londonweb
Thread Starter
macrumors 6502
 
Join Date: Sep 2005
Location: london
Quote:
Originally Posted by floyde
hmm... I did that once... I can't for the life of me remember how I did it though . I'll get back to you once I get home, I have the code there.
Thanks, I'd appreciate that. I've been scouring various websites and the manuals I have here, but can't find any obvious way to do it. I can see how you could do it by passing variables for the image along with the file itself, but there must be a simpler way...
londonweb is offline   0 Reply With Quote
Old Jan 30, 2006, 06:18 PM   #4
robx2
macrumors member
 
Join Date: May 2005
Glad that basic code lives on.

You know, the problem might be that it looks for the width before the jpg gets through loading. You might need to put in some sort of onLoad action to make it work properly.

Otherwise you might need to build an external xml file where you could store file names and jpeg dimensions.

Rob
robx2 is offline   0 Reply With Quote
Old Jan 30, 2006, 06:38 PM   #5
londonweb
Thread Starter
macrumors 6502
 
Join Date: Sep 2005
Location: london
Quote:
Originally Posted by robx2
Glad that basic code lives on.

You know, the problem might be that it looks for the width before the jpg gets through loading. You might need to put in some sort of onLoad action to make it work properly.

Otherwise you might need to build an external xml file where you could store file names and jpeg dimensions.

Rob
Hi Rob

The code actually looks for the width of the previously loaded thumbnail (j-1)- I understand that this won't work until the loop gets to the 2nd one, but when I trace the value of prevwidth, I get something like this:

undefined
0
0
0
0
etc.

I'm trying to avoid having to have all my thumbnails the same size (as some will be landscapes) and also having to write an accompanying xml file to go with it...
londonweb is offline   0 Reply With Quote
Old Jan 30, 2006, 08:39 PM   #6
floyde
macrumors 6502a
 
floyde's Avatar
 
Join Date: Apr 2005
Location: Monterrey, México
Sorry, I couldn't find the code, but robx2 is right. You get the wrong dimensions because the code execution is usually much faster than loading a picture. You need something like this to read the proper values:

Code:
if (this.getBytesLoaded() >= this.getBytesTotal())
{
      //Read dimensions here
}
I think you substitute this with the name of the movieclip, I havent used flash in a while...

I'm not sure what's the most effective way of doing this though. There's a tutorial on loading jpg's here.
__________________
"He who will not reason is a bigot; he who cannot is a fool; and he who dares not is a slave."
floyde is offline   0 Reply With Quote
Old Jan 31, 2006, 05:31 AM   #7
londonweb
Thread Starter
macrumors 6502
 
Join Date: Sep 2005
Location: london
Thanks floyde

I'll have a look at that tutorial later on today. I take the point about the jpeg not being loaded fully before the size is returned, but I'm confused because a lot of tutorials I've read say that the jpeg you load takes on the dimensions of the clip it's loaded into...

I'll let you know what happens tomorrow
londonweb is offline   0 Reply With Quote
Old Jun 26, 2007, 10:51 PM   #8
SteveMania
macrumors newbie
 
Join Date: Jun 2007
Send a message via AIM to SteveMania Send a message via Yahoo to SteveMania
I know this is an old thread, but I am sick of reading posts that i personally want answers for and there not being one after all of that reading! Below is how you should load images and gain access to their height/width and so on... The answer is onLoadInit(); onLoadComplete will not work because all of the variables and things are not initialized until the onLoadInit(); Hope this saves someone some time!

Use the MovieClipLoader object (with a Listener):

var my_mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();

mclListener.onLoadProgress = function(target_mc:MovieClip,numBytesLoaded:Number,numBytesTotal:Number):Void {
var pctLoaded:Number =Math.ceil(100*(numBytesLoaded/numBytesTotal));
// This will get you the percent amount loaded for use in a preloader, etc...
};
mclListener.onLoadInit = function(mc:MovieClip):Void {
trace("LoadInit Rules! "+mc._width); // This is the method that will return the proper values for height/width

}

my_mcl.addListener(mclListener);
my_mcl.loadClip(imageVariable, MovieClipToLoadImageInto);
SteveMania is offline   0 Reply With Quote

Reply
MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Dimensions of MacBook Pro 13" box? MJNBGA MacBook Pro 3 Jun 16, 2011 07:32 AM
how to get rid of bootcamp load up whatupkiddo MacBook Pro 7 Sep 15, 2010 05:20 PM
How to get iPhoto to display jpeg instead of RAW? Mjmar Mac Basics and Help 0 Jun 8, 2010 04:54 PM
How do I get rid of a software helper file that keeps trying to load? NJRonbo Mac Basics and Help 9 Jan 17, 2010 10:06 AM
I need to get the dimensions of a window ffej2ffej Mac Programming 8 Sep 20, 2009 04:45 AM


All times are GMT -5. The time now is 10:58 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC