I'm displaying 1 Background Image and 1 small X button to close the box.
Calling a function on a close button which is on top of a background. Btw Background also has a click listener.
Now when i click on POI/Background it works but when i click on close-button, it doesn't respond. Why?
Is it because of the priority..? Like IF the container (Background) also has click-listener then all the sub component on it will get fail to respond to their listener?
Is there anyone who faced same issue and now resolved it?
If anyone knows the root cause of it or it's solution, please do share it with me. Thanks in advance.
document.getElementById("statusElement").innerHTML = 'On Close Btn Click Fired: '+id;
}
Regards!
Aamir Ali
iOS Apps Developer
Sr. Software Engineer @ Time Group Limited
C
Christian Ebner
said
over 10 years ago
Hello,
you don't return a boolean in your click-functions createClickTrigger and testBtnClick. If you don't return anything the next click-trigger will be fired. It should be enough to "return true;" at the end of both functions.
You find more details about the onClick-trigger in the reference.
Hope that helps, Chris
A
Aamir Ali
said
over 10 years ago
Hi Chris,
Thanks to direct me on right source i was looking for.
Yes you are right according to wikitude documentation, we've to return BOOLEAN.
I also found if we gonna create onClick callback function while initialization of ARObject, it suddenly fires right after object's initialization.
I got it's solution by defining anonymous function inside callback function as
function closeBtnClick(){
return function()
{
alert("close button click event fire.");
}
return true;
}
By this way, button click event registered but if i want to pass any parameter to closeBtnClick function to use it when close Button Clicks.
For instance, on close buttn click i want to print that passing parameter on screen.
I'm doing it though this way which is not accepting by Wikitude architectView and I can't see any ARObject on the screen due to this approach.
Can you please guide here what went wrong? Or Param variable doesn't accesible inside the anonymous function?
Regards!
Aamir Ali
A
Aamir Ali
said
over 10 years ago
Hi Guys,
Is there anybody who can answer my post??? :(
Regards!
Aamir Ali
A
Aamir Ali
said
over 10 years ago
Hi Guys,
Finally i got solution of my problem by exploring Javascript a bit in detail.
Its about Javascript Closures in which In-line function fail to transfer outer-world variable. So We've to store that outer-world variable into a local variable inside the In-line function and start using local variable now. But we also have to use (); at the end of the function which is like a magic statement.
Here is code that exactly looks like
for(var i=0; i<jsonObject.length; i++){
closePOIImgDrw.onClick = (function(){
var currentIndex = i;
return function(){
alert('My ID:'+currentIndex);//Here i'm using currentIndex local variable name not outer-function.
removeSinglePOI(currentIndex);
}
})();
}//for end
It is working fine in my case and I'm glade to share this solution with others whoever get stuck in same kinda problem.
Aamir Ali