We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Unwanted behaviour with registerOnHover and for loop

Home Forums Puzzles Unwanted behaviour with registerOnHover and for loop

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #40076
    elie520
    Participant

    Hello,
    I’m trying to have an outline when I hover all the objects of my scene which fit a certain criteria.
    When I do it manually, with

    registerOnHover(obj1,false,function(){outline(obj1, 'ENABLE')},function(){outline(obj1,'DISABLE')});
    registerOnHover(obj2,false,function(){outline(obj2, 'ENABLE')},function(){outline(obj2,'DISABLE')});
    //...

    it works fine. But when I try to use a for loop like this:

    for (var a = 0 ; a < objs.length ; a++) {
    registerOnHover(objs[a],false,function(){outline(objs[a], 'ENABLE')},function(){outline(objs[a],'DISABLE')});
    }

    whenever I hover one of the objects, it is always the last one of the list that gets outlined.

    If anyone could help, it’d be greatly appreciated :)
    Thanks!

    #40079
    elie520
    Participant

    I could solve my problem using _pGlob.hoveredObject in the following way:

    for (var a = 0 ; a < objs.length ; a++) {
    registerOnHover(objs[a],false,function(){outline(_pGlob.hoveredObject, 'ENABLE')},function(){outline(_pGlob.hoveredObject,'DISABLE')});
    }
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.