nislim | 5 Oct 11:33

Menubutton error


This is the code i use to generate a simple menu:

CreateMenu : function()
	  {
		  if (parseInt(navigator.appVersion)>3) {
			if (navigator.appName=="Netscape") {
			winW = window.innerWidth;
			}
			if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.body.offsetWidth;
	}
}
		  
		  var frame = new qx.ui.container.Composite(new qx.ui.layout.Grow);

      var menuBar = new qx.ui.menubar.MenuBar;
      menuBar.setWidth(winW-2);
      frame.add(menuBar);

      // [MenuBar]
     menuBar.add(new qx.ui.menubar.Button("Test", this.createFileMenu())); 
	  //fileMenu.addListener("execute", this.createFileMenu());

	    
      return frame;
	  },
	  
	 	createFileMenu: function()
	  {
(Continue reading)

Matthew Gregory | 5 Oct 23:44

Re: Menubutton error

Hi nislim,
Try changing this.createFileMenu() to this.createFileMenu.
You don't want to call the function here you just want to reference it.

Also instead of trying to get the document width have you tried 
something like this?
frame.add(menuBar, {left : 0, right : 0})

nislim wrote:
> This is the code i use to generate a simple menu:
> 
> CreateMenu : function()
> 	  {
> 		  if (parseInt(navigator.appVersion)>3) {
> 			if (navigator.appName=="Netscape") {
> 			winW = window.innerWidth;
> 			}
> 			if (navigator.appName.indexOf("Microsoft")!=-1) {
> 			winW = document.body.offsetWidth;
> 	}
> }
> 		  
> 		  var frame = new qx.ui.container.Composite(new qx.ui.layout.Grow);
> 
>       var menuBar = new qx.ui.menubar.MenuBar;
>       menuBar.setWidth(winW-2);
>       frame.add(menuBar);
> 
>       // [MenuBar]
>      menuBar.add(new qx.ui.menubar.Button("Test", this.createFileMenu())); 
(Continue reading)

nislim | 7 Oct 20:19

Re: Menubutton error


Matthew Gregory wrote:
> 
> Hi nislim,
> Try changing this.createFileMenu() to this.createFileMenu.
> You don't want to call the function here you just want to reference it.
> 
> Also instead of trying to get the document width have you tried 
> something like this?
> frame.add(menuBar, {left : 0, right : 0})
> 
> 
> nislim wrote:
>> This is the code i use to generate a simple menu:
>> 
>> CreateMenu : function()
>> 	  {
>> 		  if (parseInt(navigator.appVersion)>3) {
>> 			if (navigator.appName=="Netscape") {
>> 			winW = window.innerWidth;
>> 			}
>> 			if (navigator.appName.indexOf("Microsoft")!=-1) {
>> 			winW = document.body.offsetWidth;
>> 	}
>> }
>> 		  
>> 		  var frame = new qx.ui.container.Composite(new qx.ui.layout.Grow);
>> 
>>       var menuBar = new qx.ui.menubar.MenuBar;
>>       menuBar.setWidth(winW-2);
(Continue reading)

Re: Menubutton error

Hi Nislim,

This is because you are calling the function when your application
starts. Try this:

var f = function() { alert("Alerted"); };

var a = f();
var b = f;

alert(typeof a);
alert(typeof b);

You should see the results. f() will always call function f, so if you
want function that calls function f, you should create new one (or
anonymous):

var I_Will_Call_F_And_Return_String = function() { f(); return "string"; };

So in listener if you want function that will call something, use anonymous:

fileMenu.addListener("execute", function(e) { do something here } );

Cheers
- Petr

2008/10/7 nislim <aerts.nick <at> gmail.com>:
>
>
> Matthew Gregory wrote:
(Continue reading)

nislim | 20 Oct 18:32

Re: Menubutton error


Thanks for the reply but now I have another problem:

This works:

  var menuAction = function(e) { alert("You clicked me!"); };
  var ClickMeButton= new qx.ui.menu.Button("Click me",null,
this.debugButton);
  ClickMeButton.addListener("click",menuAction);

But

 var menuAction = function(e) { this.CreateMenu(); };
 var ClickMeButton= new qx.ui.menu.Button("Click me",null,
this.debugButton);
 ClickMeButton.addListener("click",menuAction);

CreateMenu : function()
{
alert("You clicked me!"); 
},

The function works if I just add it to the main funtion.
--

-- 
View this message in context: http://www.nabble.com/Menubutton-error-tp19810858p20073608.html
Sent from the qooxdoo-devel mailing list archive at Nabble.com.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
(Continue reading)

Jonathan Rass | 21 Oct 07:58
Favicon

Re: Menubutton error

Hello Nick!

Please note that the scope inside event handlers is different so that 
"this" is linked to window object. To set a scope (and change the "this" 
reference to an object you want) addListener() takes a third argument:

http://demo.qooxdoo.org/current/apiviewer/#qx.core.Object~addListener

In short: just change

ClickMeButton.addListener("click",menuAction);

to

ClickMeButton.addListener("click",menuAction, this);

Kind regards,
Jonathan

nislim wrote:
> Thanks for the reply but now I have another problem:
> 
> This works:
> 
>   var menuAction = function(e) { alert("You clicked me!"); };
>   var ClickMeButton= new qx.ui.menu.Button("Click me",null,
> this.debugButton);
>   ClickMeButton.addListener("click",menuAction);
> 
> But
(Continue reading)


Gmane