Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 9:54 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Adding extra Array functions with ".prototype."
PostPosted: January 18th, 2005, 10:58 pm 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
Hi all,
Opusscript can use prototype to add functions to the array object, because Opusscript is based on ECMAscript which supports prototyping.

I've enclosed an Opus Pro 2.81 pub that contains array functions available in other authoring apps that use vbscript or javascript as their scripting languages.
The functions are Push, Pop, Splice, Shift, Unshift, Max value, Average, Negative value and Shuffle.

As an example the script below adds a max function to the array object.
All arrays on the page will inherit the function.
//-----------------------------------------------------------
function array_max() {
var i, max = this[0];
for (i = 1; i < this.length; i++) {
if (max < this[i])
max = this[i];
}
return max;
}
// set the prototype
Array.prototype.max = array_max;

//------------------------------------------------------------

Example of usage::

var ar = new Array(1, 2, 3, 7, 4, 5, 6);

maxval = ar.max() // will return the largest number in the array.

You can add extra functions to the string Object in a similar manner.
cheers
Paul


For this message Paul has been thanked by : mackavi


Top
 Profile  
 
 Post subject:
PostPosted: January 18th, 2005, 11:07 pm 
Offline

Joined: October 25th, 2004, 1:03 pm
Posts: 74
Location: Sydney Australia
Hey Paul - very usefull, Thanx.


For this message SWAN has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject:
PostPosted: January 24th, 2005, 12:08 pm 
Offline

Joined: November 11th, 2004, 1:43 pm
Posts: 172
Location: Buckinghamshire, UK
Paul,Swan
Downloaded the .imp file.... on preview, I am getting blank page and an output from "Opus Professional Script Console" of the result.

Where is the code?

Using 4.3 Opus....


For this message eomc40 has been thanked by : mackavi


Top
 Profile  
 
 Post subject:
PostPosted: January 24th, 2005, 12:35 pm 
Offline

Joined: October 25th, 2004, 12:27 pm
Posts: 526
Location: Digital Workshop
eomc40 wrote:
Downloaded the .imp file.... on preview, I am getting blank page and an output from "Opus Professional Script Console" of the result.

Where is the code?


Paul has used the Debug.trace() function to display the output of each script function in the Script Console.

For example, if you preview the 'Shuffle' page, the script output window will show you the original array and the result of the shuffled array.

If you wish to see the 'code', simply take a look inside the script object on each page of the publication.

Kind regards,

_________________
Robin Garrett
Digital Workshop Technical Support


For this message Robin Garrett has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject:
PostPosted: November 13th, 2009, 1:11 pm 
Offline

Joined: May 24th, 2007, 11:02 am
Posts: 132
Location: UK - Wales - Ceredigion
Opus: illuminatus > Evolution
OS: Windows 10 Pro
System: i7 8GB RAM
is this file still available?


For this message jezjones29 has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject:
PostPosted: November 13th, 2009, 6:38 pm 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
That's strange -- a lot of the files I've posted over the years seem to have disappeared.
I think this is the file; I haven't checked it as I don't have Opus installed...

cheers
Paul


For this message Paul has been thanked by : mackavi


Top
 Profile  
 
 Post subject:
PostPosted: November 13th, 2009, 7:41 pm 
Offline

Joined: May 24th, 2007, 11:02 am
Posts: 132
Location: UK - Wales - Ceredigion
Opus: illuminatus > Evolution
OS: Windows 10 Pro
System: i7 8GB RAM
Thanx, but I still can't see it, I'm logged in, but no link

Edit: Now I've posted that - I can see the link ?! :D


For this message jezjones29 has been thanked by : mackavi


Top
 Profile Visit website  
 
 Post subject: Re: Adding extra Array functions with ".prototype."
PostPosted: March 27th, 2012, 1:47 pm 
Offline

Joined: August 26th, 2011, 10:51 pm
Posts: 8
Opus: 7
OS: Ubuntu / Windows
These functions seem very useful, could you perhaps upload them again? Thanks!


For this message arnoud999 has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Adding extra Array functions with ".prototype."
PostPosted: March 28th, 2012, 12:48 am 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
I think this is the file, see attached...

cheers
Paul


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


For this message Paul has been thanked by : mackavi


Top
 Profile  
 
 Post subject: Re: Adding extra Array functions with ".prototype."
PostPosted: March 28th, 2012, 12:59 pm 
Offline

Joined: August 26th, 2011, 10:51 pm
Posts: 8
Opus: 7
OS: Ubuntu / Windows
It works! Thanks a lot, this can be extremely useful!

Best,
Arnoud


For this message arnoud999 has been thanked by : mackavi


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 37 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group