FLEX中加载图片失败时自动加载默认图片.
就是使用图片组件的brokenImageSkin
样式,
这个样式非常方便,一般用在产品列表,新品图片没有出来,先用一张缩略的“尚没有展品照片”显示,如果有,就用产品图片自动替换掉这个“尚没有展品照片”的图片。
<?xml version="1.0"?>
<!-- http://blog.flexexamples.com/2008/03/02/setting-a-custom-broken-image-skin-for-the-image-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private var alert:Alert;
private function image_ioError(evt:IOErrorEvent):void {
alert = Alert.show(evt.text, evt.type);
}
private function loadImage(src:String):void {
image.source = src;
}
]]>
</mx:Script>
<mx:Style>
Image {
brokenImageSkin: Embed("assets/flex_logo.jpg");
}
</mx:Style>
<mx:ApplicationControlBar dock="true">
<mx:Button label="Good"
click="loadImage('assets/flashplayer_icon.jpg');" />
<mx:Button label="Bad"
click="loadImage('assets/404.gif');" />
</mx:ApplicationControlBar>
<mx:Image id="image"
maintainAspectRatio="true"
scaleContent="false"
width="200"
height="200"
ioError="image_ioError(event);" />
</mx:Application>
<!-- http://blog.flexexamples.com/2008/03/02/setting-a-custom-broken-image-skin-for-the-image-control-in-flex/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private var alert:Alert;
private function image_ioError(evt:IOErrorEvent):void {
alert = Alert.show(evt.text, evt.type);
}
private function loadImage(src:String):void {
image.source = src;
}
]]>
</mx:Script>
<mx:Style>
Image {
brokenImageSkin: Embed("assets/flex_logo.jpg");
}
</mx:Style>
<mx:ApplicationControlBar dock="true">
<mx:Button label="Good"
click="loadImage('assets/flashplayer_icon.jpg');" />
<mx:Button label="Bad"
click="loadImage('assets/404.gif');" />
</mx:ApplicationControlBar>
<mx:Image id="image"
maintainAspectRatio="true"
scaleContent="false"
width="200"
height="200"
ioError="image_ioError(event);" />
</mx:Application>
来自:http://blog.flexexamples.com/2008/03/02/setting-a-custom-broken-image-skin-for-the-image-control-in-flex/