Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: How to remove widgets previously loaded dynamically  (Read 8251 times)
spacecom
Newbie
*
Posts: 6


View Profile Email
« 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
« Last Edit: April 21, 2008, 02:16:42 by spacecom » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 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>
Logged
Pages: [1]
Print