Page 1 of 1

Drawing or cloning new objects.

PostPosted: Tue Jan 20, 2015 6:06 am
by John Robin Dove
Is it possible to create new objects at runtime? I need to create a series of small rectangles each with a unique name and they need to be draggable. I can create objects on an embedded HTML using canvas but they're not draggable and don't have names. I looked for pgClone :D

Re: Drawing or cloning new objects.

PostPosted: Tue Jan 20, 2015 9:12 am
by Clifton
Why not just use several fields, which can be made draggable with createDraggableObject()? Initially they can be left hidden until they are needed in your application. Regarding naming them, just use PowerPac's userProperty() to create unique identifiers for each one that is relevant to your program.

If a rectangle needs a particular size and shape when shown, you could attach a stylesheet using pgExtFiles() and just set the class name of the rectangle from one in the stylesheet before it is shown. In this way you could even include graphics and other special effects and animations too. The userProperty() can set the class name of ToolBook objects and it works very nicely, though sometimes you have to use the "!important" expression in your stylesheet to override ToolBook's inline styles (that is, if you are manipulating one of them).

It is possible to clone objects, but it is unnecessarily complicated and events are lost in cloning. Whatever you are trying to accomplish will probably be more fun and interesting with the approach suggested, rather than doing down the road of cloning.

Re: Drawing or cloning new objects.

PostPosted: Tue Jan 20, 2015 9:24 am
by John Robin Dove
OK. Thanks I had thought about preparing the objects in advance like this but I don't know exactly how many the user will require. Is there a limit to the number of objects I can 'set aside' to be used if necessary? 50 ... 100?

Re: Drawing or cloning new objects.

PostPosted: Tue Jan 20, 2015 10:12 am
by Clifton
You should be fine regardless of the number of objects used. Just make sure to use fields, not rectangles because ToolBook will attempt to load a lot of graphics. Fields have very little overhead on the DOM; especially if they are empty (no text).