Skip to main content
Participant
June 16, 2013
Answered

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

  • June 16, 2013
  • 1 reply
  • 3378 views

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?

This topic has been closed for replies.
Correct answer Ned Murphy

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

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
June 16, 2013

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

Participant
June 16, 2013

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?

Ned Murphy
Legend
June 16, 2013

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.