Jump to content
Search Community

[SOLVED] Set scaleMode based on image aspect

alanpuccinelli test
Moderator Tag

Recommended Posts

I'm trying to get my slideshow to automatically set the scaleMode for an imageloaders content based on the aspect ratio of the image but it's proving difficult.

 

For example if the image is a portrait I'd like it to scale proportionalInside and if it's landscape I'd like it to be proportionalOutside.

 

Trouble is, I don't think the loader is aware of the image's dimensions until after the content has been loaded at which point the scaleMode needs to have already been set. Is this correct? If that's the case is it even possible to do what I'm trying to do?

Link to comment
Share on other sites

Scratch this. Not sure why I assumed that the scaleMode has to be set prior to load but this is apparently not the case. By doing the aspect check after the load is complete I can attain the result I need. Here's a code snippet for anyone trying to do the same thing:

 

public function ssLoadComplete(evt:Event):void{
		var cntnt:Array = LoaderMax.getContent(evt.target.name);
		for (var i:int = 0; i < cntnt.length; i++) {
			if (cntnt[i] is ContentDisplay) {
				if (cntnt[i].width > cntnt[i].height){
					cntnt[i].scaleMode = "proportionalOutside";
                                               cntnt[i].crop = true;
				}else{
					cntnt[i].scaleMode = "proportionalInside";
				}
				var content:ContentDisplay = cntnt[i];
				cntnt[i].fitWidth = 1024;
				cntnt[i].fitHeight = 576;
			}
		}

 

 

XML just looks like this:

<?xml version="1.0" encoding="utf-8"?>


























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.
×
×
  • Create New...