View Full Version : problem with defer

21 Sep 2010, 5:45 AM

on switching to a special card in my main panel i'd like to set some text to a textfield and four buttons with short pauses inbetween. This is my main panel:

var panel_Main = new Ext.Panel({
id: 'panelMain',
fullscreen: true,
layout: 'card',
items: [card_Main, card_Steps, card_Game, card_Sites],
onCardSwitch: function(newCard, oldCard, newIndex, animated) {
/* This works as expected!
setText.defer(1000, this, ['btnA', 'Antwort A']);

if((newCard == card_Game) && (oldCard == card_Steps)) {
// The 'if' here is getting true but these don't work!
setText.defer(1000, this, ['quest', 'Question']);
setText.defer(1000, this, ['btnA', 'Answer A']);
setText.defer(1000, this, ['btnB', 'Answer B']);
setText.defer(1000, this, ['btnC', 'Answer C']);
setText.defer(1000, this, ['btnD', 'Answer D']);
});And the function i'm calling:

function setText(thisID, thisTXT) {
Ext.getCmp(thisID).text = thisTXT;
}The problem is that calling 'setText' within the if-condition doesn't work although the function is called with the correct values after a second (i traced them)! And calling 'setText' in front of the if-condition is working! I don't understand that. Please, can anybody tell me what's wrong!?

21 Sep 2010, 6:08 AM
There's absolutely no difference, the fact that it's inside another block doesn't have any impact. Are you sure it ever actually evaluates to true?

21 Sep 2010, 6:39 AM
Ok, i found out that the problem isn't due to the if-condition or 'defer'. The problem is that obviously the 'newCard' in 'onCardSwitch' isn't active. The reason why it seemed to work when i called 'setText' in front of 'if' was that this line was executed one time before the aimed card (card_Game) became the 'newCard'. So the text was set while the card wasn't involved in any 'cardSwitch' and therefore seemed to be active but not in front or visible of course. But if it is the card to be switched to it seems to be inactive even when setting the texts 'onCardSwitch' and with 'defer'. What can I do?

21 Sep 2010, 7:44 AM
Ok, obviously the text on the buttons is set but not shown! When is this supposed to happen? I mean when does "btn.text='hello';" sets the text without showing it? And how can i force the buttons to show their dynamically new set texts? Thanks ...

21 Sep 2010, 7:57 AM
You want the setText method.

21 Sep 2010, 8:17 AM
Yes, exactly, thanks (i still have to learn a lot ...)! It works for the buttons now but not for my text which is a component. Here i don't have 'setText', 'html' or 'text' is again not working, i mean not showing. What can I do here?

22 Sep 2010, 1:39 AM
Ok, i found it, it's 'component.update(html);' that sets and shows the text in a component dynamically. Thanks.