Skip to main content
Loic.Aigon
Legend
March 28, 2012
Question

ScriptUI stroking a field

  • March 28, 2012
  • 1 reply
  • 2036 views

Hi,

I need to red stroke fields. Inspite of the doc and this great thread : http://forums.adobe.com/message/4215908#4215908,

I can't get it working

field.onDraw = function()

{

          var gx = this.graphics,

           pen = this.graphics.newPen (this.graphics.PenType.SOLID_COLOR, [1, 0, 0,1], 5);

          gx.drawOSControl();

          gx.rectPath( this.location[0] , this.location[1], this.size.width, this.size.height);

          gx.strokePath(pen);

}

What am I doing wrong ?

Best,

Loic

This topic has been closed for replies.

1 reply

Loic.Aigon
Legend
March 29, 2012

Hi,

I finally got what I wanted with a workaround. First of all I could get the above snippet adding this line :

field.onDraw = function()
{
          var gx = this.graphics,
           pen = this.graphics.newPen (this.graphics.PenType.SOLID_COLOR, [1, 0, 0,1], 5);
          gx.drawOSControl();

          gx.newPath();
          gx.rectPath( this.location[0] , this.location[1], this.size.width, this.size.height);
          gx.strokePath(pen);
}

But the result wasn't the one I expected. The path was indeed drawn inside the text field area when I wanted it outside. Finally my cheat was to create a dummy group object on the back of the text field. Those both objects are placed into a stacked group. Then it's easy to set dimensions and background attributes for the dummy group and finally get what I wanted.


var w = new Window('dialog');

var gp = w.add('group');

gp.orientation = 'stack';

gp.alignChildren = ['center','center'];

var dummyGp = gp.add('group');

dummyGp.preferredSize = [102,52];

dummyGp.graphics.backgroundColor = dummyGp.graphics.newBrush (dummyGp.graphics.BrushType.SOLID_COLOR, [1,0,0,1] );

var tf1 = gp.add('edittext');

tf1.preferredSize = [100,50];

w.show();

Hope it helps.

Loic


Peter Kahrel
Community Expert
Community Expert
March 30, 2012

Nice one, Loic. But remember that on the Mac and on Windows, the stacked objects are drawn in a different order. So on Windows, your script shows just a red rectangle because the edit field is placed behind the rectangle.

Peter