Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently October 8th, 2024, 6:16 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Global functions
PostPosted: February 2nd, 2006, 12:21 pm 
Offline

Joined: February 2nd, 2006, 12:00 pm
Posts: 3
Location: Italy
problem: to call a function from anywhere, without including the script object into every page

I believe mine is a common question. I'd like to call this simple function
Code:
function setText(obj, text)
{
  obj.SetSelection(0,-1)
  obj.ReplaceSelection(text)
}

each time I need to set some text on a text object.

So I put it into a Script Object, but this way I should copy the same script into every page.
What is the right way to do this? May I add the function to the "Text Objects" hierarchy? Is there a concept like "global function"?
What's not yet clear to me is the object model of Opus when defining new functions

Regards,
Enrico


Top
 Profile  
 
 Post subject:
PostPosted: February 2nd, 2006, 12:25 pm 
Offline

Joined: April 1st, 2005, 6:59 pm
Posts: 98
Location: Maastricht, The Netherlands
Opus: V7
OS: Mac OS X 10.7.2 | Windows 8 Dev
System: i5 2.7 | 8G Ram | 1 T HD
Hi,

Code:
function setText()
{
  obj.SetSelection(0,-1)
  obj.ReplaceSelection(text)
}


Then on a mouseaction insert a script with code:

Code:
setText()


Hope this helps

Ronnie Dackus


Top
 Profile Visit website  
 
 Post subject:
PostPosted: February 2nd, 2006, 12:34 pm 
Offline

Joined: October 26th, 2004, 10:23 am
Posts: 666
Location: Digital Workshop
Two solutions:

1. Add the script to a master page; in which case a copy is available from every page that uses the master page.

2. In your script object assign a reference to the function to a new member of the publication object:
Code:
function setText()
{
  obj.SetSelection(0,-1)
  obj.ReplaceSelection(text)
}
GetPublication().setText = setText;

You can than use setText() from anywhere. The script that does this should only be evaluated once to avoid any potential issues with different copies of code. (Note the "setText" member of the publication is a reference to setText(), not the same thing - so GetPublication().my_setText = setText; is equally valid, for example and you woul then call my_setText())

Hope this helps.

_________________
ddww Opus Developer


Top
 Profile Visit website  
 
 Post subject:
PostPosted: February 2nd, 2006, 1:27 pm 
Offline

Joined: February 2nd, 2006, 12:00 pm
Posts: 3
Location: Italy
Duncan Lilly wrote:
Two solutions:

2. In your script object assign a reference to the function to a new member of the publication object:


Thank you, now I see that it's quite like Javascript.

I've just tried to use the nicer form:
Code:
Object.prototype.mySetText = setText;

but I couldn't find the Text's object name. When printing an instance Opus says "ILMObject" but than it doesn't recognize this as a class name

Any idea?


Top
 Profile  
 
 Post subject:
PostPosted: February 2nd, 2006, 6:35 pm 
Offline

Joined: November 3rd, 2004, 8:12 pm
Posts: 129
Location: New Brunswick, Canada
Opus: 8.6
OS: Win 8 (ASUS) - Win 7: (ASUS)
System: Asus - Windows 7 - 8 - Intel Core 3 - 4RAM - 16RAM
Hi,

Did you try searching the forum for the word: ILMObject

Have a good one.

_________________
Leo Taylor
Win XP Home / Opus Pro 7.01 & 6.4 / P4-2.8 / 1.5 GB RAM / ATI All-in-Wonder 9600 /160GB-HD


Top
 Profile Visit website  
 
 Post subject:
PostPosted: February 2nd, 2006, 6:41 pm 
Offline

Joined: October 26th, 2004, 10:23 am
Posts: 666
Location: Digital Workshop
santoemma wrote:
Thank you, now I see that it's quite like Javascript.

OpusScript and Javascript are both based on ecmascript.

santoemma wrote:
I've just tried to use the nicer form:
Code:
Object.prototype.mySetText = setText;

but I couldn't find the Text's object name. When printing an instance Opus says "ILMObject" but than it doesn't recognize this as a class name

I'm not sure what you are trying to achieve here. obj.GetName() will return the name of an object.

_________________
ddww Opus Developer


Top
 Profile Visit website  
 
 Post subject:
PostPosted: February 3rd, 2006, 11:23 am 
Offline

Joined: February 2nd, 2006, 12:00 pm
Posts: 3
Location: Italy
Duncan Lilly wrote:
I'm not sure what you are trying to achieve here. obj.GetName() will return the name of an object.


Actually GetName() seems to give the content of the attribute "name" of the class X. The question is: what is X? How one can know the class name given an instance of that class?

Because, having the class name, if Opus is ecmascript, I can say:
Code:
TextObject.prototype.SetText = mySetText;
// assuming that a text widget's class is TextObject

and magically extend the text widgets with my own behaviour.

Before I forget to say it, Duncan, you all have made quite a nice job with Opus. There are a lot of bugs but I'm start loving it

enrico


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

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 1 guest


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