PDA

View Full Version : Destroy a panel throws an error



Kurt001
11 Jun 2011, 7:49 AM
Hi

currently I am trying to make my menu setting up based on the orientation.
When I show the menu the first time all buttons work fine, but setting it up after orientation change, it does not work any longer.

Toggling through my code, shows that it throws an error trying to destory the old layout.

Any idea, what I have to change??



To show what I am talking about I uplaoded the code to (currently optimized for iPhone):
http://www.m-gd.com/ipad/mydrop/

Here is what it is doing:


Ext.regApplication({
name: 'myDrop',
launch: function() {
/**
* Here I am initially defining myDrop.rootPanel
*/
myDrop.rootPanel = new Ext.Panel({
fullscreen: true,
layout: 'card',
style:"background: #333"
});
Ext.EventManager.onOrientationChange(setOrientation);
setOrientation();
}
});

function setOrientation(){
/**
* the next line throws the error when running it the second time, although I am
* rebuilding myDrop.rootPanel afterwards.
*/
myDrop.rootPanel.destroy();

if (Ext.orientation == 'landscape') {
/**
* Here I am rebuilding myDrop.rootPanel
*/
myDrop.rootPanel = new Ext.Panel({
fullscreen: true,
layout: "card",
style: 'background: url(resources/images/menu/iphone/background_landscape.png);',
items: [{
xtype: 'panel',
itemId: 'buttonList',
cls: 'iphoneMenuBtnPanel',
items:
[ //Fill it ]
}],
dockedItems:
[//Fill it]
});
}

if (Ext.orientation == 'portrait') {
myDrop.rootPanel = new Ext.Panel({
fullscreen: true,
layout: "card",
style: 'background: url(resources/images/menu/iphone/background_portrait.png);',
items: [{
xtype: 'panel',
itemId: 'buttonList',
cls: 'iphoneMenuBtnPanel',
items:
[//Fill it]
}],
dockedItems:
[//Fill it]
});
}
}

Kurt001
12 Jun 2011, 2:50 AM
Hi again,

no one knows how to solve this?

So far I fixed it using the following lines instead of destroy:

var myChild = document.childNodes[1].childNodes[1].lastChild;
document.childNodes[1].childNodes[1].removeChild(myChild);
This is not the best way, but seems to work.
though this seems to me is a very unstable way to solve it.

Any better ideas?