5 Replies Latest reply on Sep 28, 2010 8:53 AM by Devtron

    flex OOP

    jagguy999 Level 1

      I have an example below I want to modify


      1)IN flex actionscript when I create classes does it have the constructors like in .net?


      I want to create a button in the AS class  below


      2)How can I get the current  X value  of the button from the actionscript class and called by the mxml file. Does AS have the equivalent to set,get with properties like in .net


      I have a button that moves but I want the button declared in  the AS class  and a way to get the x value of the button in the mxml file.



      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
                        minWidth="955" minHeight="600" frameRate="30" 
                     import mx.events.FlexEvent;
                     import ButtonMover.ButtonMover;
                     protected function application1_creationCompleteHandler(event:FlexEvent):void
                          new ButtonMover(addEmployee);
           <s:Button id="addEmployee"
                       label="Add Employee"
      package ButtonMover
           import flash.events.Event;
           import mx.core.FlexGlobals;
           import spark.components.Button;
           public class ButtonMover
                private var _but:Button;
                public function ButtonMover(but:Button)
                     _but = but;
                     FlexGlobals.topLevelApplication.addEventListener(Event.ENTER_FRAME, move);
                private function move(event:Event):void {
                     _but.x += 1;
                     if (_but.x >= 400)
                          (_but.x = 0);
        • 1. Re: flex OOP
          rootsounds Level 4
          1. Yes, ActionScript is very much object-oriented. It has all of the familiar features such as constructors.
          2. There are simple, publicly exposed variable properties such as:
            public var myInt:int = 5;
            However there are also ActionScript-style getter and setter functions that mimic properties but provide you will the flexibility of a body of code:
            public function get myString():int { return _myString; }
            These are typically backed by a private variable.




          You know .NET which is good. It shouldn't be much of a jump learning Flex, especially if you have experience with Silverlight. I think that what you are getting stuck on is that you are trying to cram all of your code into the MXML file are are confused about these actually work. The problem with most of the examples you will find on the web is that they teach bad style in favor of providing a quick-and-dirty paste. Use MXML as strictly your layout. The logic should be in AS and in separate files. You will want to read up on the code-behind approach. Remember that when built MXML essentially gets translated into an AS class that is then compiled. MXML is therefore a convenience tool for quickly and clearly laying out the UI.

          • 2. Re: flex OOP
            Devtron Level 3

            Constructors are not .NET specific. Constructors have been around long before Microsoft.



            Most FLEX classes I have dug into have super constructors. So, yes they do have constructors, but at the class definition level. Not generally in your MXML unless you reference an override of a particular class, in your script tags.

            • 3. Re: flex OOP
              rootsounds Level 4

              Devtron wrote:


              Constructors are not .NET specific. Constructors have been around long before Microsoft.

              I never said that they were. If you're strong in .NET, it may be easier for you to first pick up Silverlight and then move over to Flex to get used to the development ideas. They are very similar. Just a few syntactical differences and libraries to learn.

              • 4. Re: flex OOP
                Devtron Level 3

                Well, I have 9+ years of .NET experience (started using it in beta 2 release, before public launch). And I have WPF, Silverlight experience and I would never ask a question like "does this language have constructors like .NET" because I know very well that C has constructors and has had constructors since before I was born.


                I do not consider ActionScript a programming language. It is a scripting language, much like Javascript. It is full of hacks, written by non-traditional programmers, who do not understand the fundamentals of structured logic and design. I am versed in Assembler, CICS, JCL all on IBM mainframes. So when you ask about constructors, I tend to think more about "C".


                One thing I would like to point out is that ActionScript does not support multi-inheritance, which is something VB catches a lot of flack for, in the .NET realm.

                • 5. Re: flex OOP
                  Devtron Level 3

                  to get the current button's x value, you would need to reference your button's x value.

                  like so:

                  trace ( addEmployee.x );