471,085 Members | 1,071 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,085 software developers and data experts.

Know the dimension of a picture

3
Suppose that i load a picture inside my movie clip
mc.loadMovie("pic.jpg");

How can i know the dimension of the "pic.jpg" ?
I need the info such as the width and height of the pic to continue with my scripting. (such 1024 x 768 or 680 x 480).

Well, the reason i want to do this is to make a photo gallery and i want to put all pics with different dimensions into the frame that i've created.

Thx for advance
May 16 '07 #1
5 6950
Motoma
3,237 Expert 2GB
Simply check the dimensions of the movie clip.

Suppose that i load a picture inside my movie clip
mc.loadMovie("pic.jpg");

How can i know the dimension of the "pic.jpg" ?
I need the info such as the width and height of the pic to continue with my scripting. (such 1024 x 768 or 680 x 480).

Well, the reason i want to do this is to make a photo gallery and i want to put all pics with different dimensions into the frame that i've created.

Thx for advance
May 16 '07 #2
nomad
664 Expert 512MB
if you have any photo enhancement like Adobe Photoshop or MS Photo editor you can get the dimension of the "pic.jpg. They will have a section where you can resize your image and or find out what size it is.

nomad
May 21 '07 #3
Recently I was trying to get the height and width of an image loaded into Flash but kept getting zero for height and width. Turns out I was getting the dimensions before the picture was completely loaded .

Instead, I used the movieClipLoader object to load the picture. Then I could use a listener object to detect the onLoadInit event of the movieClipLoader object so that I could get the dimensions after the picture was completely loaded.

Here's the movieClipLoader related code in which the height and width are captured in the image movieclip's orig_height and orig_width variables.

Expand|Select|Wrap|Line Numbers
  1. // ************************************************************
  2. // Create object to listen for when done with loading pic
  3. // ************************************************************
  4. var loadListener:Object = new Object();
  5. loadListener.onLoadInit = function(target_mc:MovieClip):Void  {
  6.     target_mc.orig_height = target_mc._height;
  7.     target_mc.orig_width  = target_mc._width;
  8. };
  9. var mcLoader:MovieClipLoader = new MovieClipLoader();
  10. mcLoader.addListener(loadListener);;
  11.  
  12. // ---------------------------------------------------------------------------
  13. // Use MovieClipLoader to load the image
  14. // ---------------------------------------------------------------------------
  15. mcLoader.loadClip("pic.png", image);


todd
May 21 '07 #4
Recently I was trying to get the height and width of an image loaded into Flash but kept getting zero for height and width. Turns out I was getting the dimensions before the picture was completely loaded .

Instead, I used the movieClipLoader object to load the picture. Then I could use a listener object to detect the onLoadInit event of the movieClipLoader object so that I could get the dimensions after the picture was completely loaded.

Here's the movieClipLoader related code in which the height and width are captured in the image movieclip's orig_height and orig_width variables.

Expand|Select|Wrap|Line Numbers
  1. // ************************************************************
  2. // Create object to listen for when done with loading pic
  3. // ************************************************************
  4. var loadListener:Object = new Object();
  5. loadListener.onLoadInit = function(target_mc:MovieClip):Void  {
  6.     target_mc.orig_height = target_mc._height;
  7.     target_mc.orig_width  = target_mc._width;
  8. };
  9. var mcLoader:MovieClipLoader = new MovieClipLoader();
  10. mcLoader.addListener(loadListener);;
  11.  
  12. // ---------------------------------------------------------------------------
  13. // Use MovieClipLoader to load the image
  14. // ---------------------------------------------------------------------------
  15. mcLoader.loadClip("pic.png", image);


todd
there are other methods available for the MovieClip.loadClip() that might be very useful. just grab add them to todd's code and you're sorted.
onLoadError, in case of an error
onLoadProgress, during the load
onLoadStart, when it starts loading
onLoadComplete, when it finishes loading
onLoadInit, when it is loaded and goes to the first keyframe (that's why using any of the previous methods would return zero, cos it was empty, but when it checks the first keyframe it is filled with your image)

for example:
loadListener.onLoadError = function(target_mc:MovieClip):Void {
trace('not loaded: ' + mc);
};

HTH :)
dns
Jul 5 '07 #5
wtdtan
1
Expand|Select|Wrap|Line Numbers
  1. mcLoader.loadClip("pic.png", image);
in response to Todd's code, it works great. However, one little tidbit was left out with line 15.

the reference to
Expand|Select|Wrap|Line Numbers
  1. image
, that is the movie clip you are loading your images into. so it has to be declared before the
Expand|Select|Wrap|Line Numbers
  1. mcLoader.loadClip
.
Oct 4 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by John Pastrovick | last post: by
5 posts views Thread by riki | last post: by
4 posts views Thread by Michael Kirchner | last post: by
9 posts views Thread by James | last post: by
3 posts views Thread by tg | last post: by
5 posts views Thread by Jackson | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.