Expressions/Scripts/Presets

Moderator: Paul Tuersley

 
Tomas Sinkunas
Topic Author
Posts: 5
Joined: Sun Apr 06, 2014 11:36 am

Text as a button in GUI

Sun Apr 06, 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:
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
Topic Author
Posts: 5
Joined: Sun Apr 06, 2014 11:36 am

Re: Text as a button in GUI

Tue Apr 08, 2014 11:26 am

No one?
Is this so difficult or impossible?
 
beginUndoGroup
Posts: 77
Joined: Tue Nov 27, 2012 6:41 am

Re: Text as a button in GUI

Wed Apr 09, 2014 2:50 am

There are event listeners "mouseover", "mouse out", etc.

Xavier.

(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
Topic Author
Posts: 5
Joined: Sun Apr 06, 2014 11:36 am

Re: Text as a button in GUI

Thu Apr 10, 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
Topic Author
Posts: 5
Joined: Sun Apr 06, 2014 11:36 am

Re: Text as a button in GUI

Sat Apr 12, 2014 12:39 pm

Hm, any idea why this approach does not work under AE CS3?
 
beginUndoGroup
Posts: 77
Joined: Tue Nov 27, 2012 6:41 am

Re: Text as a button in GUI

Sat Apr 12, 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
Topic Author
Posts: 5
Joined: Sun Apr 06, 2014 11:36 am

Re: Text as a button in GUI

Wed Apr 16, 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.

Who is online

Users browsing this forum: No registered users and 4 guests