Creating an object dynamically - Possible?

Hi all :slight_smile: Me again :wink:

How to create, dynamically, an object?

For example, I wish to create, simply with code AppleScript, a button at the front window, how to do it?

on clicked theObject
	tell window of theObject
		make at beginning new button with properties {name:"1"}
	end tell
end clicked

Do not work :frowning:
Thanks for any idea :slight_smile:

I think I asked this same question some time ago, and didn’t receive replies, or simply negative replies.

To the best of my knowledge, it can’t be done. There are, however, workarounds. You could create several buttons in IB and position them beyond the bounds of the window (or simply make them invisible) and, when necessary, move the position/visibility of the buttons as needed. You can change how a button behaves easily using if-then-else statements in the on clicked handler and you can also easily change the title of the buttons as needed as well. I wish there were a more elegant way of doing this but I’m fairly certain there isn’t.

If you do come up with something better, please share.

Jon

Thank you, Jon and JJ, for your answers. :slight_smile:

I am under development of a small game which will have three principal screens, each one having an increasing number of buttons.
I can completely carry out the three windows manually, but I wanted to consider another working method by the dynamic creation of the buttons after having changed the dimension of the window (easy to make with the code), unfortunately all my attempts remained without success.

I sought documentation on Internet, but I did not find anything of interesting.
I a question however, in your opinion, is this raises possible to do that or not?

Lastly, I had also considered your proposal Jon, but, the operating mode that I use for this application implies an exact number of buttons in each window, it is thus not possible to create all the buttons and to display only the necessary ones.

In any case, me also I am really interested by any information being able to a little better clarify these techniques.

Still thank you for your lights. :slight_smile:

perhaps you should look into Custom Views.

create multiple custom views, and move their posiiton to put their within or not within the visible portion of the window.

Hi β€œpetey” :slight_smile:

Thank you very much for your answer.

I never yet used this type of object, I does not know their possibilities. I will explore a little in this direction, while hoping to find a method which is appropriate better so that I want to make.

Thank you again for your assistance. :slight_smile: