|
-
Detecting image width/height loaded by XML
I am able to load images into my file by designating their locations in an XML file using AS3. I'd like to be able to determine the width and height of the individual images without having to manually enter each one into the XML file.
I think once I reach this point, I'll be able to figure it out on my own:
I want to be able to load an image to the stage and trace its width.
Is there a simple way to do this?
Thanks.
-
Once you have the image loaded, the Loader width and height will be the image width and height. You cannot determine the width and height before you load it.
-
Thanks, but it doesn't seem to be working in practice. I probably left something out.
PHP Code:
function loadPics(xThumb:XMLList):void{
imageLoader = new Loader();
imageLoader.load(new URLRequest(xThumb[1]));
imageLoader.x = 1;
imageLoader.y = 1;
//s is an empty movie clip on stage
s.addChild(imageLoader);
//this just traces out 0, but the picture is several hundred pixels wide
trace(imageLoader.width);
}
-
At the time you are tracing, the picture is still loading. You need to put in a listener for Event.COMPLETE, and do your size dependent stuff in there.
-
I just made something similar and can't get images width nor height, I used the events, my progress bar works without problems but when Event.COMPLETE happens I trace the width and heigth and are both 0.
And if I try to change height or width after finish loading, the picture disappears. I just can change size with scaleX or scaleY but I need to fix it to a pixel number and each image is different. Please help.
Thanks.
-
Damn!!!! it was very simple. Don't use Event.COMPLETE, use Event.INIT, with this one all vars are ready to use.
-
no it's wrong, Event.COMPLETE is OK, I just made a mistake and was accessing another object. but you must use:
loaderName.contentLoaderInfo.addEventListener(Even t.COMPLETE,yourHandler);
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|