Flex 4 设置背景图片

Flex 3中Canvas是可以设置backgroundImage的,但是在Flex 4的Spark组件中则不支持backgroundImage属性的设置,怎么办呢?方法当然很多:

可以考虑用s:Group去代替Canvas,两个组件可以达到类似的功能,

<s:Group width="100%"
height="111">
<s:Rect width="100%"
height="100%">
<s:fill>
<s:BitmapFill fillMode="scale"
source="@Embed(source='/assets/image/test.png')"/>
</s:fill>
</s:Rect>
<s:Button label="test"
color="#FFFFFF"
left="10"
top="10"/>
</s:Group>




也可以在Canvas的外面用BorderContainer制造“假象”,


<s:BorderContainer backgroundImage="@Embed(source='/assets/image/test.png')"
backgroundImageFillMode="scale"
width="100%"
borderVisible="false">
<mx:Canvas id="upPanel"
width="100%"
height="111"
horizontalScrollPolicy="off"
verticalScrollPolicy="off">
<s:Button label="test"
color="#FFFFFF"
left="10"
top="10"/>
</mx:Canvas>
</s:BorderContainer>

你可能感兴趣的:(canvas,backgroundImage,BitmapFill,fillMode)