PDA

View Full Version : run methods using LzReplicationManager or anything!


yuna
04-09-2007, 02:49 PM
Hi all,

I have a view which contains methods and I want to run all method without knowing a name of each method (because I will have lots of views and different name of methods inside of each view later on.)

Only thing I know is the name of view.

Here is example

<view id="firstView">
<method name="unknownIDno">
</method>
<method name="unknownline3">
</method>
<method name="unknownline4">
</method>
<method name="unknownline5">
</method>
<method name="unknowntname">
</method>
... more methods ....

</view>

Here is debug inspection:

var viewID = canvas.searchSubviews("id", "firstView")

Debug.inspect(#firstView)
#firstView {
_instanceAttrs: «Object#210#211| {id: firstView}»
_instanceChildren: «undefined»
addedToParent: true
unknownIDno: «Function#212| firstView_unknownIDno»
unknownline3: «Function#213| firstView_unknownline3»
unknownline4: «Function#214| firstView_unknownline4»
unknownline5: «Function#215| firstView_unknownline5»
unknowntname: «Function#216| firstView_unknowntname»
id: firstView
immediateparent: «LzCanvas#217| This is the canvas»
isinited: true
mask: null
nodeLevel: 1
parent: «LzCanvas#217| This is the canvas»
}
«LzView#209| #firstView»

It seems like I can get methods/functions using LzReplicationManager or something like that...
do you have any idea/thought?

Thank you

ptw
04-10-2007, 05:01 AM
Methods are properties of the view. You can enumerate them in script:


for (var p in firstView) {
if (p.indexOf('unknown') == 0) {
if (firstView[p] instanceof Function) {
if ($debug) {
Debug.debug("firstView.%s is %w", p, firstView[p]);
}
// Call it
firstView[p]();
}
}
}

yuna
04-10-2007, 01:27 PM
Paul,

Thank you for reply. I've been playing with this for loop and can't seem to get the first part to work.
Seems like you are using this like an array but we can't figure out how to pull the first[p], as it doesn't
give us anything in the laszlo debug window.

lzx> firstView[1]()
lzx> firstView[1]
lzx> firstView[1] instanceof Function
false
lzx>

for (var p in firstView) { <-- how can i find the var p in firstView?

Any suggestions?

Thanks so much!

ptw
04-11-2007, 03:26 AM
Try this:


lzx> for (var p in firstView) Debug.write(p);


`for ... in` is Javascript, it will enumerate the keys of an object.

yuna
04-23-2007, 01:38 PM
Thanks Paul! =)