2010-04-13 5 views
0

나는 스프라이트에 맞게 이미지 크기를 조정하도록되어 ActionScript 코드의 조각을 가지고 : (같이하는 이미지 크기를 조정하지 그냥 클립) 왜 작동하지 않습니다어떻게이 이미지가 스프라이트에 맞게 크기가 조정되지 않습니까?

package 
{ 
    import flash.display.Sprite; 
    import flash.display.Bitmap; 
    import flash.events.Event; 

    public class Main extends Sprite 
    { 
     [Embed(source = 'img.png')] 
     private var TheImage:Class; 

     public static const TheImageWidth:Number = 1300; 
     public static const TheImageHeight:Number = 1300; 

     public function Main():void 
     { 
      if (stage) init(); 
      else addEventListener(Event.ADDED_TO_STAGE, init); 
     } 

     private function init(e:Event = null):void 
     { 
      removeEventListener(Event.ADDED_TO_STAGE, init); 
      // entry point 

      var image:Bitmap = new TheImage(); 

      addChild(image); 

      image.scaleX = width/TheImageWidth; 
      image.scaleY = height/TheImageHeight; 
     } 

    } 

} 

? 이미지의 크기가 올바르지 않습니다.

답변

0

image.image.content.width = TheImageWidth; 
image.image.content.height = TheImageHeight; 
+0

아니요. 'image'는'image'의 속성이나 메소드가 아닙니다. –

+0

그건 내가 제대로 질문을 읽지 못해서 얻는거야! 나는 그 이미지가 비트 맵이 아니라 이미지라고 가정했다 ... transform 속성을 사용하고 scaleX 및 Y 속성 대신 매트릭스를 할당 해보십시오. –

0

나는 이미지에 대해이 같은 일을했다보십시오. Flex 2.5 용 ArcGIS를 사용하여 MapImage와 MapImageLayer를 사용하는 데 문제가있었습니다. 3.5에서 수정 된 것 같습니다. 어쨌든 이미지를 스프라이트에 넣고 스프라이트 폭을 기반으로 이미지를 페인트해야했습니다. 스프라이트의 크기로 이미지의 크기를 조정하려면 Matrix API를 사용하고 scale 메서드를 사용해야합니다. 이 값은 스프라이트의 폭을 이미지의 너비로 나눈 값이 이미지가 스프라이트보다 큰 것으로 가정해야합니다. 높이와 똑같이하십시오. 이 작업을 수행하는 데 사용한 코드는 다음과 같습니다.

   const point:MapPoint = geometry as MapPoint; 

       sprite.x = toScreenX(map, point.x); 
       sprite.y = toScreenY(map, point.y); 

       // grab left x point for upper left then for lower right 
       // actua 
       var bottomLeftX:Number = toScreenX(map, geomertyWrapper.extent.xmin); 
       var topRightX:Number = toScreenX(map, geomertyWrapper.extent.xmax); 

       var bottomLeftY:Number = toScreenY(map, geomertyWrapper.extent.ymin); 
       var topRightY:Number = toScreenY(map, geomertyWrapper.extent.ymax); 

       iconWidth = Math.abs(topRightX - bottomLeftX); 
       iconHeight = Math.abs(topRightY - bottomLeftY); 

       sprite.width = iconWidth; 
       sprite.height = iconHeight; 

       var scaleX:Number = iconWidth/bitmapData.width; 
       var scaleY:Number = iconHeight/bitmapData.height; 

       m_matrix.a = 1.0; 
       m_matrix.d = 1.0; 
       m_matrix.scale(scaleX, scaleY); 
       m_matrix.tx = -iconWidth/2; 
       m_matrix.ty = -iconHeight/2; 

       //Values needed for drawing AlertNotificationInstance 

       sprite.graphics.beginBitmapFill(m_bitmapData, m_matrix, false, false); 
       sprite.graphics.drawRect(m_matrix.tx, m_matrix.ty, 
        iconWidth, 
        iconHeight); 
       sprite.graphics.endFill(); 

희망이 있습니다.

관련 문제