| By Andrew Trice | Article Rating: |
|
| February 6, 2007 10:00 AM EST | Reads: |
13,938 |
The previous two components both implement the IAutomobile interface, but have nothing else in common. One is simply a class that implements the interface, the other is an MXML component that implements the interface. The MXML component example extends the mx:Canvas component (the same thing could be done by creating an AS class that extends mx.containers.Canvas). Now, let's look at a function similar to the "race" function from earlier:
public function race( auto1 : IAutomobile, auto2 : IAutomobile ) : void
{
auto1.accellerate();
auto2.accellerate();
}
This example will work with either object that I have created because both objects implement the IAutomobile interface. The do not rely upon functions in the class hierarchy, just those that were implemented for this interface. You can also use multiple interfaces on classes that you create. Implementing multiple interfaces basically means that you are adding more required method signatures to your class, and you will have to implement these methods to satisfy each interface. On the other hand, you cannot inherit from multiple classes. Some programming languages allow for multiple inheritance (http://en.wikipedia.org/wiki/Multiple_inheritance). ActionScript 3.0 does not support multiple inheritance (so I'll stop there).
Enough of this rambling...what does this have to do with Flex?
Inheritance and interfaces are used extensively in AS3 to create the Flex framework. Just look at the Flex documentation for the mx:Canvas component (http://livedocs.macromedia.com/flex/2/langref/mx/containers/Canvas.html) and you can see inheritance in action (http://livedocs.macromedia.com/flex/2/langref/mx/containers/Canvas.html).
Canvas
-->
Container
-->
UIComponent
-->
FlexSprite
-->
Sprite
-->
DisplayObjectContainer
-->
InteractiveObject
-->
DisplayObject
-->
EventDispatcher
-->
All Flex framework components that are rendered to the screen extend from the UIComponent class. All combo boxes and lists implement the IList interface, an AbstractService, DataService or EventDispatcher object implements the IEventDispatcher Interface. You may be using these concepts every day, but weren't aware of it, and how you can use it to your own benefit. Inheritance seems easier to take advantage of at first. Let's say that you want to create several objects, all of which will have identical functions and variables. It is easy to see that you can create a base class that encapsulates all of the common functionality. You can then create sub-classes that implement the differing functionality for each class.
When putting these concepts into real-world Flex applications, you'll need to get familiar with the following keywords:
public class A extends public class B
public class MyClass implements MyInterface
final function myFunction() : void
public static function myStaticFunction(): void
//to use it call it directly from classMyClass.myStaticFunction()
internal var foo : String;
override public function myFunction() : void
private var myPrivateValue : String;
protected var myProtectedValue : String;
public var myPublicValue : String;
Published February 6, 2007 Reads 13,938
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Andrew Trice
Andrew Trice is a consultant with Cynergy Systems in Washington, DC, where he specializes in development of Flex-based Rich Internet Applications. Andrew has over 5 years of proven experience in the RIA industry, including application design and development using Flex, Flash, ColdFusion, J2EE and .NET architectures.
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Betas Target RIAs and Cloud Computing
- Adobe Cans Another 9% of its Workforce
- Moyea DVD4Web Converter V2.0 Converts DVD to FLV Fast and Synchronously with Watermarks
- Adobe & Salesforce Cut Cloud Deal
- Adobe Fiddles with its Web Apps
- Hosting.com Launches ColdFusion 9 in the Cloud
- The Real Time Infrastructure Ultimatum
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Is Microsoft as Free as Open Source?
- Adobe Reader Sued
- The Planet Named “Bronze Sponsor” of Cloud Computing Expo
- Microsoft Expression Web Has Got Game
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Bruce Chizen Joins Voyager Capital as Venture Partner
- My Top Seven Wishes From Adobe MAX 2009
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- Constructing an Application with Flash Forms from the Ground Up
- AJAX World RIA Conference & Expo Kicks Off in New York City
- CFEclipse: The Developer's IDE, Eclipse For ColdFusion
- Personal Branding Checklist
- Adobe Flex 2: Advanced DataGrid
- Has the Technology Bounceback Begun?
- Building a Zip Code Proximity Search with ColdFusion
- i-Technology Viewpoint: We Need Not More Frameworks, But Better Programmers
- The Asynchronous CFML Gateway
- Web Services Using ColdFusion and Apache CXF





















