{"id":202,"date":"2008-05-06T05:31:41","date_gmt":"2008-05-06T13:31:41","guid":{"rendered":"http:\/\/www.ericfeminella.com\/blog\/2008\/05\/06\/package-level-function-closures-in-actionscript\/"},"modified":"2012-03-04T23:32:10","modified_gmt":"2012-03-05T04:32:10","slug":"package-level-function-closures-in-actionscript","status":"publish","type":"post","link":"https:\/\/www.ericfeminella.com\/blog\/2008\/05\/06\/package-level-function-closures-in-actionscript\/","title":{"rendered":"Package-level function closures in ActionScript"},"content":{"rendered":"<p>Package-level <a href=\"http:\/\/www.jibbering.com\/faq\/faq_notes\/closures.html\" target=\"_blank\">function closures<\/a> are very useful for creating generalized functionality which does not require a class (static methods) or instance of a class (instance methods). <\/p>\n<p>Unlike static and instance methods package-level function closures are not associated with a class or instance of a class but rather with a package. There are no syntactical differences between package-level functions and static or instance methods.<\/p>\n<p>Package-level functions are for the most part utility functions; for instance the <a href=\"http:\/\/livedocs.adobe.com\/flash\/9.0\/ActionScriptLangRefV3\/flash\/utils\/package.html\" target=\"_blank\">flash.utils<\/a> package contains a number of package-level functions, the most common of which are <a href=\"http:\/\/livedocs.adobe.com\/flash\/9.0\/ActionScriptLangRefV3\/flash\/utils\/package.html#describeType()\" target=\"_blank\">describeType()<\/a>, <a href=\"http:\/\/livedocs.adobe.com\/flash\/9.0\/ActionScriptLangRefV3\/flash\/utils\/package.html#getDefinitionByName()\" target=\"_blank\">getDefintionByName()<\/a>, <a href=\"http:\/\/livedocs.adobe.com\/flash\/9.0\/ActionScriptLangRefV3\/flash\/utils\/package.html#getTimer()\" target=\"_blank\">getTimer()<\/a> and so forth.<\/p>\n<p>Package-level function closures are created by defining a function directly inside the body of a package (where class and interfaces are defined), as can be seen in the following example:<\/p>\n<pre lang=\"actionscript\">\r\n\r\npackage com.ericfeminella.display\r\n{\r\nimport flash.display.Bitmap;\r\nimport flash.display.IBitmapDrawable;\r\nimport mx.graphics.ImageSnapshot;\r\n\t\t\r\npublic function createSnapShot(target:IBitmapDrawable) : Bitmap \r\n{\r\n    return new Bitmap( ImageSnapshot.captureBitmapData( target ) );\r\n}\r\n}<\/pre>\n<p>Calling a package level function is straightforward, simply import the function just as you would a class or interface and then invoke the function directly&#8230;<\/p>\n<pre lang=\"actionscript\">\r\n\r\n\/\/ import package function\r\nimport com.ericfeminella.display.createSnapShot;\r\n\r\n\/\/ once imported the function can be invoked\r\ncreateSnapShot( this );<\/pre>\n<p>Typically you will find that most functionality can be grouped to a Class or an instance object, however on occasion you may identify specific functionality which is common to packaged functionality as opposed to a specific object, and in these cases utilizing package-level functions is a great option.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Package-level function closures are very useful for creating generalized functionality which does not require a class (static methods) or instance of a class (instance methods). Unlike static and instance methods package-level function closures are not associated with a class or instance of a class but rather with a package. There are no syntactical differences between package-level functions and static or&#8230; <a class=\"read-more\" href=\"https:\/\/www.ericfeminella.com\/blog\/2008\/05\/06\/package-level-function-closures-in-actionscript\/\">Continue Reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[31,35],"tags":[],"class_list":["post-202","post","type-post","status-publish","format-standard","hentry","category-oop","category-software-engineering"],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/posts\/202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/comments?post=202"}],"version-history":[{"count":0,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/posts\/202\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/media?parent=202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/categories?post=202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ericfeminella.com\/blog\/wp-json\/wp\/v2\/tags?post=202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}