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 8758011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:26:26+00:00 2026-06-13T14:26:26+00:00

im a bit stuck here. Some hints would be really nice. Asume i have

  • 0

im a bit stuck here. Some hints would be really nice.
Asume i have to have a multi-dimensional array of objects, the objects contain functions i want to use on mouseover (play, stop, showFrame, etc.). But they are not all loaded yet, so my first approach was using

.on("mouseover", function () { ... }

until i ran into a closure problem, that was already discussed a couple of times here on StackOverflow and on other places. First i tried to encounter the problem with a solution given on another SO-thread, until i ran into the eventData that you could pass within .bind(). The SO-closure solution i had first is commented in the following, active code contains my approach with .bind eventData:

$(function(){
    for (var r=0, firDep=menu[0][0].length; r<firDep; r+=1){
        objects[0][0][r].init();
}
for(var f=0, livLen=menu.length; f<livLen; f++){
    for(var g=0, livWid=menu[f].length; g<livWid; g++){
        for(var h=0, livDep=menu[f][g].length; h<livDep; h++){
            if(menu[f][g][h]){
//                  (function( ) {
//                        var fr = f;
//                        var gr = g;
//                        var hr = h;
// to apply this prior solution, i would simply replace all occurences of e.data.** with ** again and all .bind's with .on's
                    $('#'+menu[f][g][h]).bind("mouseover", { fr: f, gr: g, hr: h}, function(e) {
                        if(objects[e.data.fr][e.data.gr][e.data.hr].status==0){
                            objects[e.data.fr][e.data.gr][e.data.hr].showFrame(1);
                        }
                    });
                    $('#'+menu[f][g][h]).bind("mouseout", { fr: f, gr: g, hr: h}, function(e) {
                        if(objects[e.data.fr][e.data.gr][e.data.hr].status==0){
                            objects[e.data.fr][e.data.gr][e.data.hr].showFrame(0);
                        }
                    });
                    $('#'+menu[f][g][h]).bind("click", {fr: f, gr: g, hr: h}, function(e) {
                        e.preventDefault();
                        if(objects[e.data.fr][e.data.gr][e.data.hr].status!=1 || objects[e.data.fr][e.data.gr][e.data.hr].status!=2){
                            for(var t=0, tstLen=menu[e.data.fr][e.data.gr].length; t<tstLen; t++){
                                if(objects[e.data.fr][e.data.gr][t].status==1 || objects[e.data.fr][e.data.gr][t].status==2){
                                    objects[e.data.fr][e.data.gr][t].stop();
                                    objects[e.data.fr][e.data.gr][t].playReverse();
                                }
                            }
                            objects[e.data.fr][e.data.gr][e.data.hr].stop();
                            objects[e.data.fr][e.data.gr][e.data.hr].play();
                            finc = e.data.fr+1;
                            if(menu[finc][e.data.hr] && menu[finc][e.data.hr].length > 0){
                                $('#menu'+finc).load('menu'+finc+e.data.hr+'.php', function () {
                                    for(var b=0, ldLen=menu[finc][e.data.hr].length; b<ldLen; b++){
                                        objects[finc][e.data.hr][b].init();
                                    }
                                    $('#menu'+finc).slideDown('slow');
                                });
                            } else {
                                if ($('#menu2').is(':visible')) {
                                    $('#menu2').slideUp('slow', function () {
                                        $('#menu1').slideUp('slow', function () {
                                            $('#menu1').empty();
                                            $('#menu2').empty();
                                        });
                                    }); 
                                } else if ($('#menu1').is(':visible')){
                                    $('#menu1').slideUp('slow', function () {
                                        $('#menu1').empty();
                                    });
                                }
                            }
                            loadContent(menu[e.data.fr][e.data.gr][e.data.hr]+".php");
                        }
                    });
                //})(); //function execution for prior closure-defeating attempt
            }
        }
    }
  }
});

So i have a 3d-array menu[][][], defining the structure, the 3d-array of objects[][][] with their play(), stop() etc functions, on the html-page i have 3 menu divs, #menu0, #menu1, #menu2 which would contain the appropriate depths’ menu.
Basically both solutions work BUT only for elements that are already loaded on the page from the beginning. The mouseover-part for example is not triggered on div’s that are load()ed later on, but very well match the selector

$('#'+menu[f][g][h]).

For the alternative solution that i found here on SO, you would remove the comments in the beginning to get that anonymous function, replace all occurences of e.data.** with the appropriate ** only, replace all the .binds with .on and of course remove the { fr:f, gr:g, hr: h} eventData parts. Oh, and remove the comment in the end where the function is directly beeing executed })();

Any hint would be great, thanks in advance for your time.

—-edit—-

Accepted, this is a total mess. Im going to go a different way, thanks for the help.
Yet the logical problem still exists, even in simpler forms, and im really interested in the answer, just to understand what the basic logical problem behind it is. There must be something either about the closure fix or on() that i dont understand.
So i re-asked the question with a much simpler example at
jQuery: click function bind in for-loop with closure fix .

  • 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-06-13T14:26:28+00:00Added an answer on June 13, 2026 at 2:26 pm

    Your code looks too complicated – thats a problem. I think you should look on backbone.js or similar frameworks to structure your data and separate logic from views. Backbone(and underscore) have a very useful methods to work with collections and models.

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

Sidebar

Related Questions

I'm a wee bit stuck on this, and was hoping you might have some
I am a little bit stuck: I would like to change the max option
I haven't implemented a search feature before and feel a bit stuck. I have
I'm a bit stuck with some of the new CSS3 Background commands an was
As you can tell I'm new to multithreading and a bit stuck here. For
I'm a bit stuck, and probably not understanding AR properly. Here's what I've got:
I have a problem that I am a bit stuck on and I was
I have a situation where in MS Dynamics Crm it returns some objects using
I'm stuck here again. I have a database with over 120 000 coordinates that
I'm a little bit stuck with my db4o homework and I don't really know

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.