Page 1 of 1

Text as a button in GUI

Posted: April 6th, 2014, 11:44 am
by Tomas Sinkunas
Hi guys. Newby here.

I am pulling my hair and cannot figure out how to make a TEXT into BUTTON.
I know how to create a button like this:

Code: Select all

buttonHelp = win.add("button", [20, 365, 240, 395], "Help",);
However, I don't need it to look like a button - instead I just want it to look like a text object, and once mouse over it - it get's to different color. Imagine "a href" where text is like a button and it changes color once mouse overs it.

Is it possible?

Appreciate your time.

Re: Text as a button in GUI

Posted: April 8th, 2014, 11:26 am
by Tomas Sinkunas
No one?
Is this so difficult or impossible?

Re: Text as a button in GUI

Posted: April 9th, 2014, 2:50 am
by beginUndoGroup
There are event listeners "mouseover", "mouse out", etc.

Xavier.

Code: Select all

(function(ooo){

	(ooo instanceof Panel) || (ooo=new Window("palette"));
	ooo.onResizing = ooo.onResize = function(){this.layout.resize();};
	
	var myText = ooo.add("panel{margins: 2}").add("statictext{text: 'Come and see!'}");
	myText.addEventListener("mouseover", myHandleFunc);
	myText.addEventListener("mouseout", myHandleFunc);
	myText.addEventListener("mousedown", myHandleFunc);
	myText.addEventListener("mouseup", myHandleFunc);

	function myHandleFunc(ev){
		var t = ev.target, color, gfx;
		if (t instanceof StaticText){
			switch(ev.type){
				case "mousedown": color = [1,1,1]; break;
				case "mouseover": color = [0.5,0.5,0.5]; break;
				case "mouseup": color = [0.5,0.5,0.5]; break;
				default : color = [0,0,0];
				};
			gfx = t.graphics;
			gfx.foregroundColor = gfx.newPen(gfx.PenType.SOLID_COLOR, color, 1);
			};
		return;
		};
	
	(ooo instanceof Panel) ? ooo.layout.layout(true) : ooo.show();
	return;
	})(this);

Re: Text as a button in GUI

Posted: April 10th, 2014, 12:18 pm
by Tomas Sinkunas
Now That's a proper reply.

Big thank you Xavier for taking your time answering my question, appreciate that.

Re: Text as a button in GUI

Posted: April 12th, 2014, 12:39 pm
by Tomas Sinkunas
Hm, any idea why this approach does not work under AE CS3?

Re: Text as a button in GUI

Posted: April 12th, 2014, 5:29 pm
by beginUndoGroup
Do you have an error in CS3 or just a text that doesnt respond to event ?
In the second case, it might be that texts didnt support that kind of events at that time...
Really i don't know.

Xavier.

Re: Text as a button in GUI

Posted: April 16th, 2014, 4:38 am
by Tomas Sinkunas
No problems. Indeed mouse events were added in CS4. So i just ended up catching AE version and displaying regular buttons instead.

Cheers.