Adds onAttach event.