Text as a button in GUI

All things .jsx

Moderator: Paul Tuersley

Post Reply
Tomas Sinkunas
Posts: 5
Joined: April 6th, 2014, 11:36 am

April 6th, 2014, 11:44 am

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.
Tomas Sinkunas
Posts: 5
Joined: April 6th, 2014, 11:36 am

April 8th, 2014, 11:26 am

No one?
Is this so difficult or impossible?
beginUndoGroup
Posts: 80
Joined: November 27th, 2012, 6:41 am

April 9th, 2014, 2:50 am

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);
Tomas Sinkunas
Posts: 5
Joined: April 6th, 2014, 11:36 am

April 10th, 2014, 12:18 pm

Now That's a proper reply.

Big thank you Xavier for taking your time answering my question, appreciate that.
Tomas Sinkunas
Posts: 5
Joined: April 6th, 2014, 11:36 am

April 12th, 2014, 12:39 pm

Hm, any idea why this approach does not work under AE CS3?
beginUndoGroup
Posts: 80
Joined: November 27th, 2012, 6:41 am

April 12th, 2014, 5:29 pm

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.
Tomas Sinkunas
Posts: 5
Joined: April 6th, 2014, 11:36 am

April 16th, 2014, 4:38 am

No problems. Indeed mouse events were added in CS4. So i just ended up catching AE version and displaying regular buttons instead.

Cheers.
Post Reply