BitmapFill中的MultiDPIBitmapSource不起作用

时间:2015-01-14 13:50:22

标签: flash-builder

<{1}}中的

MultiDPIBitmapSource不起作用。

这是我的代码:

BitmapFill

1 个答案:

答案 0 :(得分:0)

使用Flash构建器有时会变得比另一个sdk更复杂......就像视觉体验......我们应该关注细节,例如在Flash Builder的MultiDPIBitmapSource帮助中说:

此类提供各种运行时密度的位图列表。

  

It is supplied as the source to BitmapImage or Image and as the icon of a Button   。组件将使用Application.runtimeDPI来选择要显示的图像。

所以我们不能在rect中的bitmapFill中使用MultiDPIBitmapSource。我们也许想用这个代码解决问题:

   <fx:Script>
   <![CDATA[
    .
    .
    switch( FlexGlobals.topLevelApplication.runtimeDPI)
  {
  case  DPIClassification.DPI_240 :
    bgFill.source =  "images/backgroundSkin/160/image.jpg 
    break;

  case  DPIClassification.DPI_160 :
    bgFill.source =  "images/backgroundSkin/160/image.jpg 
    break;

  case  DPIClassification.DPI_320 :
    bgFill.source =  "images/backgroundSkin/160/image.jpg 
    break;
   }
     .
     .
    ]]>
    </fx:Script>
    .
    .
<s:Rect id="background2"  left="0" right="0" top="0" bottom="0" width="100%" height="100%" >
        <s:fill>
            <s:BitmapFill  id="bgFill" fillMode="repeat"   />
        </s:fill>
</s:Rect>

但你可以看到这段代码也不起作用我认为BitmapFill的id在脚本代码中是已知的..任何方式对我来说唯一的方法是使用loader: 。

.switch( FlexGlobals.topLevelApplication.runtimeDPI)
     {
       case  DPIClassification.DPI_240 :
        loader.load(new URLRequest("images/backgroundSkin/240/image.jpg"));
     loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderComplete);
        break;

    case  DPIClassification.DPI_160 :
       loader.load(new URLRequest("images/backgroundSkin/160/image.jpg"));
       loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderComplete);
        break;

    case  DPIClassification.DPI_320 :
       loader.load(new URLRequest("images/backgroundSkin/320/image.jpg"));
       loader.contentLoaderInfo.addEventListener(Event.COMPLETE,loaderComplete);
       break;
    }



    }
    public function loaderCompleteHandler(evt:Event):void
    {
        bgFill.source = evt.target.content;
    }