Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-02-2007, 07:58 AM   #1
Registered User
Join Date: Jul 2007
Posts: 3
Default image width and height

Hi there,

i have already imported the images externally. but i would like to put them in the BitmapData which needs to specify the width and height. i dont want to hard code it, i want to get the width and height of the image itself and then assign to the width and the height of the Bitmapdata.

i can't seem to find any way to do that. pls help.

thank you!

jjyang is offline   Reply With Quote
Old 08-02-2007, 08:45 AM   #2
Registered User
Join Date: Nov 2005
Posts: 139

load them in with movieclip loader.. then onLoadInit() method you can get the width and height.
thatblokemike is offline   Reply With Quote
Old 10-30-2009, 07:42 PM   #3
Senior Member
ggalan's Avatar
Join Date: Feb 2006
Location: New York
Posts: 620

onLoadInit is for AS2, does anyone have a solution for AS3?
ggalan is offline   Reply With Quote
Old 10-31-2009, 05:33 AM   #4
Site Contributor
Mazoonist's Avatar
Join Date: Jun 2006
Posts: 3,160
Send a message via AIM to Mazoonist

ActionScript Code:
var loader:Loader = new Loader(); var bmd:BitmapData; var bitmap:Bitmap; loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded); loader.load(new URLRequest("yourfile.jpg")); function imageLoaded(event:Event):void {     //event.target is loader.contentLoaderInfo, and already     //has the information as to the width and height of     //the loaded image:         bmd = new BitmapData(event.target.width, event.target.height);     bmd.draw(loader);     bitmap = new Bitmap(bmd);     addChild(bitmap);     //alternatively, since event.target.content is a bitmap object,     //try uncommenting this code and commenting the previous block:         /*bitmap = event.target.content;     addChild(bitmap);*/ }
My Tutorials * My Website

Last edited by Mazoonist; 10-31-2009 at 05:35 AM.
Mazoonist is offline   Reply With Quote
Old 10-31-2009, 06:16 AM   #5
Senior Member
Join Date: Jun 2008
Posts: 1,206

width and height parameters are ignored with imported bitmaps.
ie: you can specify 0,0 with imported bitmaps.
snickelfritz is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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
get width and height of a dynamically loaded image once it's done loading?! manovotny ActionScript 3.0 3 06-14-2007 03:41 PM
Get height and width of loaded image vsgill ActionScript 2.0 3 04-30-2006 12:18 AM
Determine width & Height of loaded image with AS? dprichard ActionScript 1.0 (and below) 3 02-22-2006 04:58 PM
How to get jpg image width and height amvian ActionScript 2.0 18 10-28-2004 08:43 PM
oxx{::FREE CODE Image Gallery .AS:::> flavoredthunder ActionScript 1.0 (and below) 1 03-01-2003 12:48 AM

All times are GMT. The time now is 02:05 PM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.