bgchange

7550 ワード

Apple.aplication.set Style(「background Color」、「胭00 FF 00」)
<?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:クラス;直してください
定義して初値を付与します
public var backimage:String=new String(Apple.appration.get Style); 
HorizontalListのselected Item属性はイメージに戻ります。
prvate function selectImage():void 
{  
  backimage=selectedItem.fullImage;

クリック処理に追加
    itemRenderer=「puremvc.view.UU.C.ustomItemRenderer」 
  height=「90」columnCount=「4」columnWidth=「80」rowCount=「1」rowHeight=「90」 
  click=「selectImage()」