Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > Adobe Web Programming > Flash (all versions)
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Flash (all versions) section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 19th, 2005, 07:09 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default Loading a jpg and determining the pixel size

I'm loading a jpg into a movie clip, and based on its size I want to scale it so it is no larger than 350px in either width or height. I want to keep the aspect ratio the same, however.

To do this, I'm doing the following calculation:
Code:
var scale=( Math.min ( ( 350 / logo_mc._width ) , ( 350 / logo_mc._height ) ) * 100 );
logo_mc._xscale=scale;
logo_mc._yscale=scale;
The image, at this point, has an alpha value of 0%. In the next frame it begins a 10-frame tween where the alpha ends up as 100%.

I'm always ending up with a scale of 100, though. The image I'm loading in is 650px * 462px. However, the logo_mc._width and logo_mc._height are only equal to these about four frames into the alpha tween.

I've tried putting in a event handler for the logo_mc.onLoad event. This didn't work at all (i.e. the function is never event executed. Since looking at the documentation, it says that the onLoad event only occurs for clips being loaded in from the library, rather than external clips/jpegs).

I've tried putting in an event handler using the onClipEvent(load). The values of _width and _height when tested for in the function are 350px square, rather than 650 * 462 as they should be.

In desparation, I've tried looping in the code until the _width and _height are the correct values. It just enters a permenent loop and I have to crash out of flash.

This surely shouldn't be impossible - I would have thought determining the size of an image and scaling it accordingly isn't an unheard-of task, but I just can't seem to accomplish it. Please help!

Thanks in advance,

Jaucourt.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Get image size without loading? tal Javascript How-To 3 June 30th, 2007 07:05 AM
Determining the cache size easwars C++ Programming 0 January 28th, 2007 12:33 PM
php form for up-loading a gif., jpg, or bmp file Wilbon Beginning PHP 2 January 8th, 2006 10:32 AM
control window loading size, toolbars etc dunc Javascript How-To 1 August 18th, 2004 06:33 AM
Determining size of recordset column gp_mk ADO.NET 0 May 27th, 2004 04:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.