Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
bluebill1049

Loader return image's original width and height

Recommended Posts

Hi there,

 

var stageProductImageLoader:ImageLoader = new ImageLoader(_IMGDIR + e.target.parent.parent.productCategory + '/' + e.target.parent.parent.productId + ".png",

{container: _allTempleProducts[0].mc_stageProductContainer,

height:80,

x:-15,

y:0,

hAlign: 'left',

vLaign: 'top',

scaleMode: 'proportionalInside',

centerRegistration: false

});

 

is there i way i can get the image's original width and height, cause i want to know the ratio of the image.

 

Thanks

Bill

Link to comment
Share on other sites

what you can get is the scale of the rawContent of the loader. using that you can determine the original width

 

in your case:

 

trace(stageProductImageLoader.rawContent.width/stageProductImageLoader.rawContent.scaleX) // output original width

Link to comment
Share on other sites

when i have this rawContent. i go this term undefined error. Thanks for the help

 

TypeError: Error #1010: A term is undefined and has no properties.

at src.products::ProductsList/createProductOnStage()

Link to comment
Share on other sites

Sorry I wasn't more clear.

 

the code I provided needs to be run after the asset has loaded. do you have an onComplete handler in place?

Link to comment
Share on other sites

var stageProductImageLoader:ImageLoader = new ImageLoader(_IMGDIR + e.target.parent.parent.productCategory + '/' + e.target.parent.parent.productId + ".png",

{container: _allTempleProducts[0].mc_stageProductContainer,

height:80,

x:-15,

y:0,

onComplete:onImageLoad,

hAlign: 'left',

vLaign: 'top',

scaleMode: 'proportionalInside',

centerRegistration: false

});

 

private function onImageLoad(e:LoaderEvent):void{

//trace(e.target.rawContent.width/e.target.rawContent.scaleX)

trace(e.target.rawContent.width/e.target.rawContent.scaleX);

}

 

i had this but it doesn't return me the right width, anything wrong i did?

 

Cheers

Bill

Link to comment
Share on other sites

nothing jumps out at me. I tried to break my own example many times with different images and always got the proper result.

 

good news is this should work fine:

 

trace(e.target.rawContent.bitmapData.width);

Link to comment
Share on other sites

Thank you very much for all your help. you have a great day~ it workes

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×