Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 23rd, 2024, 3:19 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Cloned Object Script
PostPosted: March 20th, 2007, 1:57 pm 
Offline

Joined: December 25th, 2004, 3:31 pm
Posts: 178
Having a bit of trouble implementing this using cloned tickbox and trying to set each to a different variable in an array.

I am pulling data from a database, it's a list of names, each appearing on a new line in a text box. Beside each name will be a checkbox, I am currently cloning the textbox as the names are pulled from the database and placing them down alongside the names, to the left.

Code:
function PullDB
{
SQL Function here .....

for (i = 1; i <= numRecords; i++)
{
   Text_DB.SetSelection(-1)
   Text_DB.ReplaceSelection(nameList.Name + "\n")
   CloneTickboxFunction(i * 26)
   nameList.NextRecord();
}
}

function CloneTickboxFunction(posY)
{
Button_Tick.CloneObject(180, 120 + posY, true)
}



This creates a nice list of checkboxes (tickboxes) beside the names, now I want to be able to record the value of each checkbox, so if I check the box put a tick in it I can record this to the database. Currently had hoped to do this with the GetName() function on the checkbox and this would then be cloned.

Code:
TickBox = this.GetName()


The trouble is that when I click on this I get a very long string for the name and I need to know that the names will always appear similar so I can grab which are clicked and place in an array and then send it back to the database. Current names start with Button_Tick.2147483648, the second is called Button_Tick.2147483649 and the third Button_Tick.2147483650. Question will this always be the name, or where does Opus get this from, if there are a 100 names in the DB.

Final question, is there an easier way of doing this?

Joe


Top
 Profile  
 
 Post subject: Re: Cloned Object Script
PostPosted: March 20th, 2007, 2:23 pm 
Offline

Joined: October 26th, 2004, 10:23 am
Posts: 666
Location: Digital Workshop
josephroddy wrote:
will this always be the name, or where does Opus get this from, if there are a 100 names in the DB.

No - the names of dynamically created objects cannot be predicted in advance - if you add a different number of objects the names would be different. I would look at coming up with a way of mapping your database entries into an array of objects and referring to them by index.

_________________
ddww Opus Developer


Top
 Profile Visit website  
 
 Post subject:
PostPosted: March 20th, 2007, 2:41 pm 
Offline

Joined: December 25th, 2004, 3:31 pm
Posts: 178
Thanks for the comment.

How would this be possible, can you set the name of each cloned object as they are created so you make reference to them. I can put each database name into an array thats not a problem, it just knowing which name has a tick in each checkbox.

Would it be possible to do with a List Box, so when each is clicked the ClonedCheckbox is changed to Button Down state, but then we're back to the same problem of needing to know the names of each cloned item or be able to set when cloned.

Is this possible to do in Opus, or am I way over my head.


Top
 Profile  
 
 Post subject: Hi JP
PostPosted: March 20th, 2007, 10:51 pm 
Offline

Joined: November 11th, 2004, 1:43 pm
Posts: 172
Location: Buckinghamshire, UK
Please see the .imp, this implements reading/writing data to file.

Am using a frame that will hold a text and a checkbox button that (frame) will be cloned and its children updated with relevant data... Only completed for the text object but same can be done with button status (up/down/selected/unselected).

@save, the x/y position of the frame is saved, as well as the contents of the text object.

Hope you will be able to adapt it to your requirements...


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
 
 Post subject:
PostPosted: March 21st, 2007, 12:47 am 
Offline

Joined: December 25th, 2004, 3:31 pm
Posts: 178
Thanks,

I have been working on for the past few hours and I think I have something working.

Thanks for the help, I was able to take bits and saw how I could create the cloned object in an array and then check the state of the cloned object to determined if it was checked or now. The array corresponded directly with the data pulled from the database which I also placed in an array.

Once I clean up the code and get everything working I will post the code here for anyone else who may need it.


Top
 Profile  
 
 Post subject:
PostPosted: March 21st, 2007, 10:00 pm 
Offline

Joined: December 25th, 2004, 3:31 pm
Posts: 178
Hi,

How is it possible to destroy CloneObjects which are inside an array? Cloned using the following code inside a for loop:

