2 Replies Latest reply on Sep 25, 2006 3:08 AM by Ed_Syrett

    Enhancement requests

    Ed_Syrett
      I've used OO languages including C++ and C# for more years that I can remember, so I think I have some idea of what is useful or not in an OO language. Flex 2 comes mighty close to offering a full-featured environment, but I've come across some issues, so here they are all in one place. I've written this in the hope that someone at Adobe will read these and put them into some sort of wish list for consideration in the next release.

      Dynamic Creation
      Flex Builder doesn't currently compile .as files unless they are referenced. This is unlike every other development environment I have worked with and means that getDefinitionByName() won't find the class definition unless something actually uses that class (which kinda defeats the object of getDefinitionByName() don't you think?)

      My reply to this on another topic

      XML Parsing
      e4x offers the capability to search on sub-nodes, e.g

      myXML.item.(@quantity == "45")

      But this only works if each <item> node has an attribute called 'quantity' (otherwise it blows up) Although this is actually a documented feature, it still seems to defeat the object of the functionality, i.e. dig out all the <item> elements with an attribute called 'quantity' It's clearly not doing that because the programmer has to pre-filter the list.

      My reply to this on another topic.

      Reserved Words
      The documentation says:

      quote:

      Reserved words are words that you cannot use as identifiers in your code because the words are reserved for use by ActionScript.


      I assume that identifier just means function names and variable names, although I couldn't find any confirmation of that in the documentation.

      The following code throws an error:

      public function delete()
      {
      }


      ..because obviously it contains the reserved word delete. But this fragment is obviously a function name and I don't believe the compiler should have any problem recognising it as such. The only valid excuse I can think of for the compiler to complain is that there is already a delete method on the object, in which case I would want to override it. I really did want a delete method on this particular class as it's a model object and I want a function to delete the object from the database. I'm sure there are other cases where somebody might want to use a "reserved word" as a function name. For example:

      • import - to import a file....
      • default - to return a default value...
      • switch - to switch from something to something else....




        Enumerations
        I think the lack of support for an enum type is a big shortcoming and it goes without saying that most if not all languages have something approaching it. The documentation suggests using a set of const strings within a class, i.e.

        public final class PrintJobOrientation {
        public static const LANDSCAPE:String = "landscape";
        public static const PORTRAIT:String = "portrait";
        }

        But then I can pass any old string to a var or function that actually requires a PrintJobOrientation.

        The documentation also suggest the slightly better alternative:

        public final class Day {
        public static const MONDAY:Day = new Day();
        public static const TUESDAY:Day = new Day();
        ...etc...
        }

        This is a nice idea, and it does enforce type-safety. But when you pass a Day object into a function, the variables window will show you that your parameter is an instance of Day, but you have no indication which of the enums was passed in....!!!!

        I got around this by adding a name var to the enum class, i.e.

        public class TestEnum
        {
        public var _name:String;
        public function TestEnum(name:String)
        {
        _name = name ;
        }

        public static const TEST_VALUE:TestEnum = new TestEnum("TEST_ENUM");
        }

        ..so now I can look at the _name attribute to see which enum value it is. It works, but I still believe that I'm having to work around something that the compiler should provide.

        That's all for now folks!






        • 1. Re: Enhancement requests
          Ed_Syrett Level 1
          Private members in the variables window
          Whilst doing some research for the Enums bit above, I noticed something else....

          Here's my test application....

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()">
          <mx:Script>
          <![CDATA[
          import Enumerations.TestEnum;

          public function initApp():void
          {
          anyFunc(TestEnum.TEST_VALUE);
          }

          private function anyFunc(te:TestEnum):void
          {
          // Put a break point on the next line.
          trace(te);
          }

          ]]>
          </mx:Script>
          </mx:Application>

          ..and the implementation of the TestEnum class..

          package Enumerations
          {
          public class TestEnum
          {
          private var _name:String;

          public function TestEnum(name:String)
          {
          _name = name ;
          }

          public static const TEST_VALUE:TestEnum = new TestEnum("TEST_ENUM");
          }
          }

          If you debug this app and put a breakpoint where indicated on "trace(te);", the variables window shows nothing for the te parameter, which is kinda worrying since it has a private var _name. I have to make _name public for it to show in the variables window, and I think that's a bug....

          • 2. Re: Enhancement requests
            Ed_Syrett Level 1
            Singletons
            By Singleton, I refer to the design pattern as described in the Gang Of Four book (Gamma et al). This describes how to produce a class that can only have one instance. In their implementation, the compiler will throw an error at any attempt to instantiate more than one instance.

            Unfortunately, in Actionscript you can't do that, and the reason is that you cannot make a class constructor private. Because the constructor is always public, you can go ahead and create it as many times as you like and the compiler will not complain. The best you can do is put in runtime checks, e.g.


            public class TestSingleton
            {
            private static var _instance:TestSingleton;

            public function TestSingleton()
            {
            if (_instance != null)
            throw("Only one instance of TestSingleton is allowed...");

            _instance = this ;
            }
            }



            But the value of the Singleton is drastically reduced by this. The check for the subsequent instance happens at runtime, and IMHO it would be far better to get the compiler to do that job for me. So if you see any code in ActionScript that says it's a Singleton, it isn't a proper Singleton, merely the next best thing.