tag:blogger.com,1999:blog-12467669.post28002493040829001..comments2023-04-29T07:23:25.825-04:00Comments on Jay Fields' Thoughts: ActionScript and Essence vs CeremonyJayhttp://www.blogger.com/profile/14491442812573747680noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-12467669.post-29629273335873472312008-05-14T08:25:00.000-04:002008-05-14T08:25:00.000-04:00Very cool information, thank you. I was hoping som...Very cool information, thank you. I was hoping someone would point me in a better direction.<BR/><BR/>Cheers, JayAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-57379042669392251742008-05-13T19:57:00.000-04:002008-05-13T19:57:00.000-04:00Hey Jay,Having worked with the SWF stack (ActionSc...Hey Jay,<BR/><BR/>Having worked with the SWF stack (ActionScript 1, 2, 3, and the Flex Framework) for the past 8 years, I hear where you're coming from. I bet you would have liked AS2. In the places where AS3 feels like Java and C#, AS2 feels like Ruby. There was less, as you say, "ceremony" with AS2. You should check out haXe [http://www.haxe.org/] - a language with both strong typing and type inference that compiles to Flash Player 6-9 bytecode.<BR/><BR/>Great blog and good post. It's not entirely accurate, though. Your AS3 code example is only more verbose than what you prefer because of the way it's written. In ActionScript, you can definitely pass classes around as objects, and if you decided against that, there's also an eval-like method called getDefinitionByName() [http://livedocs.adobe.com/flex/3/langref/flash/utils/package.html#getDefinitionByName()] that would also work for your illustrated use case. <BR/><BR/>Modified versions of your example code follow...<BR/><BR/><BR/>//----------------------------------------------------<BR/>passing classes around as objects to themselves be used as the "data" for the drop down<BR/>--------------------------8<--------------------------<BR/><?xml version="1.0" encoding="utf-8"?><BR/><mx:Application <BR/> xmlns:mx="http://www.adobe.com/2006/mxml" <BR/> creationComplete="doTypeSelected()"<BR/> ><BR/> <mx:Script><BR/> <[CDATA[<BR/> import mx.collections.ArrayCollection;<BR/><BR/> import views.OptionOne;<BR/> import views.OptionTwo;<BR/><BR/> [Bindable]<BR/> protected var options:ArrayCollection = new ArrayCollection([ <BR/> {label:"1", data:OptionOne},<BR/> {label:"2", data:OptionTwo}<BR/> ]);<BR/><BR/> public function doTypeSelected():void {<BR/> if (typeDetailsBox.numChildren > 0) {<BR/> typeDetailsBox.removeChildAt(0);<BR/> }<BR/><BR/> typeDetailsBox.addChild(new typeCombo.selectedItem.data());<BR/> }<BR/> ]]><BR/> </mx:Script><BR/> <BR/> <mx:HBox><BR/> <mx:ComboBox <BR/> id="typeCombo" <BR/> dataProvider="{options}"<BR/> close="doTypeSelected()" <BR/> /><BR/> <mx:Box id="typeDetailsBox" /><BR/> </mx:HBox><BR/><BR/></mx:Application><BR/><BR/><BR/><-- ~/views/OptionOne.mxml --><BR/><--<BR/><?xml version="1.0" encoding="utf-8"?><BR/><mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"><BR/> <mx:Label text="You chose option 1"/><BR/></mx:HBox><BR/> --><BR/><BR/><-- ~/views/OptionTwo.mxml --><BR/><--<BR/><?xml version="1.0" encoding="utf-8"?><BR/><mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"><BR/> <mx:Label text="You chose option 2"/><BR/></mx:HBox> <BR/>--><BR/>-------------------------->8--------------------------<BR/><BR/><BR/>//----------------------------------------------------<BR/>using ActionScript's eval-like getDefinitionByName() method<BR/>--------------------------8<--------------------------<BR/><?xml version="1.0" encoding="utf-8"?><BR/><mx:Application <BR/> xmlns:mx="http://www.adobe.com/2006/mxml" <BR/> creationComplete="doTypeSelected()"<BR/> ><BR/> <mx:Script><BR/> <[CDATA[<BR/> import flash.utils.getDefinitionByName;<BR/><BR/> import mx.collections.ArrayCollection;<BR/><BR/> import views.OptionOne;<BR/> import views.OptionTwo;<BR/><BR/> protected var optionOneRef:OptionOne;<BR/> protected var optionTwoRef:OptionTwo;<BR/><BR/> [Bindable]<BR/> protected var options:ArrayCollection = new ArrayCollection([ <BR/> {label:"1", data:"views.OptionOne"},<BR/> {label:"2", data:"views.OptionTwo"}<BR/> ]);<BR/><BR/> public function doTypeSelected():void {<BR/> if (typeDetailsBox.numChildren > 0) {<BR/> typeDetailsBox.removeChildAt(0);<BR/> }<BR/><BR/> var ClassRef:Class = getDefinitionByName(typeCombo.selectedItem.data) as Class;<BR/> typeDetailsBox.addChild(new ClassRef());<BR/> }<BR/> ]]><BR/> </mx:Script><BR/> <BR/> <mx:HBox><BR/> <mx:ComboBox <BR/> id="typeCombo" <BR/> dataProvider="{options}"<BR/> close="doTypeSelected()" <BR/> /><BR/> <mx:Box id="typeDetailsBox" /><BR/> </mx:HBox><BR/><BR/></mx:Application><BR/><BR/><BR/><-- ~/views/OptionOne.mxml --><BR/><--<BR/><?xml version="1.0" encoding="utf-8"?><BR/><mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"><BR/> <mx:Label text="You chose option 1"/><BR/></mx:HBox><BR/> --><BR/><BR/><-- ~/views/OptionTwo.mxml --><BR/><--<BR/><?xml version="1.0" encoding="utf-8"?><BR/><mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"><BR/> <mx:Label text="You chose option 2"/><BR/></mx:HBox> <BR/>--><BR/>-------------------------->8--------------------------<BR/><BR/><BR/>//----------------------------------------------------<BR/>using regular old object instances<BR/>--------------------------8<--------------------------<BR/><?xml version="1.0" encoding="utf-8"?><BR/><mx:Application <BR/> xmlns:mx="http://www.adobe.com/2006/mxml" <BR/> creationComplete="doTypeSelected()"<BR/> ><BR/> <mx:Script><BR/> <[CDATA[<BR/> import mx.collections.ArrayCollection;<BR/><BR/> import views.OptionOne;<BR/> import views.OptionTwo;<BR/><BR/> [Bindable]<BR/> protected var options:ArrayCollection = new ArrayCollection([ <BR/> {label:"1", data:new OptionOne()},<BR/> {label:"2", data:new OptionTwo()}<BR/> ]);<BR/><BR/> public function doTypeSelected():void {<BR/> if (typeDetailsBox.numChildren > 0) {<BR/> typeDetailsBox.removeChildAt(0);<BR/> }<BR/><BR/> typeDetailsBox.addChild(typeCombo.selectedItem.data as DisplayObject);<BR/> }<BR/> ]]><BR/> </mx:Script><BR/> <BR/> <mx:HBox><BR/> <mx:ComboBox <BR/> id="typeCombo" <BR/> dataProvider="{options}"<BR/> close="doTypeSelected()" <BR/> /><BR/> <mx:Box id="typeDetailsBox" /><BR/> </mx:HBox><BR/><BR/></mx:Application><BR/><BR/><BR/><-- ~/views/OptionOne.mxml --><BR/><--<BR/><?xml version="1.0" encoding="utf-8"?><BR/><mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"><BR/> <mx:Label text="You chose option 1"/><BR/></mx:HBox><BR/> --><BR/><BR/><-- ~/views/OptionTwo.mxml --><BR/><--<BR/><?xml version="1.0" encoding="utf-8"?><BR/><mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"><BR/> <mx:Label text="You chose option 2"/><BR/></mx:HBox> <BR/>--><BR/>-------------------------->8--------------------------<BR/><BR/><BR/>Don't get me wrong. I completely agree that Ruby is a lower ceremony language that ActionScript, but I felt obliged to point out that AS isn't really as high a ceremony language as your making it out to be. Honestly, you can make AS pretty loose if you use dynamic classes and setting the MXMLC -strict flag to "false". Some links you might be interested in follow:<BR/><BR/>ActionScript's Class :: http://livedocs.adobe.com/flex/3/langref/Class.html<BR/>getDefinitionByName() :: http://livedocs.adobe.com/flex/3/langref/flash/utils/package.html#getDefinitionByName()<BR/>getQualifiedSuperclassName() :: http://livedocs.adobe.com/flex/3/langref/flash/utils/package.html#getQualifiedSuperclassName()<BR/>registerClassAlias() :: http://livedocs.adobe.com/flex/3/langref/flash/net/package.html#registerClassAlias()<BR/>getClassByAlias() :: http://livedocs.adobe.com/flex/3/langref/flash/net/package.html#getClassByAlias()<BR/>As3Eval (ActionScript 3 eval library) :: http://eval.hurlant.com/<BR/>Dynamic Classes in ActionScript :: http://livedocs.adobe.com/flex/3/html/03_Language_and_Syntax_10.html<BR/>MXMLC compiler options :: http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=compilers_123_24.html<BR/>Francis Cheng's blog (AS language designer) :: http://blogs.adobe.com/fcheng/<BR/><BR/>Enjoy, and keep up the great blog!<BR/><BR/><BR/>AliUnknownhttps://www.blogger.com/profile/04934072041003238718noreply@blogger.comtag:blogger.com,1999:blog-12467669.post-80350390729600638542008-05-13T18:58:00.000-04:002008-05-13T18:58:00.000-04:00... I realized I should've clarified...the class r...... I realized I should've clarified...the class references can then be instantiated where you need them. For example:<BR/><BR/>var classRef:Object=MovieClip; //The standard MovieClip class reference<BR/>var newClip:MovieClip=new classRef(); //Creates a new MovieClip<BR/><BR/>The same can be done in a method:<BR/><BR/>public function someFunc(classRef:Object) {<BR/> var myInstance:*=new classRef();<BR/>}<BR/><BR/>Again, I go over all this and *much* more on http://www.peabee.com/<BR/><BR/>Hope to see you there!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-43944676084473352012008-05-13T18:55:00.000-04:002008-05-13T18:55:00.000-04:00Hi Jay,You mention that you'd like to pass classes...Hi Jay,<BR/><BR/>You mention that you'd like to pass classes around as objects. Well, in ActionScript 3 that's perfectly valid...you can pass a class reference (not an instance, a proper class prototype reference) as you would any other variable or parameter.<BR/><BR/>The best way to store references to classes is to type the associated variables as objects or simply untyped:<BR/><BR/>var classRef:Object=someClass;<BR/>-or-<BR/>var classRef:*=someClass;<BR/><BR/>Glad to hear you've had positive experiences with ActionScript. If you (or any of your readers) are looking for more indepth explanations of ActionScript or want to be able to use the Flash IDE (nothing against Flex, just not my cup of tea), drop on by http://www.peabee.com/<BR/><BR/>Cheers,<BR/>PatrickAnonymousnoreply@blogger.com