bgchange

Application.application.setStyle("backgroundColor", "#00FF00");
<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml">
	<mx:Script>
		<![CDATA[
			import mx.controls.Image;
 
			private var _image : Image = null;
 
			public function setTileImage( image : Image ) : void
			{
				this._image = image;
				this.invalidateDisplayList();
			}
 
			public function setBackground(source:String) : void
			{
				// 1. for crossdomain images, we need to create a LoaderContext object and set its checkPolicyFile to true.
				var loaderContext : LoaderContext = new LoaderContext ();
				loaderContext.checkPolicyFile = true;
 
				// 2. assign that loaderContext object to an Image object
				var image : Image =  new Image();
				image.loaderContext =  loaderContext;
 
				// 3. set source and load
				image.source = source;
				image.addEventListener( Event.COMPLETE, onImageLoaded  );
				image.load();
 
 
			}
 
			private function onImageLoaded( event : Event ) : void
			{
				var image : Image = Image( event.currentTarget );
 
				// 1. set as tile image background
				this.setTileImage( image );
			}
 
 
			override protected function updateDisplayList( unscaledWidth : Number, unscaledHeight : Number ) : void
			{
				super.updateDisplayList(unscaledWidth, unscaledHeight );
 
				if ( _image != null )
				{
					var bitmap : Bitmap = Bitmap( _image.content );
					var bitmapData : BitmapData = new BitmapData( bitmap.width, bitmap.height );
					bitmapData.draw( bitmap );
 
					graphics.clear();
					graphics.beginBitmapFill( bitmapData );
					graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
					graphics.endFill();
				}
			}
		]]>
	</mx:Script>
</mx:Canvas>
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" fontSize="14" xmlns:images="images.*">
 
	<mx:Script>
		<![CDATA[
			private function clickHandler():void{
				this.tc.setBackground(this.textInput.text);
			}
		]]>
	</mx:Script>
 
	<mx:Label text="可自行更換圖片 TileCanvas 的使用範例"/>
	<mx:HBox width="600" horizontalAlign="center">
		<mx:Label text="圖片 HTTP 路徑 : "/>
		<mx:TextInput id="textInput" width="322"/>
		<mx:Button label="送出" click="clickHandler()"/>
	</mx:HBox>
 
	<!-- 自訂定義的 tileCanvas -->
	<images:tileCanvas id="tc" width="600" height="300" borderStyle="solid" borderThickness="2" borderColor="#B26C28"/>
</mx:Application>

<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" width="420" height="392"
  title="桌面背景">

  <mx:Script>
  <![CDATA[
  import mx.managers.PopUpManager;
  import mx.core.Application;   
  import mx.binding.utils.BindingUtils;   
  [Bindable]
  ?????????????????
  public var backimage:Class;
    
    
  private function DVbtn1_clickHandler(event:MouseEvent):void
    
  {   
  PopUpManager.removePopUp(this);
  }

  private function DVbtn2_clickHandler(event:MouseEvent):void
  {
  PopUpManager.removePopUp(this);
  }
  private function DVbtn3_clickHandler(event:MouseEvent):void
  {   
  Application.application.setStyle("backgroundImage",backimage);
  }

  ]]>
  </mx:Script>
<mx:XML id="ImageXml" source="../src/puremvc/view/AllImage.xml"/>
<mx:XMLListCollection id="xmlListColl" source="{ImageXml.image}"/>
<mx:VBox width="100%" height="100%">
  <mx:HBox width="100%" height="230" horizontalAlign="center" verticalAlign="middle">
  <mx:Image id="img"
  source="{ViewList.selectedItem.@middleImage}"
  maintainAspectRatio="true"
  horizontalAlign="center"/>
  </mx:HBox>
  <mx:HorizontalList width="100%" id="ViewList" dataProvider="{xmlListColl}"
  itemRenderer="puremvc.view.UI.CustomItemRenderer"
  height="90" columnCount="4" columnWidth="80" rowCount="1" rowHeight="90">
  </mx:HorizontalList>
  <mx:HBox width="100%" height="31" horizontalAlign="right">
  <mx:Button label="确定" click="DVbtn1_clickHandler(event)" id="DVbtn1"/>
  <mx:Button label="取消" id="DVbtn2" click="DVbtn2_clickHandler(event)"/>
  <mx:Button label="应用" id="DVbtn3" click="DVbtn3_clickHandler(event)"/>
  </mx:HBox>
  </mx:VBox>
    
</mx:Panel>
然后是xml文件
<?xml version="1.0" encoding="utf-8"?>
<AllImage>
  <image Title="我"
  middleImage="assets/middle1.jpg"
  smallImage="assets/small1.jpg"
  fullImage="assets/full1.jpg"/>
  <image Title="是"
  fullImage="assets/full2.jpg"
  middleImage="assets/middle2.jpg"
  smallImage="assets/small2.jpg" />
  <image Title="一"
  fullImage="assets/full3.jpg"
  middleImage="assets/middle3.jpg"
  smallImage="assets/small3.jpg" />
  <image Title="个"
  fullImage="assets/full4.jpg"
  middleImage="assets/middle4.jpg"
  smallImage="assets/small4.jpg" />
  <image Title="人"
  fullImage="assets/full5.jpg"
  middleImage="assets/middle5.jpg"
  smallImage="assets/small5.jpg" />
  <image Title="吧"
  fullImage="assets/full6.jpg"
  middleImage="assets/middle6.jpg"
  smallImage="assets/small6.jpg" />
  <image Title="日"
  fullImage="assets/full7.jpg"
  middleImage="assets/middle7.jpg"
  smallImage="assets/small7.jpg" />

</AllImage>

public var backimage:Class;改一下。

定义并赋初值
public var backimage:String = new String(Application.application.getStyle("backgroundImage"); 

HorizontalList的selectedItem属性会返回image
private function selectImage():void 
{  
  backimage = selectedItem.fullImage;


加入单击处理
  <mx:HorizontalList width="100%" id="ViewList" dataProvider="{xmlListColl}" 
  itemRenderer="puremvc.view.UI.CustomItemRenderer" 
  height="90" columnCount="4" columnWidth="80" rowCount="1" rowHeight="90" 
  click="selectImage()"> 
  </mx:HorizontalList> 
  <mx:HBox width="100%" height

你可能感兴趣的:(xml)