当前位置: 代码迷 >> Web开发 >> Flex中错误捕捉有关问题
  详细解决方案

Flex中错误捕捉有关问题

热度:304   发布时间:2012-05-08 22:09:41.0
Flex中异常捕捉问题
刚学flex 不知道怎么去捕捉异常,用try和catch没反应。向各位高手请教……
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
xmlns:s="library://ns.adobe.com/flex/spark" 
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
creationComplete="IOErrorEvent.IO_ERROR,Division"
>
<s:layout>
<s:BasicLayout/>
</s:layout>

<fx:Script>
<![CDATA[
import mx.controls.Alert;
protected function btnOperation_clickHandler(event:MouseEvent):void
{
try
{
var a:int = 30;
var b:int = 6;
var c:int = a/(b-6);
Alert.show(c.toString(),"结果");
}
catch(e:Error)
{
Alert.show(e.message);
}
}
]]>
</fx:Script>

<fx:Declarations>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<fx:Script>
<![CDATA[
private function Division(event:IOErrorEvent):void{  
Alert.show("进入监听异常捕捉!");  
}
]]>
</fx:Script>

<mx:Button label="除零的异常" id="btnOperation" verticalCenter="0" horizontalCenter="0" click="btnOperation_clickHandler(event)"/>

</s:Application>


------解决方案--------------------
http://forum.csdn.net/SList/Flex/