Book Shelf
Our Products
Component News
Stay informed on our latest component releases and specials.
Understanding add-remove clients
Adding client IUIComponents
The UIManager, the resize and move manager's parent, maintains a client queue that is used in all manager operations. To successfully use the manager and overlay's you must call one of the 3 methods listed below;
addClient(client:IUIComponent):BooleanaddClients(components:Array):BooleanaddParentClient(parentComponent:IUIComponent, excludeComponents:Array = null):Boolean
The manager will then add a client overlay to the client or clients if the style hitTestType is 'overlay'. The manager also registers event listeners on the client for other various operations it must perform to maintain the client overlay.
addClient()
The addClient() method will add a single client to the manager's queue.
ResizeManagerFX.addClient(myWindow);
The myWindow instance is now resize enabled by this single call.
addClients()
The addClients() method adds an array of clients to the manager's queue. This as it seems it just a shortcut for the developer not to have to write a loop to add a list of client UIComponents.
var clients:Array = [myButton1, myButton2]; ResizeManagerFX.addClients(clients);
addParentClient()
The addParentClient()method adds all the children of a parent Container to the manager's queue minus the excludes array in the second parameter.
ResizeManagerFX.addParentClient(myCanvas);
All of the methods above assume you are adding a component that implements the IUIComponent interace. Using addClient() and passing a non IUIComponent will result in a runtime exception. Also, if you pass a non IUIComponent in the multiple add client methods, you will also get a runtime exception during the add process.
Each of the add/remove methods return a Boolean indicating if the manager’s operation succeeded. If the operation failed, it is due to the fact the client already exists in the manager's queue. There is no harm or error thrown if this situation occurs.
NOTE :: In versions up to 2.0.x of the resize and move manager, the parent of a manager client can only be held within a mx.core.Container subclass. Check the issue link to see whn this has been resolved;
Removing client IUIComponents
The manager removes clients as easy as it adds them with 3 specific methods;
removeClient(client:IUIComponent):BooleanremoveClients(components:Array):BooleanremoveParentClient(parentComponent:IUIComponent):Boolean
removeClient()
The removeClient() method will remove a single client from the manager's queue.
ResizeManagerFX.removeClient(myWindow);
removeClients()
The removeClients() method removes an array of clients from the manager's queue. This as it seems it just a shortcut for the developer not to have to write a loop to remove a list of client UIComponents.
var clients:Array = [myButton1, myButton2]; ResizeManagerFX.removeClients(clients);
removeParentClient()
The removeParentClient()method removes all the children of a parent Container from the manager's queue.
ResizeManagerFX.removeParentClient(myCanvas);
Client Life Cycle
When a component is added or removed from a Container, the FlexEvent.ADD and FlexEvent.REMOVE events are fired. The manager framework is not responsible for cleaning up after one of these two events. When you explicitly remove a client of the manager from a Container, you must call removeClient() on the client being removed.
The manager does use weak references in it's event listeners but, it is still required by the developer to remove the client from the manager.
It has been tossed around to have the manager listen for the FlexEvent.REMOVE but, it is better form to have a developer remove something than continually add it if they do not want the functionality to be removed.
Enabling and Disabling resize and move
If you find yourself needing to disable and re-enable a component's move or resize functionality, you can set the resizeEnabled or moveEnabled styles of the client or it's styleName to false.
You do not need to call the add or remove methods of the manager to temporarily disable it's function.
myCanvas.setStyle("resizeEnabled", false); myCanvas.setStyle("moveEnabled", false); // then later when you need this functionality back myCanvas.setStyle("resizeEnabled", true); myCanvas.setStyle("moveEnabled", true);
In the above example, there is a lot less processing going on by setting a style and if you are using overlays, they will not be recreated, just set to invisible.
Conclusion
The manager framework provides a solid public static interface for adding and removing clients for it's desired operations.
©2003-2008 Teoti Graphix, LLC - All rights reserved.
