ActionScript 3 - Design Problems

All compilers have a few design problems.

If it is in the help file, then that is a feature ... if it is NOT in the help, it is a bug.

Text Rotation | TextArea Component | import fl.controls.*; | Log10 | Graphs & Sprite Sizes | Stack Overflow


Text Rotation

Simple, I was graphing some data and wanted the y-axis label to be rotated. Well, TextField is based on DisplayObject which has a rotation property.
TextField -> InteractiveObject -> DisplayObject -> EventDispatcher -> Object
So, I set the rotation and the text disappeared. Solution - use embedded fonts.

Let me be specific,

(No, I don't think calling this a design problem is being too negative.)


TextArea Component

This is complete nonsense - if you set the TextArea component's text property to the contents of a DOS text file (ie, a real text file), then it adds extra blank lines. You see, each of the 3 main types of operating systems uses a different way to terminate text lines - DOS has more than 80% of the total market ... and Flash screws it up.

I tried using the htmlText property and enclosing the text in pre tags ... same thing. (Actually, most html tags are ignored - *b* (bold) works, *p* (paragraph) fails, and so forth. There is no definition of which tags are supported, and some in the examples are not ... pretty lame.)

The following code fixes this problem by using a regular expression.

I also wanted to use a fixed pitch font - no such luck. I tried using an embedded font ... no luck.

And what does font="_sans" mean? Sometimes this is shown, other times it reports what I set it to. Either way, there is no obvious way to control the fonts.


import fl.controls.*;

When writing ActionScript 3 code, the help says to use the import statement to use objects. It appears that this works for all classes EXCEPT the Flash controls. This is the error message - pretty worthless

The solution is to manually add the controls you want to your form (via Windows / Components...) ... which automatically adds them to the library. Then, specific import's will work. You can still use the asterisk notation, but only those controls in the library will be found.

Once a control is in the library, then you can delete the control from the form (because the pieces will stay in the library).

This information is NOT in the help files.

Note that the help for Slider contains the following in the examples

To make this even harder to debug - if ANY fl-control is placed on your form, then, sometimes, no error will be shown when you try to use a different control AND nothing will be displayed.

In a separate test case, there was an error when other controls were in the library. That's correct, I have 2 test cases - one shows an error and the other does not.

Don't get me wrong - this IS a reasonable design. However, the error message and the help file should be VERY explicit on this constraint.

For what it is worth - this took me over 6 hours to research and document. (It only took about half an hour to realize that this is a Adobe Flash design problem.)

Reference 1 Reference 2


Log10

ActionScript 3.0 does not provide a function to compute a base-10 log. The help suggests using I tried using the following and got the wrong answer This table summarizes what I learned The "error" is extremely small, but is was enough to make my program fail. I had created a function that used the integer part of the base-10 logarithm - I could not round the value before taking the integer because the function would then fail when the value was 900. For a value of 100, the correct result is 2 and the function I wrote returned 1 ... which is how I found this.

Comment - I was taught that

For reasons that defy logic, Basic, C, Java, Flash, and MS Access use log(x) to find the natural log of a value ... Pascal and Excel use ln(x).

At any rate, I needed the base-10 log to plot some data. C, Java, and Pascal (but not Flash) provide log10(x) for this purpose. Solution ... write my own. I stored 1/ln(10) as a constant that could be reused because multiplication is usually faster than division. I did not discover (or expect) the problem until my code failed. That is also when I discovered that AS3 provides a constant for this purpose.

Bottom line - it appears that AS3 has a design problem when computing 1/x.


Graphs & Sprite Sizes

I use Sprites to draw graphs via moveTo and lineTo. I attempted to interact with the results using the mouse and the reported width and height of the object. The basic problem was that when the width was set to 40, it was reported as 41, 42, 40.2, and so forth as the program ran. (I used lots of trace's.) As a result, the scroll and zoom functions I wrote were unpredictable.

If you want a drawing area to be 40x50, create it 39x49 with a border of one. However, only draw in the area 38x48 ... otherwise the drawing area will automatically increase (the values returned by width and height will increase).

Basically, subtract 2 from both the reported width and height to determine the size of the drawing area. Both moveTo and lineTo will change the size and scaling of the canvas (graphics property) if they exceed those values.

This is totally insane ... it only took 4 months to finally figure it out.


Stack Overflow

I wrote an *.as file with several almost exact subroutines. When I called one, Flash produced and a long trace. The others worked fine.

One *solution* was to add a trace() command to the routine. It does not matter which variable is traced ... even tracing a constant string (as shown below) "fixes" the overflow problem.

The following code produces this error

I tried many things, to get the error. In addition to the notes above, when the style parameter was omitted, there was no error. It does not matter if the value has a default or if the parameter is used in the test code.

A similar problem is confirmed by Adobe - it was reported 11-16-2007.


Author: Robert Clemenzi - clemenzi@cpcug.org
URL: http:// cpcug.org / user / clemenzi / technical / Languages / ActionScript / DesignProblems.html