Original User: mehu11111TO CLOSE MULTIPLE WIDGETS:
In your widget :
--------------
var widgetIdxUnLoadArray:Array = [6,7,8];
private var closeMultiple:Boolean = false;
protected function button2_clickHandler(event:MouseEvent):void
{
closeMultiple = true;
preUnloadNextWidget();
}
private function preUnloadNextWidget():void
{
if (widgetIdxUnLoadArray.length > 0)
{
var id:Number = widgetIdxUnLoadArray[0];
widgetIdxUnLoadArray.splice(0, 1);
ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_STOP, id));
}
}
private function myWidgetRemovedHandler(event:AppEvent):void
{
if (closeMultiple)
{
closeMultiple=false;
preUnloadNextWidget();
}
}
In WidgetContainer.MXML,
-------------
add elementRemove as shown below
<s:Group id="widgetContainer"
width="100%" height="100%"
left="{_left}" left.collapsedRight="{containerWidth}" left.resized="{_left}" right="{_right}" right.normal="{_right}" right.resized="{_right}" top="{_top}" top.collapsedDown="{containerHeight}" top.resized="{_top}" bottom="{_bottom}" bottom.resized="{_bottom}"
clipAndEnableScrolling="true"
elementAdd="widgetAddedHandler(event)"
elementRemove="widgetRemoveHandler(event)" />
And
protected function widgetRemoveHandler(event:ElementExistenceEvent):void
{
var wObj:IVisualElement = event.element;
ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_REMOVED, wObj));
}
In AppEvent.as
---------
public static const WIDGET_REMOVED:String = "widgetRemoved";
public static const WIDGET_STOP:String = "widgetStopRequested";
In WidgetManager.mxml
----------------
add following line in Init() Method:
ViewerContainer.addEventListener(AppEvent.WIDGET_STOP, onStopWidget);
Add following method:
private function onStopWidget(event:AppEvent):void
{
var id:Number = event.data as Number;
var idx:Object = configData.widgetIndex[id];
var wgtContainer:IWidgetContainer = configData.widgetContainers[idx.container].container.obj;
var wgt:Object = configData.widgetContainers[idx.container].widgets[idx.widget];
widgetAdded = false;
var widget:IBaseWidget;
if (widgetTable.containsKey(id))
{
widget = widgetTable.find(id) as IBaseWidget;
widget.setState(BaseWidget.WIDGET_CLOSED);
}
}
TO OPEN MULTIPLE WIDGETS
Add following code in widget
<s:Button label="Open Multiple Widget" click="button1_clickHandler(event)" />
var widgetIdxArray:Array = [6,7,8]; // 6,7,8 are widget Ids. This can be obtained from configData object
protected function button1_clickHandler(event:MouseEvent):void
{
ViewerContainer.addEventListener(AppEvent.WIDGET_ADDED, myWidgetAddedHandler);
preloadNextWidget();
}
private function preloadNextWidget():void
{
if (widgetIdxArray.length > 0)
{
var id:Number = widgetIdxArray[0];
widgetIdxArray.splice(0, 1);
ViewerContainer.dispatchEvent(new AppEvent(AppEvent.WIDGET_RUN, id));
}
}
private function myWidgetAddedHandler(event:AppEvent):void
{
preloadNextWidget();
}
hope this helps.