|
|
#1 |
|
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); } |
|
|
|
0
|
|
|
#2 |
|
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."
|
|
|
|
0
|
|
|
#3 | |
|
Quote:
|
||
|
|
0
|
|
|
#4 |
|
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 |
|
|
|
0
|
|
|
#5 | |
|
Quote:
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... |
||
|
|
0
|
|
|
#6 |
|
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'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."
|
|
|
|
0
|
|
|
#7 |
|
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 |
|
|
|
0
|
|
|
#8 |
|
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); |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
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.






. I'll get back to you once I get home, I have the code there.


Linear Mode

