topleft topright

Welcome, Guest. Please login or register.
May 18, 2013, 01:17:58 AM
Home Help Search Login Register
News: ATTENTION: Spambots must die! Humans must visit http://contact.futurescale.com to request forum access.

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


View Profile Email
« on: April 21, 2008, 01:49:11 AM »

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?

Code:
// 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 AM by spacecom » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2790



View Profile WWW
« Reply #1 on: April 21, 2008, 05:47:51 AM »

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
Jump to:  



Login with username, password and session length

Powered by SMF 1.1.11 | SMF © 2006-2007, Simple Machines LLC
Copyright © 2006-2008 Futurescale, Inc.