Welcome!

Adobe Flex Authors: Matthew Lobas, PR.com Newswire, Shelly Palmer, Kevin Benedict

Related Topics: Adobe Flex

Adobe Flex: Article

Flash MX Programmer's Guide to ActionScript 2.0

The more tools you have, the more you can build

Flash developers who are still using ActionScript 1.0 are drastically limiting their capabilities, wasting valuable time and resources. Because most Flash developers come from a nonprogramming background, they don't fully understand the true power and benefits of ActionScript 2.0. This article attempts to clear up some common misconceptions about AS2 and gives some clear examples demonstrating the new concepts and methodologies that can be applied using it.

AS1 Is Not Deprecated
What is now referred to as AS1 is the same AS you'll find in Flash MX. Contrary to popular belief, the AS1 programming style - using prototype objects as classes - is not deprecated. You can still write prototype objects and modify existing objects' prototypes in AS2 using the exact same AS1 syntax. AS2 does not deprecate AS1; it extends and refines it.

Class Declarations
With AS1 you could only use prototype objects to define a class (see Code I).

For component development you would also have to use the #initclip and #endinitclip pragmas as well as the Object.registerClass method to assign your class to a MovieClip in the library.

With AS2 you could still write the same prototype object or you could write a true class. To write a class you need to define your class in a separate AS file much as you would in Flash MX for external AS. For classes, the AS file must have the same name as the class itself. Some people might find this to be a hindrance; however, this requirement actually helps you better organize and structure your code (see Code II).

The prototype object and the class example do the exact same thing. For comparison, the constructor function was left in the example in Code II. However, a class does not explicitly have to have a constructor function defined as it does for prototype objects. In addition, no other code is required for component development. You can simply specify which class a MovieClip should use in the MovieClip's Linkage Properties panel found in the library.

When compared side-by-side you can see that the class definition is actually cleaner looking and is less redundant. In the prototype example, for every method of a class you must type the name of the object you're adding the method to and the location of the method (specified by prototype).

Some might argue that despite the redundancy the prototype approach is actually more flexible because you can add a method to any class dynamically at anytime in AS1. (This is known as delegation.) Again, AS2 doesn't deprecate AS1, so you can still reference an object's prototype even inside a class definition (see Code III).

Properties
In AS1 you could add a property to a prototype object by first declaring a method to be used as a getter and then declaring another method to be used as a setter. Then you had to use an addProperty method on the prototype object to wire the getter and setter methods together as one property (see Code IV).

You can still use the exact same syntax in AS2 or you can just declare a getter and setter function (see Code V).

In the example in Code V, Flash MX 2004 Pro does all the work of the addProperty method for you and automatically ties the getter and setter methods together in a property named "_prop". Note that this is no longer needed in most cases, saving you some extra typing.

Static, Public, Private
In AS1 there was no supported way of specifying a public, private, or static method. However, with AS2 this is possible (see Code VI).

A public method simply means that an outside object is allowed to directly access the specified property or method. A private method or property may only be accessed internally from within the class. Static methods or properties are similar to private methods in that they may only be called from within the class itself. However, static methods or properties are created only once per class rather than being created in every object based on that class.

Strict Data Typing
Another new feature of AS2 is Strict Data Typing (aka Type Casting). This allows you to cast (assign) a specific data type or class to a variable. It is especially useful when debugging. Say, for example, in AS1 you have a prototype object called List that has a method called "addNewValue":

var MyList = new List();
MyList.addNewVlaue(1);

However, when you test the movie the value never gets added to the List and you are forced to figure out the problem on your own. Granted, a typo like this by itself is pretty easy to find. However, buried in a couple thousand lines of code it may not be as obvouis.

Strict Data Typing deals with this problem by allowing only public methods or properties of nondynamic classes to be called (see Code VII).

Case Sensitivity and Member Variables
Another new addition to AS2 is case sensitivity. This means that a variable called "someVar" would have a different memory location than "somevar" would. This allows each variable to exist without one overwriting the other. In addition, gone are the days of declaring an instance/member variable anywhere inside of a prototype object as in Code VIII.

In AS2 classes you have to declare all your member variables first (see Code IX). Some developers find this to be an inconvenience initially (especially when converting old AS1 code to AS2). However, over time this will help make you a more consistent programmer and will make your code easier to read and maintain. Note the use of m_ in front of someVar. This is just a naming convention I've adapted in my source code to specify a private member variable.

Conclusion
With all the features of AS1 and the many new additions to AS2, most of which I didn't even get a chance to cover in this article, Flash developers refusing to use AS2 are limiting the tools and capabilities they have for completing a job. You wouldn't want to build a house with just a hammer. A good developer knows, just like any construction worker, that the more tools you have in your tool box, the more things you can potentially build.

More Stories By Erik Bianchi

Erik Bianchi, a member of the editorial board of Web Designer's & Developer's Journal, is a software engineer with more than five years of experience developing Flash-based RIAs and enterprise-wide applications for Fortune 50 and 500 companies. In his spare time he enjoys building Flash-based games, writing or tech editing Flash-related books, and when burned out on code, playing video games on his PC/console systems. You can get more info about Erik and his latest projects on his blog at www.erikbianchi.com.

Comments (2) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Erik Bianchi 03/17/04 03:28:43 PM EST

Obvious was intentionally misspelled to demonstrate how easy it is to overlook a typo. Many people didn't notice despite the bolding. Probably should have put a note in there or something to clarify. =)

Thanks for your post and sorry for the confusion.

-erik

A. MacDonald 03/17/04 10:14:49 AM EST

spelling mistake in news - it was pretty OBVIOUS

var MyList = new List();
MyList.addNewVlaue(1);

However, when you test the movie the value never gets added to the List and you are forced to figure out the problem on your own. Granted, a typo like this by itself is pretty easy to find. However, buried in a couple thousand lines of code it may not be as >>> obvouis. << ERROR <<

@ThingsExpo Stories
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
A strange thing is happening along the way to the Internet of Things, namely far too many devices to work with and manage. It has become clear that we'll need much higher efficiency user experiences that can allow us to more easily and scalably work with the thousands of devices that will soon be in each of our lives. Enter the conversational interface revolution, combining bots we can literally talk with, gesture to, and even direct with our thoughts, with embedded artificial intelligence, whic...
Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
"Digital transformation - what we knew about it in the past has been redefined. Automation is going to play such a huge role in that because the culture, the technology, and the business operations are being shifted now," stated Brian Boeggeman, VP of Alliances & Partnerships at Ayehu, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that Synametrics Technologies will exhibit at SYS-CON's 22nd International Cloud Expo®, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Synametrics Technologies is a privately held company based in Plainsboro, New Jersey that has been providing solutions for the developer community since 1997. Based on the success of its initial product offerings such as WinSQL, Xeams, SynaMan and Syncrify, Synametrics continues to create and hone inn...
"Evatronix provides design services to companies that need to integrate the IoT technology in their products but they don't necessarily have the expertise, knowledge and design team to do so," explained Adam Morawiec, VP of Business Development at Evatronix, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
SYS-CON Events announced today that Evatronix will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Evatronix SA offers comprehensive solutions in the design and implementation of electronic systems, in CAD / CAM deployment, and also is a designer and manufacturer of advanced 3D scanners for professional applications.
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
DevOps at Cloud Expo – being held June 5-7, 2018, at the Javits Center in New York, NY – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real results. Among the proven benefits,...
@DevOpsSummit at Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, is co-located with 22nd Cloud Expo | 1st DXWorld Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait...
SYS-CON Events announced today that T-Mobile exhibited at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on qua...