The following example shows how you can create a simple JSFL file which loops over each of the items in your Flash document’s Library panel and displays the item’s name and item type in the Output panel.
Full code after the jump.
// JSFL var items = fl.getDocumentDOM().library.items; fl.outputPanel.clear(); if (items.length > 0) { for each (var item in items) { fl.trace(item.name + " (" + item.itemType + ")"); } } else { fl.trace("Library is empty"); }
If you wanted to sort the items in alphabetical order, you need to call the sort() method on the items array and pass a custom sort function, as seen in the following example:
// JSFL var items = fl.getDocumentDOM().library.items; items.sort(textCaseInsensitive); fl.outputPanel.clear(); if (items.length > 0) { for each (var item in items) { fl.trace(item.name + " (" + item.itemType + ")"); } } else { fl.trace("Library is empty"); } function textCaseInsensitive(a, b) { var aValue = a.name.toLowerCase(); var bValue = b.name.toLowerCase(); if (aValue > bValue) { return 1; } else if (aValue < bValue) { return -1; } else { return 0; } }
This would produce beautifully sorted output similar to the following in your Flash Output panel (depending on what you had in your Flash document’s library):
Button (component)
Component Assets (folder)
Component Assets/_private (folder)
Component Assets/_private/Component_avatar (movie clip)
Component Assets/_private/ComponentShim (compiled clip)
Component Assets/ButtonSkins (folder)
Component Assets/ButtonSkins/Button_disabledSkin (movie clip)
Component Assets/ButtonSkins/Button_downSkin (movie clip)
Component Assets/ButtonSkins/Button_emphasizedSkin (movie clip)
Component Assets/ButtonSkins/Button_overSkin (movie clip)
Component Assets/ButtonSkins/Button_selectedDisabledSkin (movie clip)
Component Assets/ButtonSkins/Button_selectedDownSkin (movie clip)
Component Assets/ButtonSkins/Button_selectedOverSkin (movie clip)
Component Assets/ButtonSkins/Button_selectedUpSkin (movie clip)
Component Assets/ButtonSkins/Button_upSkin (movie clip)
Component Assets/Shared (folder)
Component Assets/Shared/focusRectSkin (movie clip)
FLVPlayback (compiled clip)
Font 1 (font)
Symbol 1 (movie clip)
Symbol 2 (button)
Symbol 3 (graphic)
Symbol 4 (movie clip)
TextLayout (compiled clip)
untitled folder 1 (folder)
Video 1 (video)
Recent Posts
- Getting started with the TLFTextField class in ActionScript 3.0 and Flash CS5
- Adding tick marks to a Slider control in Flash using ActionScript 3.0
- Creating a vertical Slider control in Flash using ActionScript 3.0
- Creating a custom context menu item in Flash using ActionScript 3.0
- Rotating a Sprite object around its x-axis in Flash using ActionScript 3.0 and Flash Player 10
- Detecting when the user changes the color in a ColorPicker control in Flash using ActionScript 3.0
- Getting the currently selected color as a hexadecimal value on a ColorPicker control in Flash using ActionScript 3.0
- Toggling the text field on the ColorPicker control in Flash using ActionScript 3.0
- Creating a vertical Slider control in Flash using ActionScript 3.0
- Setting the number of columns on a ColorPicker control in Flash using ActionScript 3.0
Categories
- Bitmap (1)
- Components (72)
- Button (19)
- CheckBox (2)
- ColorPicker (6)
- ComboBox (1)
- DataGrid (8)
- FLVPlayback (7)
- Label (9)
- ProgressBar (2)
- Slider (3)
- TextArea (1)
- TextInput (7)
- UILoader (7)
- ContextMenu (1)
- Embed (4)
- ExternalInterface (2)
- Flex (7)
- Font (2)
- General (5)
- Graphics (2)
- JSFL (14)
- Loader (3)
- LoadVars (3)
- Microphone (1)
- migration (12)
- MovieClip (1)
- MovieClipLoader (1)
- Sound (2)
- TextField (1)
- TLFTextField (1)
- TransitionManager (1)
- Tween (1)
- Uncategorized (1)
- URLLoader (4)
- URLVariables (1)
- Video (1)
- XML (2)
Advertising

