9
Ever find that you have about 4350823498 different MovieClips in your library that you would like to ‘attach’ ? Yeah yeah it’s not attach in AS3 but you know what I mean! Anyways this was inspired by a code snippet I first read on Blitz Agency’s blog but have seen in many shapes and form since. So here’s my version of using getDefinitionByName with string constants to help centralize things.
Update: I should point out, it’s important to remember that this is especially useful when used on MovieClips loaded from a separate assets SWF. When you’re working with only one SWF, you could just call the class directly. Thanks to the folks at ActionScript.org forums for reminding me :)
Also: Flex Users will need a slightly different method of either packaging SWCs or using a combination of registerClassAlias and getClassByAlias. More on that in a later post.
package com.pj_co.managers { import flash.display.DisplayObject; import flash.utils.getDefinitionByName; /** * Central list of library items attached in code * @usage provides a runtime method for access dynamicly loaded assets from the lib * @author patrick cousins */ public class LibraryManager { public static const ORANGE_LARGE : String = "LargeRollGraphicsOrange"; public static const GREEN_LARGE : String = "LargeRollGraphicsGreen"; public static const TEAL_LARGE : String = "LargeRollGraphicsTeal"; public static const PURPLE_LARGE : String = "LargeRollGraphicsPurple"; public static const BLUE_LARGE : String = "LargeRollGraphicsBlue"; public function LibraryManager() { } public static function getAsset ( assetLinkageID : String ) : DisplayObject { var asset : Class = Class ( getDefinitionByName ( assetLinkageID ) ) ; return new asset() as DisplayObject; } } }
filed under: Scripts | permalink
Leave a Reply
You must be logged in to post a comment.
