Migrating Applications to Flex 2 ® ™ Adobe Flex 2
© 2006 Adobe Systems Incorporated. All rights reserved. Migrating Applications to Flex™ 2 If this guide is distributed with software that includes an end-user agreement, this guide, as well as the software described in it, is furnished under license and may be used or copied only in accordance with the terms of such license.
Contents About Flex Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Using this manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Accessing the Flex documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Chapter 1: Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 Formatters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 Interfaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Managers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Media controls . . . . . . . . . . . .
Chapter 9: Data Services. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 About Data Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .135 Migrating RemoteObject components . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Migrating HTTPService components . . . . . . . . . . . . . . . . . . . . . . . . . . .140 Migrating WebService components . . . . . . . . . . . . . . . . . . . . . . . . . . . .143 Migrating secure data services . . . . . .
Contents
About Flex Documentation Migrating Applications to Flex 2 provides information on updating applications written for Flex 1.x to Flex 2. Contents Using this manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Accessing the Flex documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Using this manual This manual can help anyone who has developed Flex applications.
Documentation set The Flex documentation set includes the following titles: Book Description Flex 2 Developer’s Guide Describes how to develop your dynamic web applications. Getting Started with Flex 2 Contains an overview of Flex features and application development procedures. Creating and Extending Flex 2 Components Describes how to create and extend Flex components.
CHAPTER 1 1 Getting Started This topic describes the first steps of migrating a Macromedia Flex 1.x application to Adobe Flex 2. This topic describes steps that are meant to be accomplished quickly and resolve most of the warnings and errors that you encounter. When you complete the steps in this topic, you should read other topics in this manual for more information about specific migration operations. Contents Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
The basic steps are the following: ■ “Step 1: Find and replace” on page 10 ■ “Step 2: Add access modifiers” on page 14 ■ “Step 3: Add types” on page 15 ■ “Step 4: Update events” on page 16 ■ “Step 6: Put all ActionScript components in packages” on page 17 ■ “Step 7: Update data services” on page 18 ■ “Step 8: Charts” on page 18 ■ “Step 9: Overrides” on page 18 ■ “Step 10: Binding” on page 19 ■ “Step 11: API updates” on page 19 The remaining sections of this topic describe these steps in
This section describes only the most common targets of finding and replacing. There are many other members of Flex classes that have changed that are not mentioned here. For a complete list, see Chapter 3, “Flex Classes,” on page 41. Application namespace Change the MXML namespace. Change the following: xmlns:mx="http://www.macromedia.com/2003/mxml" to this: xmlns:mx="http://www.adobe.com/2006/mxml" For example: PAGE 12Application and container initialization The initialize event is now dispatched later in the startup and component creation life cycle. In particular, it is now dispatched after the object’s children have been created. If your event handler assumes that the object’s children have already been created, you can use the initialize event.
Replace _root Remove the use of “_root” from your application code if you used it to access the Application instance. In Flex 1.x, you could use _root to refer to the main application from anywhere in your application or one of the components. This was never a recommended practice, but was a convenient way to access the application root. To access the Application instance from anywhere in your application, use Application.application. import mx.core.Application; function myFunction():void { //_root.ta1.
Effects/behaviors For each effect, such as Fade, Sequence, and Parallel, change the name property to id. Also, remove the tags; for example: For more information, see Chapter 8, “Behaviors,” on page 129. getURL() method Replace the getURL() method with the navigateToURL() method in the flash.net package.
The default access modifier for methods, variables, and classes is internal. This means that all classes in the same package can access them, but classes outside of the package cannot. However, the Flex compiler issues a warning if you do not specify any access modifier. For more information about access modifiers, see “Access modifiers” on page 27. For information about disabling warnings, see Chapter 9, “Using the Flex Compilers,” in Building and Deploying Flex 2 Applications.
Step 4: Update events The Event model changed in Flex 2. However, you can migrate most event handlers with minimal effort. This section describes the most popular changes that you must make to your event handling code. For more information about migrating events, see Chapter 6, “Events,” on page 111. Specify types Events are now more strongly typed than in Flex 1.x. As a result, you should specify the object type in the event listener function.
Step 5: Import classes for package-level functions When you use package-level functions, you must import the package. For example, in Flex 1.x you could call the show() method in the following way: mx.controls.Alert.show("This is an Alert!"); In Flex 2, you must import the package before calling the function, as the following example shows: import mx.controls.Alert; Alert.
Step 7: Update data services The RemoteObject, HTTPService, and WebService MXML services are now known as RPC services. The RemoteObject tag is not functional unless you use Adobe Flex Data Services. You must replace use of this with another tag. You can still use the HTTPService and WebService tags, but you can only access resources on a server that is in the same domain as the Flex application or from a server that has a crossdomain.xml file installed on it.
Step 10: Binding To make a user-defined variable bindable, you must now explicitly identify it by adding the [Bindable] metadata tag to the property; for example: [Bindable] public var catalog:Array; In addition, the tag must be moved to the top level. The following example compiled in Flex 1.5: PAGE 20■ Expanded abbreviations. Abbreviations in property and method names have been expanded where practical. For example, the hPosition property is now horizontalPosition. ■ Property names. Some properties have been renamed so that their function is more evident. For example, the Boolean multipleSelection is now allowMultipleSelection. ■ Chart skins. The chart skins are now referred to as renderers. ■ Unnecessary interfaces and classes.
CHAPTER 2 2 ActionScript 2.0 to 3.0 The ActionScript language has undergone a complete redesign. It is now a more robust, typesafe, and usable language. This topic provides an overview of changes to the ActionScript language. For information about using ActionScript 3.0, see Programming ActionScript 3.0. For a complete reference on using ActionScript 3.0, see the ActionScript 3.0 Language Reference. Contents Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
■ A subclass cant have a var with the same name as one visible from the superclass, and you can’t override a var. ■ You must declare a type for everything or you’ll get a compiler warning. ■ Accessing methods or properties of the target of an event object won't compile unless you cast event.target to the type of the target. For example, event.target.foo must be changed to MyComponent(event.target).foo. ■ You cannot do a for in loop on every object to see the object’s properties.
Capitalization of identifiers The ActionScript 3.0 naming conventions match the Flex application model and the ECMAScript standard. All identifiers are in “camel case.” This means that an identifier’s characters are in lowercase, except that the first letter of each word in the identifier is capitalized. For example, ExternalInterface. Class names are fully capitalized using camel case. The first letter of a class name is always a capital letter.
ActionScript 2.0 had many instances where getter and setter methods existed rather than accessors. Now, ActionScript 3.0 uses accessors wherever possible. Unless a function has arguments, it was converted to an accessor. Methods that return a Boolean such as Socket.isConnected() were converted to accessors, but retained the “is” or “has” prefix. For example, a method called methods would be converted to the Socket.isConnected property. Internal functionality marked private ActionScript 3.
Abbreviations ActionScript 3.0 contains fewer abbreviations in method and property names. The names are as descriptive as possible. For example, the mapPt() method is now mapPoint(). Some abbreviations are still used in ActionScript 3.0. For example, the getBounds() method was not changed to getBoundaries() because it is shorter but just as descriptive. In some cases, the use of abbreviation was preferred.
Using packages The package statement syntax has changed. In addition, you are now required to put custom ActionScript components inside packages. If you do not put a class inside a package, then the class is only visible in the current script. For example: class Foo {} is a class that is not in any package, so it is only visible in the current script. If you put a class in an unnamed package: package { public class Foo {} } Then you can access the class from any script.
Using classes This section describes changes to ActionScript classes. Access modifiers The new internal access modifier refers to a different namespace in each package definition, and is not defined outside of a package definition (that is, in global code). If a class in a package isn’t marked public or private, then it defaults to internal. The class cannot be accessed by classes in other packages; this is the same as the protected modifier in Java.
Using external files This section describes changes to embedding, including, and importing external resources with ActionScript in your Flex applications. include In ActionScript 2.0, the include keyword was preceded by an octothorp: #include. You now use the keyword without the octothorp, and end the line with a semi-colon. For example: ActionScript 2.0: #include "../scripts/thescript.as" ActionScript 3.0: include "../scripts/thescript.
Doing the latter results in a “Type annotation is not a compile-time constant” error. Embed The Embed syntax in ActionScript is [Embed(params)], and this metadata must be used over a variable. The variable should be of type Class; for example: [Embed(source="holdon.mp3")] var sndCls:Class; public function playSound():void { var snd:flash.media.Sound = new sndCls(); snd.play(); } This works in a very similar way to what was implemented in Flex 1.x.
Default values The following example shows the default values for variables of different types: var var var var var var dog:int; // dog:uint; // dog:Boolean;// dog:Number; // dog:Object; // cat; // defaults to 0 defaults to 0 defaults to false defaults to NaN defaults to undefined type defaults to Object, so default value is undefined For all other classes (such as String, XML, MovieClip, Sprite, or any user-defined class), null is the default value for uninitialized variables of that type.
About undefined In general, ActionScript 2.0 allowed accessing undeclared variables whose value had not yet been set. By default, their value was undefined. In ActionScript 3.0, accessing undeclared variables results in a ReferenceError. You can use the hasOwnProperty() method to check if a variable has been declared: if (hasOwnProperty('b') == false) b = 20; if (someObj.hasOwnProperty('myDynamicProp') == false) someObj.
If you previously checked against undefined for a Number, you use a similar syntax; for example: if (n == undefined) // ActionScript 2.0 if (isNaN(n)) // ActionScript 3.0 Typing ActionScript 3.0 is more strongly typed than previous versions of ActionScript. This section describes changes to the rules of typing. Explicit typing Flex 2 checks for type correctness for class and package property/methods at compile-time, and enforces types at run time.
Type detection To perform type detection, you should use is rather than typeof or instanceof. The is function examines types, whereas the instanceof function looks at the prototype chain. The instanceof function has been deprecated. For example: class B { public function B() {} } class A extends B { public function A() { super(); } } class Main extends MovieClip { public function Main() { var a:A = new A(); trace(a instanceof B); // false; instanceof is deprecated.
is the non-assignment expression. The variable myVar is dynamically typed to be String if hintString is true, else its type will be Number. You can use a non-assignment expression anywhere that you would use a type-assignment expression. (hintString ? String:Number) Global functions Most global functions have changed packages. In addition, they are no longer implicitly imported. This section describes some changes to the global functions.
Function changes Some global functions have been removed and replaced with new functions. The following table shows removed global functions and their ActionScript 3.0 equivalents: ActionScript 2.0 ActionScript 3.0 chr(num) String.fromCharCode(num) int(expr) Math.round(expr) length(expr) expr.length mbchr(num) String.fromCharCode(num) mblength(string) string.length mbord(char) String(char).charCodeAt(0) mbsubstring(string, index, count) string.substr(index,count) ord String(char).
Miscellaneous This section describes miscellaneous changes to the ActionScript language. MovieClip MovieClip has been replaced by Sprite as the parent class of the base object for Flex controls, UIComponent. The following table lists changes to methods of MovieClip: ActionScript 2.0 method ActionScript 3.0 equivalent beginMeshFill() The beginMeshFill() method has been removed. There is no ActionScript 3.0 equivalent. swapDepths() Target paths are not supported in ActionScript 3.0.
Arrays Arrays no longer automatically update if you change the data. This means that you should no longer databind to an Array unless you manually call the dispatchEvent() each time an element in the Array changes. Otherwise, the control to which the data is bound will not reflect the changes. You can databind to a Collection. Two convenience methods of the Array class have been removed. You can no longer use the addItem() and removeItem() methods. You must instead use push() and pop(), respectively.
Constants You can use the const keyword to define constants in ActionScript 3.0. First, you determine which class and instance variables qualify as constants, and then declare them with const instead of var; for example: static const NONMODAL:Number = Alert.NONMODAL; const backgroundColorName:String = "buttonColor"; In general, constants should be class constants rather than instance constants. The initial value for a constant must be an expression that can be evaluated at compile time.
__proto__ ActionScript 3.0 does not support “hacking” the prototype chain. The use of __proto__ is no longer supported. For example: ActionScript 2.0: Class A {} var a: A = new A; trace(a.b) a.__proto__.b = 10 trace(a.b) class C { var x:Number = 20; } var c:C = new C(); a.__proto__ = C.prototype; trace(a.x); // Output: undefined // Ok // Output: 10 // Output: 20 ActionScript 3.0: class A {} var a: A = new A trace(a.b) a.__proto__.b = 10 // // // a.constructor.prototype.b = 10; // trace(a.
newstring2.prop = 1; trace(newstring2.prop); // prints '1' ActionScript 3.0: newstring = new String("hello"); String.prototype.sayHi = function() { trace("hi!"); } newstring.sayHi(); newstring2 = "hello"; newstring2.prop = 1; // Warning, String is sealed... String.prototype.prop = 1; trace(newstring2.prop); // Output: 1 Working with keys The Key class is now the Keyboard class. doLater() method The doLater() method on UIComponent has been removed. You now use callLater().
CHAPTER 3 3 Flex Classes This topic describes API changes to the Flex class library in Adobe Flex 2 SDK, including class-level changes to containers, core classes, and UI components. Contents Core classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Controls . . . . . . . . . . . . . . .
Core classes The UIObject and UIComponent classes have been combined. As a result, references to the UIObject class should be replaced by UIComponent. Visual Flex controls are subclasses of the UIComponent class (formerly UIObject). In Flex 1.5, the UIComponent class was a descendent of the MovieClip class. Now, the UIComponent class descends from the Sprite class. The following example shows the full hierarchy of a Flex control, such as the Button control: Object | +--flash.events.
Member Change description createLater addToCreationQueue direction The direction property has been replaced by the layout property. fillAlphas/fillColors The application background gradient now uses the backgroundGradientAlphas and backgroundGradientColors style properties for styling, instead of the fillAlphas and fillColors style properties. If the backgroundGradientColors property is undefined (which is the default), the background colors are calculated based on the backgroundColor style property.
The following table describes changes to the Container class: Member Change description allChildrenList rawChildren backgroundAlpha Deprecated. Use the background style to set this value. backgroundDisabledColor Deprecated. backgroundSize Deprecated. Use the background style to set this value. childAdded (formerly childAdd childCreated) childRemoved (formerly childRemove childDestroyed) childIndexChanged childIndexChange childrenCreationCompleteEffect Removed.
Member Change description hScroller horizontalScroller hScrollPolicy horizontalScrollPolicy marginBottom paddingBottom marginLeft paddingLeft marginRight paddingRight marginTop paddingTop maxHPosition maxHorizontalScrollPosition maxVPosition maxVerticalScrollPosition showInAutomationHierarchy Removed.
mx.core.MovieClipLoaderAsset The following table describes changes to the mx.core.MovieClipLoaderAsset class: Member Change description addedHandler Removed. Use the complete event instead. mx.core.MXMLUIObject The MXMLObject class is now the IMXMLObject class, to conform with the Flex 2 interface naming style. mx.core.Repeater The following table describes changes to the mx.core.Repeater class: Member Change description showInAutomationHierarchy Removed. mx.core.
mx.core.Skin* The mx.core.Skin* classes have been renamed to use the term Asset in the class name. For example, the SkinSprite class is now named SpriteAsset, and the SkinMovieClip class is now named MovieClipAsset. These classes now implement the IFlexAsset interface. mx.core.UIComponent The UIComponent class has been combined with UIObject to form a single base class for visual Flex components.
Member Change description createEmptyObject() Removed. Use the new operator and the addChild() method or other methods to add new visual objects to the display list. createToolTip toolTipCreate currentStateChanged currentStateChange deleteStyle() clearStyle() destroyObject() Removed. Use the removeChild() method or other methods to remove a child from its parent. doLater() callLater() draw updateComplete drawRect() Removed. Use the drawRect() method of the flash.display.Graphics class.
Member Change description mouseOverEffect rollOverEffect mouseOutEffect rollOutEffect mouseWheelOutside This event is now of type FlexMouseEvent instead of MouseEvent. notifyEffectEnding effectEnding notifyEffectPlaying effectPlaying popUp isPopUp record This event is no longer dispatched by UIComponent. regenerateProtoChain() regenerateStyleCache() scrollTrackColor Removed. setFocusLater() This method is now private.
The alpha, scaleX, and scaleY properties NO TE This change formerly applied to the UIObject class, but because UIObject and UIComponent have been combined into a single base class, the change now applies to the UIComponent class. The alpha, scaleX, and scaleY properties now range from 0 to 1 instead of from 0 to 100. For example, to make a UIObject 50% opaque, specify alpha=0.5 instead of alpha=50. To stretch the object horizontally by a factor of two, specify scaleX=2 instead of scaleX=200.
getURL() method NO TE This change formerly applied to the UIObject class, but because UIObject and UIComponent have been combined into a single base class, the change now applies to the UIComponent class. In Flex 1.5, every UIObject inherited the getURL() method from the MovieClip class. This is no longer the case. You now use the navigateToURL() method in the flash.
Enumerated values are now constants In many cases, properties that took a predefined list of values (such as the Button control’s labelPlacement property taking right, left, bottom, and top) now take class constants as well. For example, the labelPlacement property can now take one of the following constants: ■ ButtonLabelPlacement.RIGHT ■ ButtonLabelPlacement.LEFT ■ ButtonLabelPlacement.BOTTOM ■ ButtonLabelPlacement.
mx.core.UITextFormat The following table describes the changes to the UITextFormat class: Member Change description isFontFaceEmbedded Moved to the SystemManager class. mx.core.View The mx.core.View class has been removed and its functionality has been distributed between the SWFLoader (formerly Loader), ScrollControlBase (formerly ScrollView), and Container classes. Object creation and destruction methods that were on the View class have been removed.
mx.containers.Accordion The following table describes changes to the Accordion class: Member Change description Child indices The types have been changed from uint to int. change Dispatched when a user clicked on an Accordion header or when you programmatically set the value of the selectedIndex property to a new number. Now the Accordion container dispatches a change event only when a button is pressed. The Accordion container dispatches a valueCommit event in both cases.
mx.containers.ApplicationControlBar The following table describes changes to the ApplicationControlBar class: Member Change description borderStyle Can no longer be set on ApplicationControlBar. fillAlphas The default value has changed to [0,0]. fillColor Is now fillColors (with an s). The default value is [0xFFFFFF, 0xFFFFFF]. mx.containers.Box The following table describes the changes to the Box class: Member Change description marginBottom paddingBottom marginTop paddingTop mx.containers.
mx.containers.DividedBox The following table describes changes to the DividedBox class: Member Change description dividerDragged dividerDrag dividerPressed dividerPress dividerReleased dividerRelease getDividerCount numDividers horizontalCursor horizontalDividerCursor verticalCursor verticalDividerCursor mx.containers.dividedboxclasses.* The dividedboxclasses package is now named dividedBoxClasses. mx.containers.
mx.containers.FormItem The following table describes changes to the FormItem class: Member Change description labelObject This property is now internal only. marginBottom paddingBottom marginRight paddingRight marginTop paddingTop mx.containers.gridclasses.* The gridclasses package is now named dataGridClasses. mx.containers.GridRow The GridRow class now subclasses HBox instead of Box. mx.containers.
The following table describes changes to the LinkBar class: Member Change description click itemClick marginBottom paddingBottom marginTop paddingTop strokeColor separatorColor strokeWidth separatorWidth mx.containers.NavBar The mx.containers.NavBar class has been moved to mx.controls.NavBar. The following table describes changes to the NavBar class: Member Change description click itemClick "none selected" The special value for "none selected" is -1 instead of NaN.
Member Change description modalTransparency The range for this property is now 0 to 1, instead of 0 to 100. panelAlpha borderAlpha panelBorderStyle roundBottomCorners statusStyleDeclaration Removed. Use the statusStyleName style. statusTestField This property is now protected. titleStyleDeclaration Removed. Use the titleStyleName style. titleTestField This property is now protected. mx.containers.TabBar The mx.containers.TabBar class has been moved to the mx.controls package.
Member Change description getTabAt Parameter renamed from i to index. tabSkin tabStyleName mx.containers.Tile The following table describes changes to the Tile class: Member Change description marginBottom paddingBottom marginTop paddingTop mx.containers.TitleWindow The following table describes changes to the TitleWindow class: Member Change description closeButton showCloseButton In Flex 1.x, clicking on the close button (and only the close button) generated a click event.
mx.containers.ViewStack The following table describes changes to the ViewStack class: Member Change description Child indices The type of the child indices in the ViewStack container has been changed from uint to int. cachePolicy The ViewStack container no longer overrides the cachePolicy property. changeEffect Use the showEffect and hideEffect effect triggers of children of the ViewStack container instead.
Member Change description show() The show() method now has the following signature: show(text:String, title:String=null, flags:uint=0x4, parent:Sprite=null, closeHandler:Function=null, iconClass:Class=null,defaultButtonFlag:uint=0x4):A lert titleStyleDeclaration Removed. Use the titleStyleName style. mx.controls.alertclasses.* The alertclasses package is now named alertClasses. mx.controls.Button The Button class no longer inherits from SimpleButton.
Member Change description trueUpSkin selectedUpSkin version Removed. mx.controls.ButtonBar The following table describes changes to the ButtonBar class: Member Change description click itemClick mx.controls.ButtonBarButton The ButtonBarButton class has been made internal only. mx.controls.CalendarLayout The following table describes changes to the CalendarLayout class: Member Change description background This property is now internal only. backMonthButton This property is now internal only.
Member Change description upYearButton This property is now internal only. upYearHit This property is now internal only. weekDayStyleDeclaration weekDayStyleName yearDisplay This property is now internal only. mx.controls.ColorPicker The following table describes changes to the ColorPicker class: Member Change description closeEasing closeEasingFunction marginBottom paddingBottom marginLeft paddingLeft marginRight paddingRight marginTop paddingTop openEasing openEasingFunction mx.
mx.controls.ComboBox The following table describes changes to the ComboBox class: Member Change description alternatingRowColors alternatingItemColors cellRenderer itemRenderer dataChanged dataChange textDisabledColor disabledColor itemSkin itemRenderer openEasing openEasingFunction selectionEasing selectionEasingFunction mx.controls.DataGrid The DataGrid class now extends the new GridBase class, which extends the ListBase class.
Member Change description headerColor headerColors headerStyle headerStyleName hGridLineColors horizontalGridLineColors hGridLines horizontalGridLines hPosition horizontalScrollPosition minColWidth minColumnWidth removeAllColumns() Removed. removeColumnAt() Removed. setColumnIndex Removed. vGridLineColors verticalGridLineColors vGridLines verticalGridLines In Flex 2, when a DataGrid control’s width is not wide enough to show all columns, only the first column gets smaller.
mx.controls.dataGridClasses.DataGridListData The following table describes changes to the DataGridListData class: Member Change description columnName dataField mx.controls.DateChooser The following table describes changes to the DateChooser class: Member Change description background This property is now internal only. backMonthButton This property is now internal only. backMonthHit This property is now internal only. border This property is now internal only.
Member Change description weekDayStyleDeclaration weekDayStyleName yearDisplay This property is now internal only. mx.controls.DateField The following table describes changes to the DateField class: Member Change description dataChanged dataChange formattingFunction labelFunction headerStyleDeclaration headerStyleName headerColor Removed. Replaced with the dateChooserStyleName property. headerColors Deprecated. Replaced with the dateChooserStyleName property.
mx.controls.HRule The following table describes changes to the HRule class: Member Change description color strokeColor mx.controls.HSlider The following table describes changes to the HSlider class: Member Change description labelStyleDeclaration Removed. Use the labelStyleName style instead. showTicks Removed. Instead of setting it to false to turn off tick marks, you set tickInterval to 0; for example: toolTipStyleDeclaration Removed.
mx.controls.List The following table describes changes made to the List class: Member Change description cellBeginEdit itemEditBegin cellEditor itemEditorInstance cellEndEdit itemEditEnd cellFocusIn itemFocusIn cellFocusOut itemFocusOut cellRequestEdit itemEditBeginning editedCell editedItemRenderer focusedCell editedItemPosition getItemAt() DataProvider APIs are no longer on the list-based classes. Instead of myList.getItemAt(index), you use myList.dataProvider.getItemAt(index).
mx.controls.listclasses.ListBase The following table describes changes to the ListBase class: Member Change description activeTabStyleDeclaration SelectedTabStyleName alternatingRowColors alternatingItemColors cachedPaddingBottom This property is now internal. cachedPaddingTop This property is now internal. cachedVerticalAlign This property is now internal.
mx.controls.listClasses.ListCellRenderer The ListCellRenderer class is now named ListItemRenderer. The following table describes changes to the ListItemRenderer class: Member Change description dataChanged dataChange mx.controls.listClasses.TileListItemRenderer The following table describes changes to the TileListItemRenderer class: Member Change description dataChanged dataChange mx.controls.Loader The mx.controls.Loader class name has changed to mx.controls.SWFLoader.
mx.controls.Menu The following table describes changes to the Menu class: Member Change description alternatingRowColors alternatingItemColors cellRenderer listItemRenderer change itemClick defaultIcon Removed. getMenuItemAt() Removed. menuData This property is now internal. menuItemRollOut itemRollOut menuItemRollOver itemRollOver popupDuration openDuration setMenuItemSelected() This method has been made protected. rootVisible showRoot textDisabledColor disabledColor mx.controls.
mx.controls.menuclasses.* The menuclasses package has been renamed menuClasses. mx.controls.menuclasses.IMenuDataDescriptor The following table describes changes to the IMenuDataDescriptor class: Member Change description isSelected() isToggled() setSelected() setToggled() mx.controls.menuclasses.MenuCellRenderer The MenuCellRenderer class is now named MenuItemRenderer. The following table describes changes to the MenuItemRenderer class: Member Change description dataChanged dataChange mx.
Member Change description popUpObject popUp popUpOnMainButton openAlways mx.controls.PopUpMenuButton The following table describes changes to the PopUpMenuButton class: Member Change description change itemClick menuItemRollOut itemRollOut menuItemRollOver itemRollOver popUpObject popUp mx.controls.RadioButton The following table describes changes to the RadioButton class: Member Change description data value mx.controls.
mx.controls.richtexteditorclasses.* The richtexteditorclasses package is now named richTextEditorClasses. mx.controls.scrollClasses.ScrollBar The following table describes changes to the ScrollBar class: Member Change description maxPos maxScrollPosition minPos minScrollPosition thumbDisabledSkin Removed. mx.controls.SimpleButton The SimpleButton class has been removed. mx.controls.
Member Change description snapToTicks snapInterval thumbDragged thumbDrag thumbPressed thumbPress thumbReleased thumbRelease thumbWidth Removed. Use thumb skins to create custom thumbs. tickFrequency tickInterval tickHeight tickLength tickSpacing tickOffset toolTipFormatFunction dataTipFormatFunction toolTipOffset dataTipOffset toolTipPlacement dataTipPlacement toolTipPrecision dataTipPrecision toolTipStyleDeclaration Removed. Use the toolTipStyleName style.
Member Change description maxHPosition maxHorizontalScrollPosition password displayAsPassword underlineLink Removed. vPosition verticalSrollPosition vScrollPolicy verticalScrollPolicy mx.controls.textclasses.* The textclasses package has been renamed textClasses. mx.controls.
Flex 1.x: Flex 2: mx.controls.ToolTip The following table describes changes to the ToolTip class: Member Change description dropShadow dropShadowEnabled mx.controls.
mx.controls.treeclasses.* The treeclasses package is now named treeClasses. mx.controls.treeclasses.DefaultDataDescriptor The following table describes changes to the DefaultDataDescriptor class: Member Change description isBranch() Supports nodes in E4X XML, but not XMLNode objects or data that is serialized into ActionScript objects. isSelected() isToggled() setSelected() setToggled() mx.controls.treeClasses.TreeCellRenderer The TreeCellRenderer class is now named TreeItemRenderer.
Member Change description showTicks Removed. Instead of setting it to false to turn off tick marks, you set tickInterval to 0; for example: toolTipStyleDeclaration Removed. Use the toolTipStyleName style. Effects The “instance” classes (such as mx.effects.RotateInstance and mx.effects.ResizeInstance) have been moved to the mx.effects.effectClasses package. This section describes changes to individual effects classes.
mx.effects.EffectInstance The following table describes changes to the EffectInstance class: Member Change description repeat repeatCount stopRepeat This property is now internal. mx.effects.MaskEffect The following table describes changes to the MaskEffect class: Member Change description moveEasing moveEasingFunction scaleEasing scaleEasingFunction These changes also apply to the MaskEffectInstance class. mx.effects.
mx.effects.SoundEffect The following table describes changes to the SoundEffect class: Member Change description panEasing panEasingFunction soundHolder Renamed to the sound property. This property is now readwrite. volumeEasing volumeEasingFunction These changes also apply to the SoundEffectInstance class. mx.effects.Tween The following table describes changes to the Tween class: Member Change description easing easingFunction mx.effects.
Events All events in the mx.collections package were moved to the mx.events package. In addition to the changes listed here, the events architecture has changed. For more information, see Chapter 6, “Events,” on page 111. mx.events.ChildExistenceChangedEvent The following table describes changes to the ChildExistenceChangedEvent class: Member Change description CHILD_ADDED CHILD_ADD CHILD_REMOVED CHILD_REMOVE mx.events.
mx.events.DataGridEvent The following table describes changes to the DataGridEvent class: Member Change description cell itemRenderer CELL_BEGIN_EDIT ITEM_EDIT_BEGIN CELL_END_EDIT ITEM_EDIT_END CELL_FOCUS_IN ITEM_FOCUS_IN CELL_FOCUS_OUT ITEM_FOCUS_OUT CELL_REQUEST_EDIT ITEM_EDIT_BEGINNING CELL_PRESS Removed. cellRenderer itemRenderer columnName dataField itemIndex rowIndex itemSkin itemRenderer view Removed. Use target instead. mx.events.
mx.events.DropdownEvent The following table describes changes to the DropdownEvent class: Member Change description inputType triggerEvent mx.events.EventDispatcher This class has been moved to flash.events.EventDispatcher and is no longer used as a mixin. mx.events.FlexEvent The following table describes changes to the FlexEvent class: Member Change description DATA_CHANGED DATA_CHANGE DATA_OBJECT_CHANGED DATA_CHANGE DRAW UPDATE_COMPLETE VALUE_COMMITED VALUE_COMMIT mx.events.
mx.events.ListEvent The following table describes changes to the ListEvent class: Member Change description cell itemRenderer CELL_BEGIN_EDIT ITEM_EDIT_BEGIN CELL_END_EDIT ITEM_EDIT_END CELL_FOCUS_IN ITEM_FOCUS_IN CELL_FOCUS_OUT ITEM_FOCUS_OUT CELL_REQUEST_EDIT ITEM_EDIT_BEGINNING cellRenderer itemRenderer itemIndex rowIndex itemSkin itemRenderer mx.events.
Member Change description menuItemRollOut itemRollOut menuItemRollOver itemRollOver mx.events.MouseEvent The MouseEvent class is now called FlexMouseEvent. Do not confuse this with the flash.events.MouseEvent class, which still exists. The following table describes changes to the mx.events.MouseEvent class: Member Change description MOUSE_SCROLL_OUTSIDE MOUSE_WHEEL_OUTSIDE mx.utils.events.ObjectEvent The ObjectEvent class is now named and is moved to mx.events.PropertyChangeEvent. mx.utils.
Member Change description SHOW_TOOL_TIP TOOL_TIP_SHOW SHOWN_TOOL_TIP TOOL_TIP_SHOWN START_TOOL_TIP TOOL_TIP_START mx.events.TreeEvent The following table describes changes to the TreeEvent class: Member Change description CELL_PRESS Removed. cellRenderer itemRenderer inputType triggerEvent itemSkin itemRenderer mx.events.UIEventDispatcher This class has been removed. Formatters This section describes changes to formatters. mx.formatters.
The following table describes the changes to the NumberBase class: Member Change description dSymbolFrom decimalSeparatorFrom dSymbolTo decimalSymbolTo tSymbolFrom thousandsSeparatorFrom tSymbolTo thousandsSeparatorTo mx.formatters.SwitchSymbolFormatter The following table describes the changes to the SwitchSymbolFormatter class: Member Change description isValid This is now private. numberSymbol This is now private.
Old name New name IFocusManager Removed. Refer to mx.managers.FocusManager instead. IFocusManagerContainer mx.managers.IFocusManagerContainer IHistoryState mx.managers.IHistoryManagerClient IInteractionReplayer mx.automation.IAutomationReplayer ILayoutClient mx.managers.ILayoutManagerClient ILayoutManager mx.managers.LayoutManager IObjectChanged mx.core.IPropertyChangeNotifier IRecorder Removed. IRepeaterContainer Removed. Refer to mx.core.Container instead. IScrollBar Removed.
mx.managers.DragManager Instead of setting event.handled inside the dragEnter event listener, you must call the DragManager.acceptDragDrop(event.target) method. You cannot set the action property of the event object. Instead, you must call the setFeedback() method. For example, change the following code: event.action=DragManager.Link; to the following: DragManager.showFeedback(DragManager.LINK); This applies to all actions: MOVE, LINK, COPY, NONE. The signature to the doDrag() method has changed.
mx.managers.PopUpManager The following table describes changes to the PopUpManager class: Member Change description closeButton The default value of the closeButton property is now false. To enable a close button on your pop-ups, you must explicitly set the value of the closeButton property to true. createPopUp() The createPopUp() method now takes only three arguments, and returns an IFlexDisplayObject. You can no longer pass an initObj to the createPopUp() method.
Media controls This section describes changes to media controls in Flex 2. mx.controls.MediaDisplay The MediaDisplay control has been replaced by the mx.controls.VideoDisplay control. The API is the same, but it does not support MP3 files. mx.controls.MediaController The MediaController control has been removed. Use the VideoDisplay control instead. mx.controls.MediaPlayback The MediaPlayback control has been removed. Use the VideoDisplay control instead. mx.controls.
mx.print.PrintJobType The following table describes the changes to the PrintJobType class: Member Change description HEIGHT MATCH_HEIGHT WIDTH MATCH_WIDTH Resources This section provides information about changes to classes in the mx.resources package. mx.resource.* The mx.resource package is now named mx.resources. Service tags This section describes changes to Flex classes in the mx.servicetags package. In addition to the changes here, the Flex data services architecture has changed.
mx.servicetags.RemoteObject The RemoteObject class was moved to mx.rpc.remoting.RemoteObject. It now extends the mx.rpc.AbstractService class. The following table describes changes to the RemoteObject class: Member Change description encoding Removed. endpoint Was removed. Channels defined in the flex-services.xml file replace the need for this property. Has been added again to allow clients to use this tag without the configuration file at compile time. named Removed. Use the destination property.
Callback URLs Callback URLs are no longer necessary in Flex 2. Use messaging channels with endpoint mappings instead. Skins This section describes changes to Flex classes in the mx.skins package. For more information, see “Using skinning” on page 124. mx.skins.halo.RectBorder This class is now named HaloBorder. mx.skins.halo.PopUpIcon The following table describes changes to the PopUpIcon class: Member Change description arrowColor This property is now private. mx.skins.
States This section provides information about changes to classes in the mx.states package. mx.states.AddChild The following table describes changes to AddChild class: Member Change description added This property is now internal. instanceCreated This property is now internal. target relativeTo mx.states.SetEventHandler The following table describes changes to SetEventHandler class: Member Change description event name mx.states.
Utilities This section provides information about changes to classes in the mx.utils package. mx.utils.XMLUtil The following table describes changes to XMLUtil class: Member Change description createXML() createXMLDocument() Validators This section provides information about changes to classes in the mx.validator package. mx.validator.
Flex Classes
CHAPTER 4 4 Data Providers This topic describes migrating data providers, including the dataProvider property of Flex controls and the ways you access and manipulate the data represented by the dataProvider property. For detailed information on using data providers in Flex 2, see Chapter 7, “Using Data Providers and Collections,” in Flex 2 Developer’s Guide. The DataProvider interface and class no longer exist and have been replaced by the collection package hierarchy.
The following information briefly describes major migration issues: ■ Because the DataProvider interface has been replaced by methods of the collection classes, controls that have dataProvider properties do not include any of the DataProvider interface methods, such as getItemAt(). Instead, you manipulate the control contents by manipulating the object, normally a collection, that acts as the data source. You can use the methods on the dataProvider property or on the collection object directly.
■ The Tree, Menu, MenuBar, and PopUpMenuButton controls, now use a data descriptor class to access and manipulate control-specific information, such as menu item type, that is contained in the data provider. Tree controls require a class that implements the ITreeDataDescriptor interface, and menu-based controls require a class that implements the IMenuDataDescriptor interface.
Data Providers
CHAPTER 5 5 Binding This topic describes the steps required to convert properties in your applications to be usable as the source for a data binding expression in Adobe Flex. For more information binding, see Chapter 5, “Using Metadata Tags in Custom Components,” in Creating and Extending Flex 2 Components. Contents About binding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Binding from a property . . . . . . . . . . . . . . . .
The tag must be a top-level tag In Flex 1.5, you could place the tag in a Flex container. In Flex 2.0, the tag must be a top-level tag in the MXML file. For example: Flex 1.x: Flex 2: PAGE 107The Flex compiler automatically generates an event named propertyChange for all public properties so the properties can be used as the source of a data binding expression. In this case, specifying the [Bindable] metadata tag with no event is the same as specifying the following: [Bindable(event="propertyChange")] Binding from a single property To make a single property usable as the source for a data binding expression, add the [Bindable] metadata tag before the property declaration.
The following is a Flex 2 example of a getter/setter pair that uses the [Bindable] metadata tag: // Define private variable. private var _maxFontSize:Number = 15; [Bindable(event="maxFontSizeChanged")] // Define public getter method. public function get maxFontSize():Number { return _maxFontSize; } // Define public setter method. public function set maxFontSize(value:Number):void { if (value <= 30) { _maxFontSize = value; } else _maxFontSize = 30; // Create event object.
Dispatching binding events from a custom component To dispatch an event to trigger data binding for a property, the property’s class must either extend EventDispatcher or implement the IEventDispatcher interface. Be sure to update the object that is passed to the dispatchEvent() method. You must use the new Event class and not a generic Object. For more information on converting events, see “Migrating the Event object” on page 113.
Binding with Flex component properties You can no longer use all properties of Flex components as the source of a data binding expression without extending those controls. Properties of Flex components that can be used as the source of a data binding expression contain the following description in their entry in the ActionScript 3.0 Language Reference: This property can be used as the source for data binding. Binding with Arrays In Flex 1.
CHAPTER 6 6 Events This topic describes changes to the Adobe Flex 2 event model for developers who are migrating Flex applications. Contents About events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .112 Component startup life cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .112 Migrating the Event object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
About events The following list is a general overview of the changes to the Event model. Review all event handling in your Flex application by using these guidelines. ■ All event objects are either of type Event or a subclass of Event. You should explicitly declare or cast them to their appropriate type. ■ Use static constants such as MouseEvent.CLICK instead of string literals for the event type, such as “click”. For more information, see “Using static constants” on page 114.
Migrating the Event object This section describes migration issues related to accessing the Event object. Using the Event object The Event object is no longer of type Object. It is now of type flash.events.Event. Specify a stricter type in functions, as follows: private function eventHandler(event:Object):Void { // Flex 1.5 private function eventHandler(event:Event):void { // Flex 2 You should also now cast the event.target in an event handler to an appropriate type to avoid compile-time warnings.
If you try to call another method on the target (for example, the getStyle() method), Flex returns an error. The getStyle() method is a method of UIComponent, a subclass of DisplayObject. Therefore, you must cast event.target to UIComponent before calling the getStyle() method, as the following example shows: function myEventListener(e:Event) { UIComponent(e.target).
To find the appropriate static constant for your event type, see the events section of the control’s entry in Adobe Flex 2 Language Reference. Using function listeners When migrating, convert all object event listeners to function event listeners. You can no longer pass an object as the second parameter to the addEventListener() method. The listener argument of the addEventListener() method was of type Object, which also accepted a Function, but is now of type Function.
You must also change your code if you created a custom event handler class and defined a handleEvent() method that listened for all events. Flex implicitly registered this method as a handler for all events. Functions named handleEvent() no longer catch all events by default as they did in Flex 1.x. For example, if in your application you registered the custom listener with the method, as follows: addEventListener() public var myListener:MyEventListener = new MyEventListener(); b1.
Maintaining scope Previously, you used the mx.utils.Delegate class to provide access to the document scope within an event handler. You would pass the Delegate object into a call to the addEventListener() method so that the listener would execute in that scope. This is no longer necessary. The event listener’s scope is now the class in which it is declared as a function, which is in most cases the scope you should expect; for example: Flex 1.x: addEventListener("click", mx.utils.Delegate.
Events
CHAPTER 7 7 Styles and Skinning This topic describes styleable objects; new skinning workflow; and CSS rules. For information about changes to individual classes such as ProgrammaticSkin, see Chapter 3, “Flex Classes,” on page 41. Contents Using styles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .119 Using skinning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Using the StyleManager When you use the StyleManager to apply styles to entire classes, you must now access the class with the getStyleDeclaration() method. For example: Flex 1.x: StyleManager.styles.Button.setStyle("color","red"); Flex 2: StyleManager.getStyleDeclaration("Button").setStyle("color","red"); You can no longer set or get styles as properties of a component or class. You now use setStyle() and getStyle(). This also applies to using StyleManager.
Changed style properties The following table shows changes to the CSS style property names: Flex 1.
The following are the valid color value formats in CSS: .b1 .b2 .b3 .b4 .b5 { { { { { color: color: color: color: color: red; } #66CC66; } rgb(22%,22%,77%); } rgb(255,0,0); } "0xFFFF00"; } The following are the invalid color value formats in CSS: .b6 .b7 .b8 .b9 { { { { color: color: color: color: 0xFFFF00; } /* Results in a compiler error. */ "red"; } /* Fails silently; color is black. */ "#FFFF00"; } /* Fails silently; color is black. */ 100%, 0%, 0% ; } /* Results in a compiler error.
For example: // The following class selector fails in Flex 2 if // there is no associated class: myClass { color: red; } // The following class selector works fine in Flex 2: .myOtherClass { color: red; } You must include the period when you use the getStyleDeclaration() method. Global style sheet The global style sheet, global.css, was removed. Flex now uses a default style sheet, defaults.css, which is in the frameworks.swc file. If you are migrating an existing 1.
Using units Flex no longer supports using the plus (+) and minus (-) unit modifiers. Flex no longer supports the em and ex unit types. Using skinning Previously, you defined graphical skins as symbols in a FLA file, exported the FLA file as a SWC file from the Flash IDE, and added it to your Flex source path. The symbols in the new SWC file replaced existing symbols in Flex component skins. Now, all skins are specified as style properties that can be set through CSS or inline.
Skinning assets The assets that Flex includes for you to use as a basis for reskinning components are changed. Flex 1.x included: Flex 2 includes: • Sample programmatic skins in the flex_install_dir/resources/themes/ programmatic directory. • HaloClassic skins for users who want the original look and feel of Flex applications. • Halo programmatic skins, which are in the • Graphical skins in the pulseBlue.fla and mx.skins.halo package. pulseOrange.
Using embedded fonts You mjust use some differences in the syntax for embedded fonts. In addition, the default font manager is changed. The default font manager is actually both the Batik font manager and the JRE font manager. You set them in the list of font managers in the flex-config.xml file. This is a reverse ordered precedence. The preferred Batik font manager doesn’t handle all embedded font commands, so what it doesn’t handle, it passes to the JRE font manager. In Flex 1.
In Flex 1.5, you could use the following syntax to embed a bold italic font face: @font-face { src: url("GOTHICBI.TTF"); font-style: italic; font-weight: bold; font-family: myFont; } .myStyleBoldItalic { font-family: myFont; } In Flex 2, you still use the @font-face rule to embed the font: @font-face { src:url("GOTHICBI.TTF"); font-style: italic; font-weight: bold; font-family: myFont; } But you then add descriptors to the class or type selector to use the embedded font face: .
Styles and Skinning
CHAPTER 8 8 Behaviors This topic describes the new architecture for behaviors in Macromedia Flex and syntax changes from Flex 1.5. For detailed information, see Chapter 17, “Using Behaviors,” in the Flex 2 Developer’s Guide and Chapter 15, “Creating Effects,” in Creating and Extending Flex Components. Contents Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 New Behaviors syntax. . . . . . . . . . . . . . . . . . .
Overview Flex implements effects using an architecture in which each effect is represented by two classes: ■ Creates an object of the instance class to perform the effect on the target. You create instances of the factory class in your application, and configure it with the necessary properties to control the effect, such as the zoom size or effect duration. You then assign the factory class instance to a target component, as the following example shows: Factory class {phoneInput.
In ActionScript, you can use the following constants: ■ CreditCardValidatorCardType.AMERICAN_EXPRESS ■ CreditCardValidatorCardType.DINERS_CLUB ■ CreditCardValidatorCardType.DISCOVER ■ CreditCardValidatorCardType.MASTERCARD ■ CreditCardValidatorCardType.VISA Deprecated methods, properties, and events The following validator methods, properties, and events were deprecated: Deprecated item New item Validator.enable() and Validator.enabled property Validator.disable() methods Validator.
Embedding resources In Flex 1.5, embedded resources were bound to Strings that were used to reference the individual images by name. Although the preferred method of embedding resources in Flex 2 uses Class variables, you can still use String variables for some level of backward compatibility. However, the various objects and tags that use your embedded assets expect them to be tied to Class variables, so you need to use the getDefinitionByName() method to cast your string variables.
CHAPTER 13 13 Migration Patterns This topic describes some common patterns in migrating ActionScript in Adobe Flex applications. Contents Instantiating Flex controls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Using mixins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 Variable enumeration and object introspection . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Instantiating Flex controls In Flex 1.x, you created a Flex control in ActionScript by first including a reference to that control, and then using the createEmptyObject(), createChild(), createChildren(), createChildAtDepth(), or createClassChildAtDepth() method. These methods were removed. In Flex 2, you use the new operator to create child controls and attach the control to a container with the addChild() or addChildAt() method. For example: Flex 1.
Using mixins You can no longer attach a function to a class, unless that class has prior knowledge of that function. For example, you can no longer do this: UIComponent.prototype.doSomething = myFunction or this: dataGridInstance.doSomething = myFunction You can still declare a Function type property on an Object and then supply an implementation of that function later.
Variable enumeration and object introspection In Flex 1.x (ActionScript 2.0), using a for-in loop on an object let you enumerate over all properties on an object. In Flex 2 (which uses ActionScript 3.0), only dynamically added properties are enumerated by for-in loops. Declared variables and methods of classes are not enumerated in for-in loops. This means that most classes in the ActionScript API do not display any properties in a for-in loop.
// List accessors as properties: for each (var a:XML in classInfo..accessor) { ta1.text += "Property " + a.@name + "=" + button1[a.@name] + " (" + a.@type +")\n"; } // List the object's methods: for each (var m:XML in classInfo..method) { ta1.text += "Method " + m.@name + "():" + m.
Using the drag-and-drop feature When you convert drag-and-drop code, be aware of the following changes: ■ The doDrag() method takes an additional required attribute, mouse_event. This attribute is the MouseEvent object that contains the mouse information for the start of the drag. ■ All drag-and-drop-specific events are now DragEvent class events. ■ For a drop target to accept an item for dropping, it must call the acceptDragDrop() method, not use the event.handled property.
Flex 2:
Other issues In addition to the changes shown here, you might also encounter the issues described in this section when you convert drag-and-drop code. Accessing event targets Because a TextArea control uses a Flash TextField control, and mouse events are dispatched by Flash Player, not Flex, you must use the currentTarget property instead of the target property in the doDrag() method when you start a drag from a TextArea control.
Controlling the feedback indicator To control the feedback indicator that accompanies a drag proxy, you now use the new showFeedback() and getFeedback() methods of the DragManager class. The indicator shows what happens if you try to drop the item; for example, a red circle with a white x represents an aborted drop, or a green circle with a white plus (+) indicates a valid drop. In Flex 1.x, you could change the feedback indicator with the action property of the event.
Using Timer The setInterval() and clearInterval() methods were deprecated in favor of the Timer class. You can still use these methods; they are in the flash.util package. When you use Timers, keep the following in mind: ■ When a Timer is first created with the new operator, it is stopped; you must use the start() method to start it. ■ Instances of the Timer class dispatch events that you handle like any other event.
Using the Preloader The Application container supports an application preloader that uses a download progress bar to show the download progress of an application SWF file. By default, the application preloader is enabled. The preloader keeps track of how many bytes are downloaded and continually updates the progress bar. By default, the application preloader uses the DownloadProgressBar class in the mx.preloaders package to display the download progress bar.
In Flex 2, you must use the Application.application.parameters property to get the values of these variables. The parameters property is an Object, which is a dynamic class that you can use to store name and value pairs pass in as flashVars variables. The following example sets variables by using the Flex 2 syntax: public var fName:String = Application.application.parameters.firstname; public var mName:String = Application.application.parameters.middlename; public var lName:String = Application.