2011-08-26 5 views
1

UIComponent가 있고 내부에 이미지 파일을로드하는 로더를 넣습니다.ActionScript 3 : UIComponent 내부의 이미지 크기 조정

문제 : 사각형에 대한 UIComponent의 크기를 조정하더라도 여전히 로더의 이미지 크기를 따릅니다. 그러나 로더에서 이미지 크기를 조정하면 이미지가 늘어납니다. 내가하고 싶은 일은 정사각형 크기가 고정 된 컨테이너 (UIComponent)를 가지고 이미지를로드 한 후에 컨테이너의 치수에 맞게 늘어나지 않게됩니다. 누구든지 저에게 어떻게 도와 줄 수 있습니까?

답변

2

나는 긴 화면 비율을 유지하면서 이미지 크기를 조정하기 위해이 기능을 사용하고 :

public function constraintResize(iSourceWidth:*, iSourceHeight:*, iTargetWidth:*, iTargetHeight:*, iFitSmallerDimension:*):* { 
    if (iFitSmallerDimension == undefined) iFitSmallerDimension = false; 
    if (iTargetWidth == 0 || iTargetHeight == 0) return; 
    if (iSourceWidth == 0 || iSourceHeight == 0) return; 

    var newWidth:*; 
    var newHeight:*; 
    var targetRatio:*; 
    var sourceRatio:*; 

    var output:* = { width:iSourceWidth, height:iSourceHeight }; 

    if (iSourceWidth <= iTargetWidth && iSourceHeight <= iTargetHeight) { 
    if (iFitSmallerDimension) { 
     targetRatio = iTargetWidth/iTargetHeight; 
     sourceRatio = iSourceWidth/iSourceHeight; 
     if (sourceRatio < targetRatio) { 
     newHeight = iTargetHeight; 
     newWidth = newHeight * sourceRatio; 
     } else { 
     newWidth = iTargetWidth; 
     newHeight = newWidth/sourceRatio; 
     } 
     output.width = newWidth 
     output.height = newHeight 
    } 

    } else { 

    targetRatio = iTargetWidth/iTargetHeight 
    sourceRatio = iSourceWidth/iSourceHeight 
    if (sourceRatio < targetRatio) { 
     newHeight = iTargetHeight 
     newWidth = newHeight * sourceRatio 
    } else { 
     newWidth = iTargetWidth 
     newHeight = newWidth/sourceRatio 
    } 

    output.width = newWidth 
    output.height = newHeight 
    } 

    return output 
}  

기능은 당신에게 targetsource에 맞는 이상적인 크기를 줄 것이다. 구성 요소 관리자 wondow에서 진정한

var s:* = constraintResize(loader.contentWidth, loader.contentHeight, yourSquare.width, yourSquare.height); 
loader.width = s.width; 
loader.height = s.height; 
+0

와우! 나는 5 줄의 코드 안에서 그것을 할 수 있다고 생각했다. 감사합니다! 나는 이것을 확실히 시도 할 것이다! –

1

사용 UILoader 구성 요소 및 설정 scaleContent = 따라서, 귀하의 경우, 당신은 그런 식으로 사용할 수 있습니다.

+0

fl.containers.UILoader를 가져 오려고하지만 flex는이 패키지를 이해하는 것 같지 않습니다.이 작업을 위해 몇 가지 특수 라이브러리가 필요합니까? –

+0

미안하지만 나는 flex에 대한 충분한 지식이 없습니다. – hardik