On Sun, Aug 10, 2008 at 8:44 AM, Adam Golebiowski <[EMAIL PROTECTED]>wrote:
> Hi,
>
> I am designing my first webapp with qooxdoo and after reaching a phase
> where I
> am quite satisfied with how the app looks, I decided to refactoreize code a
> bit and make it a little bit more readable -- till now everything was
> inside
> main():
>
...
> // design set-up
> var vert_pane = this.gen_vert_pane(); //
> qx.ui.splitpane.VerticalSplitPane
> var horiz_pane = this.gen_horiz_pane(); //
> qx.ui.splitpane.HorizontalSplitPane
> var menu_frame = this.gen_menu_frame(); // qx.ui.toolbar.Toolbar
> var tree_frame = this.gen_tree_frame(); // qx.ui.treevirtualTreeVirtual
> var right_frame = this.gen_right_frame(); // qx.ui.layout.CanvasLayout
>
> // add elements to the horiz_pane
> horiz_pane.addLeft(tree_frame);
> horiz_pane.addRight(right_frame);
>
> // add elements to vert_pane
> vert_pane.addTop(menu_frame);
> vert_pane.addBottom(horiz_pane);
>
> // add vert_pane to the document
> vert_pane.addToDocument();
> --- cut ---
>
> Then I wanted to add eventlistener for tree_frame:
> --- cut ---
> tree_frame.addEventListener("changeSelection", this.tree_selectionChanged);
> --- cut ---
>
> Inside tree_selectionChanged(), I check which node was selected and which
> branch this node belongs to. Based on that I am calling different functions
> that are supposed to fill right_frame with data (say, a foo() function):
>
> And here are two problems:
> calling right_frame.RemoveAll() inside tree_selectionChanged results in:
> right_frame not defined
>
> And attempt to call foo() results with
> this.foo is not a function
There are two things here to understand that should help you solve your
problem.
1. As you realized, local variables in one function are not accessible in
another function. You can easily solve that by replacing things like this:
var horiz_pane = this.gen_horiz_pane();
with this:
this.horiz_pane = this.gen_horiz_pane();
and then, of course using this.horiz_pane everyplace you are currently using
horiz_pane. That way, your pane references become a part of your
application object.
2. There is a third parameter to addEventListener() which you are currently
leaving to its default. The third parameter, if specified, gives the
context in which the event listener is to be called, i.e. what 'this' refers
to in the event listener. If you don't specify it, then the default context
is the object on which addEventListener was called, In your case, that's
the 'tree' object. tree.foo() does not exist, thus your errors. So what
you want to do instead of this:
tree_frame.addEventListener("changeSelection",
this.tree_selectionChanged);
is add a third parameter to ensure that the context is the application
object:
tree_frame.addEventListener("changeSelection", this.tree_selectionChanged,
this);
Then, in your event listener, you'll have access to this.foo() since foo is
a method of the application object.
Cheers,
Derrell
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
qooxdoo-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/qooxdoo-devel