bgchange

Application.application.setStyle("backgroundColor", "#00FF00");



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();
}
}
]]>





private function clickHandler():void{
this.tc.setBackground(this.textInput.text);
}
]]>













title="桌面背景">


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);
}

]]>





source="{ViewList.selectedItem.@middleImage}"
maintainAspectRatio="true"
horizontalAlign="center"/>

itemRenderer="puremvc.view.UI.CustomItemRenderer"
height="90" columnCount="4" columnWidth="80" rowCount="1" rowHeight="90">









然后是xml文件


middleImage="assets/middle1.jpg"
smallImage="assets/small1.jpg"
fullImage="assets/full1.jpg"/>
fullImage="assets/full2.jpg"
middleImage="assets/middle2.jpg"
smallImage="assets/small2.jpg" />
fullImage="assets/full3.jpg"
middleImage="assets/middle3.jpg"
smallImage="assets/small3.jpg" />
fullImage="assets/full4.jpg"
middleImage="assets/middle4.jpg"
smallImage="assets/small4.jpg" />
fullImage="assets/full5.jpg"
middleImage="assets/middle5.jpg"
smallImage="assets/small5.jpg" />
fullImage="assets/full6.jpg"
middleImage="assets/middle6.jpg"
smallImage="assets/small6.jpg" />
fullImage="assets/full7.jpg"
middleImage="assets/middle7.jpg"
smallImage="assets/small7.jpg" />


public var backimage:Class;改一下。

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

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

加入单击处理
itemRenderer="puremvc.view.UI.CustomItemRenderer"
height="90" columnCount="4" columnWidth="80" rowCount="1" rowHeight="90"
click="selectImage()">

你可能感兴趣的:(Flex,XML)