Flex中Image加载图片出错时显示默认图片的几种方法
Flex中Image加载图片出错时显示默认图片的方法主要有以下几种:
方法一:利用 brokenImageSkin 风格显示一个默认的图,只需设置CSS就行了,如下:
<mx:Style>
Image {
brokenImageSkin: Embed("assets/404.jpg");
}
</mx:Style>
方法二:监听Image组件的IOErrorEvent.IO_ERROR事件,代码如下:
private function errorHandler():void
{
image.source = "assets/404.jpg";
}
<mx:Image id="image" source="http://不存在.jpg" ioError="errorHandler()"/>
方法三:继承Image类,覆盖其set source方法,如下:
override public function set source(value:Object):void
{
if(!value || value == ""){
value = "assets/404.jpg";
}
super.source = value;
}
推荐使用第三种方法,因为第一种方法跟第二种方法有个共同的缺点,如下情况:
<mx:Image id="image" source="" ioError="errorHandler()"/>
此时无论是第一种方法还是第二种方法都不会显示默认图片,而第三种方法就可以解决这个问题。
第三种方法具体实现及使用方法如下:
MyImage.as
package
{
import flash.events.IOErrorEvent;
import mx.controls.Image;
public class MyImage extends Image
{
private var defaultImage:String = "assets/404.jpg";
public function MyImage()
{
this.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
}
override public function set source(value:Object):void
{
if(!value || value == ""){
value = defaultImage;
}
super.source = value;
}
private function ioErrorHandler(event:IOErrorEvent):void
{
super.source = defaultImage;
}
}
}
Main.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">
<local:MyImage id="image" source=""/>
</mx:Application>
推荐使用第三种方法。
相关文档:
·下面介绍Flex与.NET的WebService的数据通信知识点;包括连接WebService,远程调用WebService方法,给WebService方法传递参数等相关知识点。
<mx:WebServiceid="dataService"
wsdl="http://localhost/FlashFlex/DataWebService.asmx?wsdl"
useProxy="false">
<mx:ope ......
Flex Builder 3 下载安装与注册码(转)
Flex Builder 3 正式版,发布于中国时间 2008 年 2 月 25 日;
下载地址一:
http://download.macromedia.com/pub/flex/flex_builder/FB3_win.exe
大小: 424 MB ;未进行压缩的 Flex Builder 3 安装文件
不用注册登录,可以直接下载。
下载地址二:
http://trials.adobe.com/ ......
今天刚接触Flex,但是当我把代码编写完成运行的时候报下了如下错误:
C:\WINDOWS\system32\Macromed\Flash\Flash10e.ocx
Flex Builder cannot locate the required debugger version of Flash Player.
You might need to install the debugger version of Flash Player 9 or
reinstall Flex Builder.
Do you want to ......
一、准备工作:
所需要的软件:
Tomcat 5: http://tomcat.apache.org/
FlexBuilder3 beta2 插件版: FB3_WWEJ_Plugin
Eclipse 3.3 : www.eclipse.org
或者
MyEclipse 6.0:http://www.myeclipseide.com/
Blazeds.war:http://flexorg.wip3.adobe.com/blazeds/3.0.x/milestone/3978/blazeds-bin-3.2.0.39 ......
Are you running your Flex Application and continually getting the error below?
"Flex Builder cannot locate the required version of the Flash Player. You might need to install Flash Player 9 or reinstall Flex Builder. Do you want to try to run your application with the current version?"
Description ......