Window within a panel

Find out why the . goes before the /

Moderator: Paul Tuersley

Post Reply
Simma
Posts: 98
Joined: June 8th, 2010, 2:57 pm

Hi all, I've been away from After Effects scripting for awhile, and now when I'm back I struggle with what I expect to be a simple task. I'm trying to create a new Window by clicking a button in my main Panel. However the new window closes as soon as it has been created. If I put an alert afterwards I see that it is created. Any ideas?

Code: Select all

   function myScript(thisObj) {
      var pal = (thisObj instanceof Panel) ? thisObj : new Window("palette", "script", undefined);

      if (pal != null) {
         var res=
         "Group { \
         orientation: 'column', \
         alignment: ['fill', 'fill'], \
         alignChildren: ['left', 'top'], \
         minimumSize: [125, 26],\
         one: Group { \
            orientation: 'row', \
            new_window: Button {text: 'create new window', size: ['120', '25']}, \
            } \
         }";

         pal.grp = pal.add(res);
         pal.layout.layout(true);
         pal.layout.resize()

         pal.grp.one.new_window.onClick = function () {
            newWindow ();
         }

         return pal;

      } // if (pal != null) {

   } // function myScript_buildUI(thisObj) {

   function newWindow() {
      var win = new Window("palette");

      if (win != null) {
         var res=
         "Group { \
         orientation: 'column', \
         alignment: ['fill', 'fill'], \
         alignChildren: ['left', 'top'], \
         minimumSize: [125, 26],\
         one: Group { \
            orientation: 'row', \
            new_button: Button {text: 'new button', size: ['100', '25']}, \
            } \
         }";

         win.grp = win.add(res);
         win.layout.layout(true);
         win.layout.resize()
		 win.show()
		 alert("A window is behind me and will close as I close this.")

      } // if (pal != null) {

   } // function myScript_buildUI(thisObj) {

ui = myScript()
ui.show()
Simma
Posts: 98
Joined: June 8th, 2010, 2:57 pm

Anyone? I still haven't figured it out.
beginUndoGroup
Posts: 81
Joined: November 27th, 2012, 6:41 am

If the window doesnt need to be persistant, just change "palette" to "dialog".
Otherwise you need to either declare the window you want to display outside of the onClick function, either append the new window object to an already existing object.
It depends on what you want to achieve (can the new window can be instantiated more than once, etc).

Xavier

Code: Select all

(function(thisObj)
{
	var pal = (thisObj instanceof Panel) ? thisObj : new Window("palette", "script");
	var auxpal;
	buildUI();
	if (pal instanceof Window) pal.show();
	return;
	
	function buildUI()
	{
		pal.grp = pal.add("Group { orientation: 'column', alignment: ['fill', 'fill'], alignChildren: ['left', 'top'], minimumSize: [125, 26],\
											one: Group { orientation: 'row', \
															new_window: Button {text: 'create new window', size: ['120', '25']}, \
															} \
											}");		
		pal.grp.one.new_window.onClick = function ()
		{
			if (!(auxpal instanceof Window)) auxpal = newWindow();
			//auxpal.center();
			auxpal.show();
			};
		pal.layout.layout(true);
		pal.layout.resize();
		};

	function newWindow()
	{
		var win = new Window("palette");
		win.grp = win.add("group { orientation: 'column', alignment: ['fill', 'fill'], alignChildren: ['left', 'top'], minimumSize: [125, 26],\
											one: Group { orientation: 'row', \
															new_button: Button {text: 'new button', size: ['100', '25']}, \
															} \
											}");
		win.layout.layout(true);
		return win;
	   };
   })(this);
Simma
Posts: 98
Joined: June 8th, 2010, 2:57 pm

Thanks Xavier, that works perfectly. I will study your code and see if I can get an understanding. Cheers!
Post Reply