PureMVC Architects Lounge

PureMVC Manifold => MultiCore Version => Topic started by: spacecom on April 21, 2008, 01:49:11



Title: How to remove widgets previously loaded dynamically
Post by: spacecom on April 21, 2008, 01:49:11
I would like to know how would you remove the coolwidget dynamically that has been previously loaded into the WidgetCanvas.mxml when clicking on superwidget button prior to the super widget been loaded into the WidgetCanvas.mxml?

Currently you click the coolwidget button and the coolwidget is loaded into WidgetCanvas.mxml, if you click on the superwiget button a super widget is added to the WidgetCanvas.mxml. The WidgetCanvas nows contains both the cool and super widget buttons.

I want to remove any previous widget that is loaded to the WidgetCanvas.mxml before the new widget is loaded. What actionscript code will remove the previously loaded widget before the new widget is loaded to the WidgetCanvas.mxml.

This code is found on line: 46 of the coolWidgetMediator.as, what would the process be to do this dynamically?

:
// Handle clicks to the buttons added to the widget canvas
protected function onComponentClick( event:MouseEvent ):void
{
var component:DisplayObject = event.target as DisplayObject;
coolWidget.widgetShell.removeComponent( component );
component.removeEventListener( MouseEvent.CLICK, onComponentClick );
coolWidget.widgetShell.setStatusMessage( 'Removed CoolWidget-generated display object from Widget Canvas')
}

Wayne


Title: Re: How to remove widgets previously loaded dynamically
Post by: puremvc on April 21, 2008, 05:47:51
It all depends.You could simply have the WidgetCanvasMediator remove any child of the canvas before adding a new component when it responds to ADD_COMPONENT.

However that leaves the button and ots Mediator back in the other widget and no way to garbage collect them.

You'd probaly want all components that will be added to the canvas to implement an interface such as ICanvasComponent, say This interface would call for a remove method, which would send an event that its mediator would hear and trigger the REMOVE_COMPONENT sequence in the same way as clicking does now.

The WidgetCanvas would expose a method addComponent, that would go through its children and call remove on each ICanvasComponent before adding the new component.

Note I'm pushing that blackbox logic into the WidgetCanvas itself rather than the Mediator.
-=Cliff>