Code:
myTextClones[i] = Button_Tick.CloneObject(16, -2 + (i * 16), true)


I have tried a few different methods but have been unable to do it:

Code:
Button_Tick.DestroyClonedObject()

inside for loop
myTextClones[i].DestroyClonedObject()

myTextClones.length = 0


Have also tried to get the name of each cloned object and destroy it that way using the code below, but this is an invalid function due to the double dots.

Button_Tick.2147483697.DestroyClonedObject()


Resetting the page works but this isn't the best solution for what I am trying to do.


Top
 Profile  
 
 Post subject:
PostPosted: March 21st, 2007, 11:36 pm 
Offline

Joined: November 11th, 2004, 1:43 pm
Posts: 172
Location: Buckinghamshire, UK
Say I have populated the array/page with clone items, and want to trash them all, the following code would do just that

Code:
for (loop=0;loop<myTextClones.length;loop++)
{
  myTextClones[loop].DestroyClonedObject()
}
Debug.trace("Array length: "+ myTextClones.length +"\n")

The debug statement at the end confirms that the array item still contains the information of the objects.

you can delete an item "using" the array index, again the array here remains the same...

Code:
myTextClones[2].DestroyClonedObject()


delete item three...

I am assuming now that you simply want to eliminate a couple of the clone objects and want to cleanup the array object.


I salvaged this bit of code from one item I got help with by someone in the forum, and after trawling through a real gem of ECMAScript document
http://www.ecma-international.org/publi ... ma-262.pdf, another good resource is http://phrogz.net/ObjJob/object.asp?id=314 just about understood the workings of the code but here goes...

You need to create the following function in a script object (keep the comments please...)




Code:
/*--------------------------------------------------------------
Array Functions

-The splice() method BOTH removes and inserts elements based
on the parameters you feed it.
-The first parameter is an index number of the element list
indicating where to start.
-The second parameter tells the function how many elements of
the array to remove starting at the indexed element.
-The remaining parameters are elements to add to the array after
its indexed element.
---------------------------------------------------------------*/

function Array_splice(index, delTotal) {
  var temp = new Array()
  var response = new Array()
  var A_s = 0
  for (A_s = 0; A_s < index; A_s++) {
   temp[temp.length] = this[A_s]
   }
  for (A_s = 2; A_s < arguments.length; A_s++) {
   temp[temp.length] = arguments[A_s]
   }
  for (A_s = index + delTotal; A_s < this.length; A_s++) {
   temp[temp.length] = this[A_s]
   }
  for (A_s = 0; A_s < delTotal; A_s++) {
   response[A_s] = this[index + A_s]
   }
  this.length = 0
  for (A_s = 0; A_s < temp.length; A_s++) {
   this[this.length] = temp[A_s]
   }
  return response
  }

if (typeof Array.prototype.splice == "undefined") {
  Array.prototype.splice = Array_splice
  }

//Syntax
// arrayObj=new Array(1,2,3,4,5,6,7,8,9,0)
// var x = arrayObj.splice(startIndex, cutTotal , arg0 , arg1,...)
// var x = arrayObj.splice(2,3,10,11,12)
// starting at index 2, deal with 3, replace with 10,11,12




And how to use the function

Code:
myTextClones.splice(1,1)

here, I am telling the code to start from index1 and delete 1 item. hence the first 1 can be a variable holding the index of the object you deleting from the array, and second one will remain as one... the array object lenth will reduce by 1....




again will like to thank forum member who originally posted the piece of code, see I remembered how it was to be used... :D ...


Last edited by eomc40 on March 22nd, 2007, 12:17 am, edited 5 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: March 21st, 2007, 11:40 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Hi Joseph

Since I'm not sure who needs to destroy clones or if they can be dragged and dropped, I can only come up with a highly speculative work-a-round:

if the end-user needs to destroy clones, what I've done (and this may be impractacle for your pub), is set up a "trash" box in one of the lower corners. If the "trash" box is large and mostly off-screen, except its upper corner, and set as a drop box with 'snap to center,' and clones can be dragged and dropped, this allows the end-user to remove them.

Just a thought.

Kind Regards,

_________________
Stephen


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 53 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group