In a previous post, “Using the Flex SDK with Flash CS4″, we saw how you could use the [Embed] metadata and the Flex SDK to embed assets within your Flash applications (instead of manually importing assets into the Library panel).
The following example shows how you can use the ObjectUtil class from the Flex SDK to help debug your Flash applications.
Full code after the jump.
// ActionScript 3.0 import mx.utils.ObjectUtil; var fontArr:Array = Font.enumerateFonts(true); fontArr.sortOn("fontName"); trace(ObjectUtil.toString(fontArr));
By default the previous example genrates the following compiler errors:
| Description | Source |
|---|---|
| 1172: Definition mx.utils:ObjectUtil could not be found. | import mx.utils.ObjectUtil; |
| 1172: Definition mx.utils:ObjectUtil could not be found. | import mx.utils.ObjectUtil; |
| 1120: Access of undefined property ObjectUtil. | trace(ObjectUtil.toString(fontArr)); |
In order to use some classes (such as ObjectUtil) that are not in the flex.swc file, you need to include other .SWC files (or specify a directory containing .SWC files).
Flash CS4 only ships with the flex.swc (Flex 3.0.2.2113):
- PC: C:\Program Files\Adobe\Adobe Flash CS4\Common\Configuration\ActionScript 3.0\libs\flex_sdk_3\frameworks\libs\
If you need to use classes not found in flex.swc, you need to download the a new build of the Adobe Flex SDK and point to the SDK’s \libs\ folder (or individual .SWC files). If you have Flex Builder 3 installed, you can point to Flex Builder’s various SDKs (see C:\Program Files\Adobe\Flex Builder 3\sdks\ for a list of preinstalled SDKs).
In Flash CS4, select File > Publish Settings to display the Publish Settings dialog box. In the Flash tab and click the Settings button next to the ActionScript 3.0 dropdown display the Advanced ActionScript 3.0 Settings dialog box. Switch to the Library path tab, delete the “$(FlexSDK)/frameworks/libs/flex.swc” entry, and click the Browse to Path button to bring up a Browse For Folder dialog box which allows you to seelect the path that contains the SWC files you wish to import. If you’re using Flex Builder 3.0.2 (if you have a previous version of Flex Builder installed, see “Upgrading to Flex Builder 3.0.2″ on FlexExamples.com), navigate to the C:\Program Files\Adobe\Flex Builder 3\sdks\3.2.0\frameworks\libs\ directory and click the OK button. If you dont have Flex Builder installed, or want to use the most recent version of the Flex 3 or Flex Gumbo SDKs, you can download nightly builds of the Flex SDK from the Adobe Open Source site (Download Flex 3 or Download Flex 4). After downloading the Flex SDK, browse to the \frameworks\libs\ directory and click the OK button.
After pointing to the /libs/ folder, you should be able to successfully run the following code:
// ActionScript 3.0 import mx.utils.ObjectUtil; var fontArr:Array = Font.enumerateFonts(true); fontArr.sortOn("fontName"); trace(ObjectUtil.toString(fontArr));
Depending on the fonts currently installed on your operating system, you should see the following output:
(Array)#0
[0] (flash.text::Font)#1
fontName = "04b08"
fontStyle = "regular"
fontType = "device"
[1] (flash.text::Font)#2
fontName = "Adobe Caslon Pro"
fontStyle = "regular"
fontType = "device"
[2] (flash.text::Font)#3
fontName = "Adobe Caslon Pro Bold"
fontStyle = "regular"
fontType = "device"
...
[278] (flash.text::Font)#279
fontName = "ZapfChancery"
fontStyle = "regular"
fontType = "device"
[279] (flash.text::Font)#280
fontName = "ZapfDingbats"
fontStyle = "regular"
fontType = "device"
The ObjectUtil.toString() method recursively loops over any object and displays all properties within the Object. This can be very useful when debugging scripts or if you want to see what properties are set on a display object.
{ 1 comment… read it below or add one }
Oh god i love it thank you!