Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4551224
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:36:21+00:00 2026-05-21T16:36:21+00:00

What i’m trying to do is a combination of a mootools class and raphael.

  • 0

What i’m trying to do is a combination of a mootools class and raphael. The problem i got is mainly mootools event binding i guess.
I’m trying to append an event to a raphael element (dom node) and when firing the event another class method should be called.
This is no problem when coding without a mootools class. But this (the right) way i have some problems. When binding the events, the raphael element cannot be longer used because “this” now refers to the mootools class.

Please take a look at this code and i guess you will understand what my problem is:

    // mootools class 
    var test = new Class({

    ...

        initPlane: function() {

            // just an JSON object array
            this.objects = [{"pid":"2","sx":"685","sy":"498","dx":"190","dy":"540"},{"pid":"3","sx":"156","sy":"341","dx":"691","dy":"500"}]; 

            // place the objects on stage and append some events to them
            this.objects.each(function(item, idx){                      
                item.gfx = this.gfx.image("assets/img/enemy.png", item.sx, item.sy, 32, 32);


                // #### differnt approaches to bind the events. all not working

                // first attempt with mootools event
                item.gfx.node.addEvent('click', function(e) {
                    console.log(this.attr('x'));    // not working because this is bound to the class i guess
                    this.info();
                }.bind(this));          

                // second attempt with mootools event
                item.gfx.node.addEvent('click', function(e) {
                    console.log(this.attr('x'));    // not working
                    parent.info(this);              // no binding and not working
                });         

                // first attempt with raphael event
                item.gfx.click( function(e) {
                    console.log(this.attr('x'));    // works !
                    this.info(this);                // not working because this refers to raphael element. 
                });         



            }.bind(this))

        },


        // this method should be called after click event and output element attribs
        info: function(event) {
            console.log(event.attr('x'));
        },      

    ...

    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T16:36:22+00:00Added an answer on May 21, 2026 at 4:36 pm

    your .each is wrong.

    Object.each(obj, function(el, key, obj) {
    
    }, bind);
    

    http://mootools.net/docs/core/Types/Object#Object:Object-each

    although you actually have this.objects as array, did not notice 🙂

    Array.each(function(el, index) {
    
    }, bind);
    

    when you need this to be bound to element on click, that’s fine. just store a copy of this into self and call self.info() instead. alternatively, keep the bind and reference e.target as the trigger element instead, whilst this is your instance

    although it may seem ‘neater’ to try to keep this bound to the class wherever possible, mootools-core devs tend to prefer the var self = this; way as it avoids the extra callback to bind etc (look at the mootools source, very common)

    also, say you want to have the click event go to a method directly:

    element.addEvent("click", this.info.bind(this));

    which will send the event as the 1st argument to info (so reference event.target).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.