Flex提供了出色的調試Flex代碼的能力,Flash Builder 4具有出色的內置調試器和調試透視圖支持。
在調試模式下,Flex應用程式運行在Flash Builder 4中內置的Flash Player調試器版本上,該版本支持調試功能。
因此開發人員可以在Flash Builder中獲得一個簡單且內置的調試配置
在本文中,我們將演示如何使用Flash Builder調試Flex客戶機代碼。我們將完成以下任務
- Set break points in the code and see them in Breakpoint Explorer.
- Step through the code line by line during debugging.
- View the values of variable.
- Inspect the values of all the variables.
- Inspect the value of an expression.
- Display the stack frame for suspended threads.
Debugging Example
Step | Description |
---|---|
1 | Create a project with a name HelloWorld under a package com.tutorialspoint.client as explained in the Flex - Create Application chapter. |
2 | Modify HelloWorld.mxml as explained below. Keep rest of the files unchanged. |
3 | Compile and run the application to make sure business logic is working as per the requirements. |
<?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" width = "100%" height = "100%" minWidth = "500" minHeight = "500" initialize = "application_initializeHandler(event)"> <fx:Style source = "/com/tutorialspoint/client/Style.css" /> <fx:Script> <![CDATA[ import mx.controls.Alert; import mx.events.FlexEvent; protected function btnClickMe_clickHandler(event:MouseEvent):void { Alert.show("Hello World!"); } protected function application_initializeHandler(event:FlexEvent):void { lblHeader.text = "My Hello World Application"; } ]]> </fx:Script> <s:BorderContainer width = "500" height = "500" id = "mainContainer" styleName = "container"> <s:VGroup width = "100%" height = "100%" gap = "50" horizontalAlign = "center" verticalAlign = "middle"> <s:Label id = "lblHeader" fontSize = "40" color = "0x777777" styleName = "heading" /> <s:Button label = "Click Me!" id = "btnClickMe" click = "btnClickMe_clickHandler(event)" styleName = "button" /> </s:VGroup> </s:BorderContainer> </s:Application>
完成所有更改後,讓我們以正常模式編譯,就像在flex-create application一章中那樣。
Step 1 - Place Breakpoints
在HelloWorld.mxml的應用程式初始化處理程序的第一行放置斷點
Step 2 - Debug Application
現在,單擊「調試應用程式」菜單,然後選擇「HelloWorld」應用程式調試應用程式。
如果一切正常,應用程式將在瀏覽器中啓動,您將在Flash Builder控制台中看到以下調試日誌。
[SWF] \HelloWorld\bin-debug\HelloWorld.swf - 181,509 bytes after decompression [SWF] \HelloWorld\bin-debug\HelloWorld.swf\[[DYNAMIC]]\1 - 763,122 bytes after decompression [SWF] \HelloWorld\bin-debug\HelloWorld.swf\[[DYNAMIC]]\2 - 1,221,837 bytes after decompression [SWF] \HelloWorld\bin-debug\HelloWorld.swf\[[DYNAMIC]]\3 - 1,136,788 bytes after decompression [SWF] \HelloWorld\bin-debug\HelloWorld.swf\[[DYNAMIC]]\4 - 2,019,570 bytes after decompression [SWF] \HelloWorld\bin-debug\HelloWorld.swf\[[DYNAMIC]]\5 - 318,334 bytes after decompression
一旦應用程式啓動,您將看到焦點放在Flash Builder斷點上,因爲我們已經將斷點放在Application_initialize Handler方法的第一行。
您可以看到掛起線程的stacktrace。
可以看到表達式的值。
您可以看到放置的斷點列表。
現在繼續按F6,直到到達最後一行application_initializeHandler()方法。作爲功能鍵的參考,F6逐行檢查代碼,F5步驟進一步深入,F8將繼續應用。現在您可以看到application_initializeHandler()方法的所有變量的值列表。
現在您可以看到flex代碼的調試方式與Java應用程式的調試方式相同。將斷點放置到任意行並使用flex的調試功能。