6 Replies Latest reply on Jun 16, 2013 7:08 PM by Matthew Alpert

    CS6 breaks ActionScript 2.0 projects. No var property for TextInput or Label.

    Matthew Alpert

      I've been programming for years, but I'm brand new to Flash. For various reasons, I need to learn ActionScript 2.0 instead of 3.0. All I could get from Adobe's website is the trial for CS6.

       

      When I look at tutorials for AS2, controls such TextInput and Label are supposed to have a variable associated with them. Then in code, one can simply get/set that variable to read/change the control's contents. For example: http://youtu.be/H_TEa6i2Bhk?t=2m57s

       

      However, in CS6, TextInput and Label controls have no such "var" property that I can find. After hours with no luck, I decided to download examples of AS2 projects and open them up to see how they look. Here's one I tried: http://www.freeactionscript.com/2009/07/endless-parallax-scrolling/

       

      Notice at the bottom of the flash window are labels for the x and y speed that change dynamically as you use the arrow keys. The zip contains both the .fla and .swf file. When I run the .swf file, it works fine. When I open the .fla file in Flash Pro CS6 and hit Ctrl+Enter (which overrites the .swf file), everything works EXCEPT the labels no longer update. The overwritten .swf file no longer works correctly either, as expected.

       

      I tried this on several other examples and in each case any Label or TextInput controls no longer worked correctly. When I go to File->ActionScript Settings, it says ActionScript 2.0. What am I doing wrong?

        • 1. Re: CS6 breaks ActionScript 2.0 projects. No var property for TextInput or Label.
          Ned Murphy Adobe Community Professional & MVP

          You might be correct as far as CS6 breaking the AS2 files' use of the textfields.  If I use an earlier version (CS3) the file plays and the textfields remain updating.  As soon as I open it with CS6 the textfields fail.  So the short answer is, you aren't doing anything wrong.

           

          The tutorial you pointed to might be good for you to learn a couple of things that you should not do as far as poor design practices go.  I don't know why but alot of tutorials teach bad practices.  If you are going to work with other people's designs, then you will probably need to be aware of the good and the bad practices... otherwise you might not find things.

           

          1) Using the "var" property of textfields is not a recommended practice.  What you should do is assign an instance name to the textfield and assign the text to it via the "text" property of that textfield.

           

               textFieldNameX.text = String(speedX); // convert numeric values to Strings

           

          2) Placing code "on" objects - avoid it.  Again, assign instance names to the object and assign functionality using those names in the timeline rather than "on" the objects.  It makes finding the code easier and provides a clearer reference point of where the code is targeting.

           

              on(release){.... }  // placed on the object

           

          becomes

           

             objectName.onRelease = function(){... }

           

          on the timeline that contains the object

          • 2. Re: CS6 breaks ActionScript 2.0 projects. No var property for TextInput or Label.
            Matthew Alpert Level 1

            Thank you, that was very helpful. I like this approach more anyway because it seems more like... normal programming, if you know what I mean.

             

            Anyway, I've noticed some inconsistency in how you set up event handlers. For a button you can do:

             

            1. button.addEventListener("click", click);
              function click(e:Object):Void {...}
            2. button.onRelease = function() {...}
            3. button.onRelease = click;
              function click(e:Object):Void {...}

             

            For 1, you have a named function that can be the event handler for multiple objects, and you get a reference to the event which has a reference to the object when the handler is called. For 2, however, there is no reference, so you can't check out the state of the sender. 3 will partially work, that is, the function will be assigned as a handler, but any use of "e" in the body will not work.

             

            So the part that's bothering me the most about this is that I cannot reliably find a list of events in string form for controls. For button, there is a list in "on####" form here: http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00000820.html, but nowhere on that page does it mention button.addEventListener("click", click). That is arguably the more useful form, but I only know that exists because I've seen it in examples.

             

            For TextInput, there is this list: http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00002922.html, which shows TextInput.change and TextInput.enter. When you click on those, it shows examples using TextInput.addEventListener("enter", listener).

             

            This inconsistency concerns me. Is "click" the only string form event for button? If there are more, how do I find them. In fact, how should I have found it in the first place? None of the "on####" forms use the word "click", so I may never have guessed to use that word.

             

            So how do I find the full lists of events in both forms for all controls?

            • 3. Re: CS6 breaks ActionScript 2.0 projects. No var property for TextInput or Label.
              Ned Murphy Adobe Community Professional & MVP

              I believe the addEventListener() code is AS3.  I know AS2 has addListener() but I do not think it has addEventListener.

               

              Things are much easier to find for AS3... it usually just requires a trip to the help documentation, where you search for the properties, methods, constants, and events associated with whatever class has your interest.

               

              In this case, for AS3 you would look up the MouseEvent class and there you would find all of the different events that you can listen for.

               

              For AS2 I can't really say where the best place to look is, but the AS2 help documents probably have it all defined somewhere within them.  Myself, I learned of them over time more than anything, so finding them in a reference wasn't a goal of mine that I can remember.

              • 4. Re: CS6 breaks ActionScript 2.0 projects. No var property for TextInput or Label.
                Matthew Alpert Level 1

                Interesting. Well, for TextInput here http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=00002922.html, that's part of ActionScript 2.0 docs, and my flash project is set to use AS2, so addEventListener does seem to be part of AS2. But there are differences between AS2 and AS3 as far as what works in that function. For example, this page http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Interacti veObject.html#event:click shows MouseEvent.CLICK, but that doesn't work in place of the string "click" in the code above. However, "addEventListener(Event.ENTER_FRAME, onEnterFrame);" works just fine.

                • 5. Re: CS6 breaks ActionScript 2.0 projects. No var property for TextInput or Label.
                  Ned Murphy Adobe Community Professional & MVP

                  There are major differences between AS2 and AS3, even with the event syntax that is used.  Still, there are bound to be similarities, and in some cases the code hasn't changed at all.

                   

                  In AS3, addEventListener is probably the most across the board common thread in the language.  If you want to keep track of anything happening, that same function is used for it in every case... which makes it a little easier to deal with from a what-you-need-to-know persepective. 

                   

                  AS2 on the other hand has the variations such as the ones you are finding all over the place.  Components have a different set of methods than common objects such as buttons and movielcips, which is liely why you found that addEventListener involved with them. 

                   

                  I am not sure but I think I have seen AS3 use the string version of the event listener that you mentioned ("click" rather than the MouseEvent.CLICK).  I haven't experimented much with AS3... it's usually enough work just getting it working one way.

                  • 6. Re: CS6 breaks ActionScript 2.0 projects. No var property for TextInput or Label.
                    Matthew Alpert Level 1

                    I just discovered that the on### form of the event handlers seem to have an implicit parameter "this". So the following code works:

                     

                    rect1.onPress = rectStartDrag;
                    function rectStartDrag()
                    {
                        this.startDrag();
                    }
                    
                    rect1.onRelease = rectStopDrag;
                    function rectStopDrag()
                    {
                        this.stopDrag();
                    }
                    

                     

                    So that solves my concern about being able to reference the caller from these functions.