There have been some reports of runtime errors when Applications are loading multiple sub-applications (such as Modules and/or PopUps) from a single Application. One of the bugs with an example that I uploaded can be found here: SDK-13152. In the sample bugfile included with this bug, you can create a popup from a loaded module with no problem. However, once you unload the module and re-load it, you will get an error when attempting to create a popup from that module. The runtime error that you will get is:
TypeError: Error #1034: Type Coercion failed: cannot convert mx.managers::PopUpManagerImpl@13068c1 to mx.managers.IPopUpManager.
at mx.managers::PopUpManager$/get impl()
To get around this error, you need to include the IPopUpManager class in your main Application:
private var iPopUpManager:IPopUpManager;
According to our developers, because of the design of the SingletonManager that supports a bootstrap topology, any time you get into a similar topology (where multiple sub-applications are loaded in a main Application), you need to move shared interfaces into the bootstrap. In this case it is the IPopUpManager, which we can be moved into the main application (effectively the bootstrap) via this two-line workaround.
A similar bug is reported with multiple sub-applications using the DragManager. Details can be found in SDK-995. In this scenario, the Application loaded different swfs using the SWFLoader into various views of a TabNavigator. These swfs both included a DataGrid using the DragManager. To get around the error, the Application needed to include:
private var iDragManager:IDragManager;
I just discovered that we could include <mx:UIComponent> in any mxml page. I had no idea :p, but, this could certainly be useful. Internally, someone asked how they could add something like a Sprite or a Video object to a Flex container (rather than using the VideoDisplay provided by Flex). Here were some basic guidelines from Alex Harui that I thought might come in handy for some of you:
1. Navigator children must be Containers.
2. Container children must be IUIComponents.
3. UIComponent children can be anything.
So, to add something like a Sprite to your Container, you would wrap the Sprite in a UIComponent. Here is an example:
<mx:UIComponent id=”spriteWrapper” initialize=”spriteWrapper.addChild(new Sprite(…))” />
Again, I’ve seen the question asked on several occasions regarding how to cancel a drag of an item between List components. The List components all have the drag events: dragEnter, dragExit, dragOver, dragComplete, and dragDrop. Each of these can be overridden with a custom event handler. If you call event.preventDefault() in your custom event handler, you will cancel the default behavior of this event in the List classes. For example, in the sample below, I call event.preventDefault() within the custom dragDrop handler of the destination List. This causes the item to not get added to the destination List and the item is not removed from the initiating List. When you are deciding which events to customize to achieve the drag and drop action you want, you can use this as a general summary of what each event does:
|dragStart: This event is triggered on the initiating List. A dragSource is created and the drag begins by calling doDrag on the DragManager.dragEnter: This event is triggered on the target destination List. In the event handler, a drag is accepted or rejected. Drop feedback is shown depending on if this is a copy or move.dragExit: This event is triggered on the target destination List if the item leaves the List without dropping an item. The event handler hides the feedback icon.
dragDrop: This event is triggered on the target destination List when an item is dropped over the List. This event adds the item to the list and hides the feedback icon.
dragComplete: This event is triggered on the initiating List. The event handler removes the item from the list if the drag was a move.
In the sample that I’m providing, I have two Lists. The first List includes the name of a guest and a number of people attending in their group. You should be able to drag items from the first List to the second List until the total number of people “attending” in the second list is greater than 5. In the code, I am increasing the value of a global variable “totalGuests” whenever an item is added to the second list. In the custom dragDrop handler for this second List, the value of totalGuests is checked. If this value is greater than 5, then, the drag is cancelled.
Sample code: dragExample.mxml