---
title: "Using non-embedded images in a spark BitmapImage"
author: "cloud21"
date: "2011-04-18T11:21:17Z"
tags: []
categories: ["Web前端"]
slug: "using-non-embedded-images-in-a-spark-bitmapimage"
draft: false
lastmod: "2011-04-18T11:21:17Z"
id: 1006143
url: "https://cloud21.iteye.com/blog/1006143"
---

```java
TiledImage.mxml
 <?xml version="1.0" encoding="utf-8"?>
<s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
         xmlns:s="library://ns.adobe.com/flex/spark" 
         xmlns:mx="library://ns.adobe.com/flex/mx">

    <fx:Script>
        <![cdata[
            import mx.controls.swfloader;
            import flash.display.bitmapdata;
            import flash.display.bitmap;
            
            public function set source(value:object):void {
                loader.source = value;
            }
            
            private function updateSource():void {
                // use a SWFLoader to download the bitmap data then push that into the BitmapImage
                bitmapImage.source = loader.content;
            }
        ]]>
    </fx:Script>
    <mx:SWFLoader id="loader" complete="updateSource()" width="0" height="0" />
    <s:BitmapImage id="bitmapImage" width="100%" height="100%" fillMode="repeat" />
    
</s:Group>
TiledImageAppcation.mxml
 <?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:local="*"
               width="90%" height="90%" viewSourceURL="srcview/index.html">
    
    <s:Group width="{widthSlider.value}" height="100" horizontalCenter="0" y="10">
        <local:TiledImage source="bgDiag.png" width="100%" height="100%" />
        <s:Label text="Tiled Background" fontSize="16" horizontalCenter="0" verticalCenter="0" fontWeight="bold" />
    </s:Group>
    
    <s:HSlider id="widthSlider" value="200" minimum="150" maximum="300" horizontalCenter="0" y="125" />
    
</s:Application>
```