JavaScript and ActionScript | 2
home / programming / javascript / j_s / column2 | [previous] |
JavaScript and ActionScript
A Class of Differences
As noted, the predefined classes in JavaScript and ActionScript are anywhere from slightly to substantially different. These differences are due to the fact that JavaScript is designed primarily to support web pages through the classes of document/windows/elements while ActionScript is devoted to control of animations through the Stage/MovieClip classes. The Table below summarizes these major differences in predefined classes:
Table 1- Predefined Classes in
ActionScript vs JavaScript | ||
Class | ActionScript | JavaScript |
area | no - has own drawing API | yes complete |
argument | yes complete | yes complete |
Array | yes - less toSource(), valueOf() | yes complete |
Boolean | yes - less toSource() | yes complete |
Button | yes - generally different from JS | yes - part of Form object |
Color | yes complete | no - part of Body, CSS and other objects |
Date | yes - less to parse(), toTimeString(), valueOf() | yes complete |
Document | no - MovieClip is dominant object | yes complete |
element | no, embodied in special objects like key, etc | yes complete |
form | no seen in special objects like Button etc | yes complete |
function | yes - less arity, caller, constructor, length | yes complete |
global | partial - greatly simplified, syntax change | yes complete |
Key | yes - very different | yes - very different, kbd syntax, properties, methods |
_level | yes | no - Netscape Layer is analogous |
location | no - but should be | yes complete |
Math | yes complete | yes complete |
MovieClip | yes | no, document/element => Stage/MovieClip |
Mouse | somewhat analogous | MouseEvent - somewhat analogous |
Number | yes - less many methods, properties | yes complete |
Object | yes - again much simplified | yes complete |
RegExp | no - 3rd party regular expression | yes complete |
Selection | yes - analogous | no buried in specific Form objects |
Sound | yes complete | no but should be |
Stage | yes | no, document/element => Stage/MovieClip |
String | yes - core set of 12 methods, key properties | yes complete |
Textfield/TextFormat | yes | no - spread over Style, text, textarea etc |
this | yes complete | yes complete |
XML | key point of divergence | key point of divergence |
As you can see, there are some core similar classes with ActionScript clearly being a subset of JavaScript. And there are times when programming in ActionScript that I wanted to see more of JavaScript's predefined classes implemented. For example, the Windows class or the location/URL class would be very useful for managing Flash's many new forms and data components. Likewise, ActionScript's sound and color predefined classes could be usefully imported into JavaScript.
But the two critical points of divergence are JavaScript's Form oriented objects like textfield, select field and radio button which are largely implemented as Flash components in ActionScript. Also there is not the logical hierarchy of form elements as in JavaScript. But JavaScript has failed to add any new form components since the origin of the language in 1995. Of even more concern is the divergence in the handling of XML. ActionScript has two predefined classes, XML and XMLSocket, for handling XML whereas JavaScript has only one, non-standard Microsoft JScript oriented XML class. It's a bit disconcerting that XML (which has managed to stay close to standard among all the major players) is subject to different definitions and processing methods when implemented in major scripting languages like ActionScript and JavaScript.
The XML Handwriting on the Wall
The divergence in XML implementations is a bellwether. The likelihood is that the two scripts will continue to diverge over time. As we have seen from the table, there are already substantial differences in the predefined classes. And with Flash adding database connectivity while JavaScript struggles with two rival implementations of database operations (the Netscape original and the Microsoft JScript latest ASP.NET incarnation), convergence of the scripts is unlikely. Web Services, threading and asynchronous messaging have little reason to converge because the base XML classes are different along with some event and error handling syntax.
This seemingly inevitable divergence in programming models is hardly welcome among programmers, who have to make a false choice between Java and Microsoft's C# clone. Developers of Web applications also must cope with knowing at least 6-8 programming languages and syntaxes: HTML, XML, UML, SQL, JavaScript, ActionScript, Java and/or C# and/or PHP and/or Perl and/or C/C++. But lets not dismiss some major blessings here - ActionScript and JavaScript share a remarkably consistent math, string and object defining syntax along with nearly uniform operators, logical operations, and flow of control statements. My gosh, look at the world of system administration where BSH, DCL, JCL, Rexx and WSH is just the tip of the batch scripting iceberg.
The new E4X XML extensions to ECMAScript will be the turning point. These extensions (the first major ones to JavaScript in 4 years are being proposed not by Netscape but BEA), truly simplify XML processing in JavaScript. They involve changes to the for-loop and other syntactical changes to streamline XML-tree processing. First, of course, they have to be accepted by ECMA and then implemented by the JavaScript vendors. Then the ball enters Macromedia's court where major additions and changes to Macromedia's XML and XMLSocket pre-defined classes will have to take place. This is not a sure thing. Despite this prospect, JavaScript and ActionScript coders will still be pleasantly surprised by how their skills transfer between the two scripting environs. No small blessing these days when, for example, moving between XSL:FO, XSLT, CSS, XPATH and WSDL - all a part of the overall XML architecture, can be a challenge. This developer is counting his JavaScript and ActionScript blessings and is praying for convergence in the near future.
Jacques Surveyer is a web developer who can be contacted at https://www.theopensourcery.com/
home / programming / javascript / j_s / column2 | [previous] |
Created: June
2, 2003
Revised: June 26, 2003
URL: https://webreference.com/programming/javascript/j_s/column2